CF1725F.Field Photography

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

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×10100N \times 10^{100} with NN rows and 1010010^{100} columns. The rows are numbered from 11 to NN from north to south, the columns are numbered from 11 to 1010010^{100} from west to east. The tile in row rr and column cc is denoted as (r,c)(r,c).

There are NN provinces that participate in OSN 2019. Initially, each contestant who represents province ii stands in tile (i,p)(i, p) for each pp satisfying Li≤p≤RiL_i \leq p \leq R_i. So, we can see that there are Ri−Li+1R_i-L_i+1 contestants who represent province ii.

Pak Chanek has a variable ZZ that is initially equal to 00. In one operation, Pak Chanek can choose a row ii and a positive integer kk. Then, Pak Chanek will do one of the two following possibilities:

  • Move all contestants in row ii exactly kk tiles to the west. In other words, a contestant who is in (i,p)(i, p) is moved to (i,p−k)(i, p-k).
  • Move all contestants in row ii exactly kk tiles to the east. In other words, a contestant who is in (i,p)(i, p) is moved to (i,p+k)(i, p+k).

After each operation, the value of ZZ will change into Z OR kZ \text{ OR } k, with OR\text{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 QQ questions. For the jj-th question, you are given a positive integer WjW_j, Pak Chanek must do zero or more operations so that the final value of ZZ is exactly WjW_j. Define MM as the biggest number such that after all operations, there is at least one column that contains exactly MM contestants. For each question, you must find the biggest possible MM 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.

帕克·查内克正在前往万鸦老。结果发现,2019 年印度尼西亚全国科学奥林匹克竞赛(OSN)正在此举行。2019 年 OSN 的参赛选手们当前正排成一列,在一块场地上准备合影。该场地形状为一个 N×10100N \times 10^{100} 的网格,共 NN 行、1010010^{100} 列。行从北向南编号为 11 至 NN,列从西向东编号为 11 至 1010010^{100}。位于第 rr 行、第 cc 列的格子记作 (r,c)(r,c)。

共有 NN 个省份参加 2019 年 OSN。初始时,代表第 ii 个省份的每位选手均站在格子 (i,p)(i, p) 上,其中 pp 满足 Li≤p≤RiL_i \leq p \leq R_i。因此,代表第 ii 个省份的选手共有 Ri−Li+1R_i - L_i + 1 人。

帕克·查内克有一个变量 ZZ,其初始值为 00。在一次操作中,帕克·查内克可任选一行 ii 和一个正整数 kk,然后执行以下两种操作之一:

  • 将第 ii 行中的所有选手恰好向西移动 kk 格。换言之,位于 (i,p)(i, p) 的选手将被移至 (i,p−k)(i, p-k);
  • 将第 ii 行中的所有选手恰好向东移动 kk 格。换言之,位于 (i,p)(i, p) 的选手将被移至 (i,p+k)(i, p+k)。

每次操作后,ZZ 的值将更新为 Z OR kZ \text{ OR } k,其中 OR\text{OR} 表示按位或运算。注意:帕克·查内克可对同一行执行多次操作;同时,他不允许将选手移出网格边界。

共有 QQ 个询问。对于第 jj 个询问,给定一个正整数 WjW_j,帕克·查内克必须执行零次或多次操作,使得最终 ZZ 的值恰好等于 WjW_j。定义 MM 为:在所有操作完成后,某一列中所含选手数量的最大可能值(即存在至少一列恰好包含 MM 名选手)。对每个询问,你需要求出所有可行操作序列下所能达到的最大的 MM 值。注意:帕克·查内克为某一个询问所执行的操作不会影响其他询问。

输入格式

The first line contains a single integer NN (1≤N≤1051 \leq N \leq 10^5) — the number of rows in the grid and also the number of provinces that participate in OSN 2019.

The ii-th of the next NN lines contains two integers LiL_i and RiR_i (1≤Li≤Ri≤1091 \leq L_i \leq R_i \leq 10^9) describing the positions of the contestants who represent province ii.

The next line contains a single integer QQ (1≤Q≤1051 \leq Q \leq 10^5) — the number of questions.

The jj-th of the next QQ lines contains a single integer WjW_j (1≤Wj≤1091 \leq W_j \leq 10^9) — the required final value of ZZ for the jj-th question.

第一行包含一个整数 NN(1≤N≤1051 \leq N \leq 10^5),表示网格的行数,也等于参加 OSN 2019 的省份数量。

接下来的 NN 行中,第 ii 行包含两个整数 LiL_i 和 RiR_i(1≤Li≤Ri≤1091 \leq L_i \leq R_i \leq 10^9),描述代表第 ii 个省份的参赛者的位置。

下一行包含一个整数 QQ(1≤Q≤1051 \leq Q \leq 10^5),表示问题的数量。

接下来的 QQ 行中,第 jj 行包含一个整数 WjW_j(1≤Wj≤1091 \leq W_j \leq 10^9),表示第 jj 个问题所要求的 ZZ 的最终值。

输出格式

Output QQ lines, with the jj-th line containing an integer that is the answer to the jj-th question.

输出 QQ 行,其中第 jj 行包含一个整数,表示第 jj 个问题的答案。

输入输出样例

  • 输入#1

    3
    1 5
    10 11
    8 8
    2
    12
    5

    输出#1

    2
    3

说明/提示

For the 11-st question, Pak Chanek can do the following operations to get M=2M=2:

  • Move all contestants in row 22 to the east by 44 tiles. ZZ changes into 0 OR 4=40 \text{ OR } 4 = 4.
  • Move all contestants in row 11 to the east by 1212 tiles. ZZ changes into 4 OR 12=124 \text{ OR } 12 = 12.

Now, columns 1414 and 1515 each contains exactly 22 contestants.

For the 22-nd question, Pak Chanek can do the following operations to get M=3M=3:

  • Move all contestants in row 33 to the east by 44 tiles. ZZ changes into 0 OR 4=40 \text{ OR } 4 = 4.
  • Move all contestants in row 33 to the west by 11 tiles. ZZ changes into 4 OR 1=54 \text{ OR } 1 = 5.
  • Move all contestants in row 11 to the east by 55 tiles. ZZ changes into 5 OR 5=55 \text{ OR } 5 = 5.
  • Move all contestants in row 11 to the east by 55 tiles. ZZ changes into 5 OR 5=55 \text{ OR } 5 = 5.

Now, column 1111 contains exactly 33 contestants.

The following is an illustration of the example operations for the 22-nd question.

对于第 11 个问题,Pak Chanek 可以执行以下操作以得到 M=2M=2:

  • 将第 22 行的所有参赛者向东移动 44 格。此时 ZZ 变为 0 OR 4=40 \text{ OR } 4 = 4。
  • 将第 11 行的所有参赛者向东移动 1212 格。此时 ZZ 变为 4 OR 12=124 \text{ OR } 12 = 12。

此时,第 1414 列和第 1515 列各自恰好包含 22 名参赛者。

对于第 22 个问题,Pak Chanek 可以执行以下操作以得到 M=3M=3:

  • 将第 33 行的所有参赛者向东移动 44 格。此时 ZZ 变为 0 OR 4=40 \text{ OR } 4 = 4。
  • 将第 33 行的所有参赛者向西移动 11 格。此时 ZZ 变为 4 OR 1=54 \text{ OR } 1 = 5。
  • 将第 11 行的所有参赛者向东移动 55 格。此时 ZZ 变为 5 OR 5=55 \text{ OR } 5 = 5。
  • 将第 11 行的所有参赛者向东移动 55 格。此时 ZZ 变为 5 OR 5=55 \text{ OR } 5 = 5。

此时,第 1111 列恰好包含 33 名参赛者。

以下是第 22 个问题示例操作的示意图。

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

首页