CF1725F.Field Photography
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Pak Chanek is traveling to Manado. It turns out that OSN (Indonesian National Scientific Olympiad) 2019 is being held. The contestants of OSN 2019 are currently lining up in a field to be photographed. The field is shaped like a grid of size N×10100 with N rows and 10100 columns. The rows are numbered from 1 to N from north to south, the columns are numbered from 1 to 10100 from west to east. The tile in row r and column c is denoted as (r,c) .
There are N provinces that participate in OSN 2019. Initially, each contestant who represents province i stands in tile (i,p) for each p satisfying Li≤p≤Ri . So, we can see that there are Ri−Li+1 contestants who represent province i .
Pak Chanek has a variable Z that is initially equal to 0 . In one operation, Pak Chanek can choose a row i and a positive integer k . Then, Pak Chanek will do one of the two following possibilities:
- Move all contestants in row i exactly k tiles to the west. In other words, a contestant who is in (i,p) is moved to (i,p−k) .
- Move all contestants in row i exactly k tiles to the east. In other words, a contestant who is in (i,p) is moved to (i,p+k) .
After each operation, the value of Z will change into Z OR k , with OR being the bitwise OR operation. Note that Pak Chanek can do operations to the same row more than once. Also note that Pak Chanek is not allowed to move contestants out of the grid.
There are Q questions. For the j -th question, you are given a positive integer Wj , Pak Chanek must do zero or more operations so that the final value of Z is exactly Wj . Define M as the biggest number such that after all operations, there is at least one column that contains exactly M contestants. For each question, you must find the biggest possible M for all sequences of operations that can be done by Pak Chanek. Note that the operations done by Pak Chanek for one question do not carry over to other questions.
输入格式
The first line contains a single integer N ( 1≤N≤105 ) — the number of rows in the grid and also the number of provinces that participate in OSN 2019.
The i -th of the next N lines contains two integers Li and Ri ( 1≤Li≤Ri≤109 ) describing the positions of the contestants who represent province i .
The next line contains a single integer Q ( 1≤Q≤105 ) — the number of questions.
The j -th of the next Q lines contains a single integer Wj ( 1≤Wj≤109 ) — the required final value of Z for the j -th question.
输出格式
Output Q lines, with the j -th line containing an integer that is the answer to the j -th question.
输入输出样例
输入#1
3 1 5 10 11 8 8 2 12 5
输出#1
2 3
说明/提示
For the 1 -st question, Pak Chanek can do the following operations to get M=2 :
- Move all contestants in row 2 to the east by 4 tiles. Z changes into 0 OR 4=4 .
- Move all contestants in row 1 to the east by 12 tiles. Z changes into 4 OR 12=12 .
Now, columns 14 and 15 each contains exactly 2 contestants.
For the 2 -nd question, Pak Chanek can do the following operations to get M=3 :
- Move all contestants in row 3 to the east by 4 tiles. Z changes into 0 OR 4=4 .
- Move all contestants in row 3 to the west by 1 tiles. Z changes into 4 OR 1=5 .
- Move all contestants in row 1 to the east by 5 tiles. Z changes into 5 OR 5=5 .
- Move all contestants in row 1 to the east by 5 tiles. Z changes into 5 OR 5=5 .
Now, column 11 contains exactly 3 contestants.
The following is an illustration of the example operations for the 2 -nd question.