CF1935E.Distance Learning Courses in MAC
普及/提高-
通过率:0%
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 n courses available. For the i -th distance learning course, a student can receive a grade ranging from xi to yi .
However, not all courses may be available to each student. Specifically, the j -th student is only given courses with numbers from lj to rj , meaning the distance learning courses with numbers lj,lj+1,…,rj .
The creators of the distance learning courses have decided to determine the final grade in a special way. Let the j -th student receive grades clj,clj+1,…,crj for their distance learning courses. Then their final grade will be equal to clj ∣ clj+1 ∣ … ∣ crj , 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 q students, tell them the maximum final grade they can achieve.
输入格式
Each test consists of multiple test cases. The first line contains a single integer t ( 1≤t≤2⋅104 ) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer n ( 1≤n≤2⋅105 ) — the number of distance learning courses.
Each of the following n lines contains two integers xi and yi ( 0≤xi≤yi<230 ) — the minimum and maximum grade that can be received for the i -th course.
The next line contains a single integer q ( 1≤q≤2⋅105 ) — the number of students.
Each of the following q lines contains two integers lj and rj ( 1≤lj≤rj≤n ) — the minimum and maximum course numbers accessible to the j -th student.
It is guaranteed that the sum of n over all test cases and the sum of q over all test cases do not exceed 2⋅105 .
输出格式
For each test case, output q integers, where the j -th integer is the maximum final grade that the j -th student can achieve.
输入输出样例
输入#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:
- The maximum grade for the first student is 1 :
- On the first distance learning course, he will receive a grade of 1 .
Therefore, the final grade is 1 .
2. The maximum grade for the second student is 5 :
- On the first distance learning course, he will receive a grade of 1 .
- On the second distance learning course, he will receive a grade of 4 .
Therefore, the final grade is 1 ∣ 4 = 5 .
3. The maximum grade for the third student is 4 :
- On the second distance learning course, he will receive a grade of 4 .
Therefore, the final grade is 4 .
In the second test case:
- The maximum grade for the first student is 15 :
- On the first distance learning course, he will receive a grade of 7 .
- On the second distance learning course, he will receive a grade of 4 .
- On the third distance learning course, he will receive a grade of 8 .
Therefore, the final grade is 7 ∣ 4 ∣ 8 = 15 .
2. The maximum grade for the second student is 11 :
- On the third distance learning course, he will receive a grade of 9 .
- On the fourth distance learning course, he will receive a grade of 2 .
Therefore, the final grade is 9 ∣ 2 = 11 .