luogu#P4885. 灭顶之灾

灭顶之灾

Background

Please read the initials of the pinyin of the problem name together.

Problem Description

Scarlet has a mysterious n×mn \times m table. Now Scarlet fills numbers into the table. She will start from some cell in the first row, and then, in the order of left to right, top to bottom, she fills positive integers starting from 11, until she fills the last row completely.

To let you determine this table, Scarlet will tell you ss groups of consecutive numbers in the same row. After that, Scarlet will ask you qq queries. You need to answer, for each queried number, which row and which column it is filled in.

Input Format

The first line contains 44 positive integers n,m,s,qn, m, s, q.

The next ss lines each contain two positive integers ai,bia_i, b_i, meaning that the integers from aia_i to bib_i are in the same row of the table and are consecutive.

The next qq lines each contain one positive integer AiA_i, representing the number in each query.

Output Format

If no table satisfying the constraints exists, output one line Impossible!.

Otherwise, if the table satisfying the constraints is not unique, output one line Uncertain!.

Otherwise, output the xor sum of all row and column results (including the earlier 0 0 cases), in order to reduce the output file size so that Scarlet can easily upload the testdata to the server.

3 4 2 2
8 9
2 4
9
3
7

Hint

Table:

0001
2345
6789

99 is in row 33, column 44.

33 is in row 22, column 22.

3422=73 \oplus 4 \oplus 2 \oplus 2 = 7 (\oplus means the xor operation).

Constraints

For 30%30\% of the data, 1n,m,s,q501 \leq n, m, s, q \leq 50.

For 60%60\% of the data, 1m,s20001 \leq m, s \leq 2000.

For 100%100\% of the data, 1n,m,Ai,ai,bi10181 \leq n, m, A_i, a_i, b_i \leq 10^{18}, 1s,q51051 \leq s, q \leq 5 * 10^5, and 0biaim10 \leq b_i - a_i \leq m - 1.

Translated by ChatGPT 5