CF1935E.Distance Learning Courses in MAC

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The New Year has arrived in the Master's Assistance Center, which means it's time to introduce a new feature!

Now students are given distance learning courses, with a total of nn courses available. For the ii-th distance learning course, a student can receive a grade ranging from xix_i to yiy_i.

However, not all courses may be available to each student. Specifically, the jj-th student is only given courses with numbers from ljl_j to rjr_j, meaning the distance learning courses with numbers lj,lj+1,…,rjl_j, l_j + 1, \ldots, r_j.

The creators of the distance learning courses have decided to determine the final grade in a special way. Let the jj-th student receive grades clj,clj+1,…,crjc_{l_j}, c_{l_j + 1}, \ldots, c_{r_j} for their distance learning courses. Then their final grade will be equal to cljc_{l_j} ∣| clj+1c_{l_j + 1} ∣| …\ldots ∣| crjc_{r_j}, where ∣| denotes the bitwise OR operation.

Since the chatbot for solving distance learning courses is broken, the students have asked for your help. For each of the qq students, tell them the maximum final grade they can achieve.

新年已至,大师辅助中心即将推出一项新功能!

现在,学生们将参加远程学习课程,一共有 nn 门课程可供选择。对于第 ii 门远程学习课程,学生可获得的分数范围为 xix_i 到 yiy_i(含端点)。

然而,并非所有课程对每位学生都开放。具体而言,第 jj 位学生仅能修读编号在 ljl_j 到 rjr_j 之间的课程,即编号为 lj,lj+1,…,rjl_j, l_j + 1, \ldots, r_j 的远程学习课程。

远程学习课程的设计者决定采用一种特殊的规则来确定最终成绩。设第 jj 位学生在其所修的远程学习课程中分别获得成绩 clj,clj+1,…,crjc_{l_j}, c_{l_j + 1}, \ldots, c_{r_j},则其最终成绩为 cljc_{l_j} ∣| clj+1c_{l_j + 1} ∣| …\ldots ∣| crjc_{r_j},其中 ∣| 表示按位或运算。

由于用于解答远程学习课程问题的聊天机器人出现故障,学生们特此向你求助。请对每位学生(共 qq 位),计算其能够取得的最高最终成绩。

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤2⋅1041 \leq t \leq 2 \cdot 10^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the number of distance learning courses.

Each of the following nn lines contains two integers xix_i and yiy_i (0≤xi≤yi<2300 \le x_i \le y_i \lt 2^{30}) — the minimum and maximum grade that can be received for the ii-th course.

The next line contains a single integer qq (1≤q≤2⋅1051 \le q \le 2\cdot10^5) — the number of students.

Each of the following qq lines contains two integers ljl_j and rjr_j (1≤lj≤rj≤n1 \le l_j \le r_j \le n) — the minimum and maximum course numbers accessible to the jj-th student.

It is guaranteed that the sum of nn over all test cases and the sum of qq over all test cases do not exceed 2⋅1052\cdot10^5.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤2⋅1041 \leq t \leq 2 \cdot 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5),表示远程学习课程的数量。

接下来的 nn 行中,每行包含两个整数 xix_i 和 yiy_i(0≤xi≤yi<2300 \le x_i \le y_i \lt 2^{30}),分别表示第 ii 门课程所能获得的最低成绩和最高成绩。

下一行包含一个整数 qq(1≤q≤2⋅1051 \le q \le 2\cdot10^5),表示学生的数量。

接下来的 qq 行中,每行包含两个整数 ljl_j 和 rjr_j(1≤lj≤rj≤n1 \le l_j \le r_j \le n),表示第 jj 名学生可选课程的编号范围(即从第 ljl_j 门到第 rjr_j 门课程)。

保证所有测试用例的 nn 之和与所有测试用例的 qq 之和均不超过 2⋅1052\cdot10^5。

输出格式

For each test case, output qq integers, where the jj-th integer is the maximum final grade that the jj-th student can achieve.

对于每个测试用例,输出 qq 个整数,其中第 jj 个整数表示第 jj 个学生所能达到的最高最终成绩。

输入输出样例

  • 输入#1

    3
    2
    0 1
    3 4
    3
    1 1
    1 2
    2 2
    4
    1 7
    1 7
    3 10
    2 2
    5
    1 3
    3 4
    2 3
    1 4
    1 2
    6
    1 2
    2 2
    0 1
    1 1
    3 3
    0 0
    4
    3 4
    5 5
    2 5
    1 2

    输出#1

    1 5 4 
    15 11 15 15 7 
    1 3 3 3

说明/提示

In the first test case:

  1. The maximum grade for the first student is 11:

    • On the first distance learning course, he will receive a grade of 11.

    Therefore, the final grade is 11.

  2. The maximum grade for the second student is 55:

    • On the first distance learning course, he will receive a grade of 11.
    • On the second distance learning course, he will receive a grade of 44.Therefore, the final grade is 11 ∣| 44 == 55.
  3. The maximum grade for the third student is 44:

    • On the second distance learning course, he will receive a grade of 44.Therefore, the final grade is 44.

In the second test case:

  1. The maximum grade for the first student is 1515:

    • On the first distance learning course, he will receive a grade of 77.
    • On the second distance learning course, he will receive a grade of 44.
    • On the third distance learning course, he will receive a grade of 88.

    Therefore, the final grade is 77 ∣| 44 ∣| 88 == 1515.

  2. The maximum grade for the second student is 1111:

    • On the third distance learning course, he will receive a grade of 99.
    • On the fourth distance learning course, he will receive a grade of 22.Therefore, the final grade is 99 ∣| 22 == 1111.

在第一个测试用例中:

  1. 第一位学生的最高成绩为 11:

    • 在第一门远程学习课程中,他将获得 11 分。

    因此,最终成绩为 11。

  2. 第二位学生的最高成绩为 55:

    • 在第一门远程学习课程中,他将获得 11 分。
    • 在第二门远程学习课程中,他将获得 44 分。因此,最终成绩为 11 ∣| 44 == 55。
  3. 第三位学生的最高成绩为 44:

    • 在第二门远程学习课程中,他将获得 44 分。因此,最终成绩为 44。

在第二个测试用例中:

  1. 第一位学生的最高成绩为 1515:

    • 在第一门远程学习课程中,他将获得 77 分。
    • 在第二门远程学习课程中,他将获得 44 分。
    • 在第三门远程学习课程中,他将获得 88 分。

    因此,最终成绩为 77 ∣| 44 ∣| 88 == 1515。

  2. 第二位学生的最高成绩为 1111:

    • 在第三门远程学习课程中,他将获得 99 分。
    • 在第四门远程学习课程中,他将获得 22 分。因此,最终成绩为 99 ∣| 22 == 1111。

输入解题思路,AI测评打分。不知道怎么写?

首页