GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Sunday 4 September 2022

[Solution] Field Photography Codeforces Solution



F. Field Photography
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 LipRi. So, we can see that there are RiLi+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,pk).
  • 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.

Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇

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.

Input

The first line contains a single integer N (1N105) — 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 (1LiRi109) describing the positions of the contestants who represent province i.

The next line contains a single integer Q (1Q105) — the number of questions.

The j-th of the next Q lines contains a single integer Wj (1Wj109) — the required final value of Z for the j-th question.

Output

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

No comments:

Post a Comment