#P5688. [CSP-S 2019 江西] 散步

[CSP-S 2019 江西] 散步

Description

There are nn people taking a walk in a park. As it gets late, everyone is ready to go home and leave the park. The park is a circular graph (a ring) with mm exits. For convenience, we number the people from 11 to nn, and number the exits from 11 to mm in counterclockwise order.

The total length of the park is LL meters. We define the position of exit 11 as 00 meters. Then for exit i (2im)i\ (2\le i\le m), it is located aia_i meters counterclockwise from exit 11. The sequence aia_i is strictly increasing, so exits i (1i<m)i\ (1\le i < m) and i+1i+1 are adjacent. Since the park is a ring, exit mm and exit 11 are also adjacent. Each exit also has a capacity limit lil_i, meaning that at most lil_i people can leave through exit ii.

When going home, each person will keep moving in their own direction, either clockwise or counterclockwise. When they reach an exit that still allows someone to leave, they will leave the park through that exit. In particular, if two people arrive at an exit that can allow only 11 person to leave at the same time, the person with the smaller index leaves through that exit, and the person with the larger index continues moving.

Now you are given the initial position and moving direction of each of the nn people. Please determine which exit each person leaves from. If person ii leaves from exit kik_i, you only need to output the XOR sum of i×kii\times k_i, that is:

$$(1\times k_1) \operatorname{xor} (2\times k_2) \operatorname{xor}\cdots \operatorname{xor} (n\times k_n)$$

where xor\operatorname{xor} is the bitwise XOR operation. In particular, if a person cannot leave in the end, then ki=0k_i = 0.

Input Format

The first line contains three positive integers n,m,Ln, m, L, as described above.

The second line contains m1m - 1 positive integers ai (2im)a_i\ (2\le i \le m), representing the exit positions. It is guaranteed that aia_i is strictly increasing.

The third line contains mm positive integers lil_i, representing the capacity limit of each exit.

The next nn lines each contain two integers si,bi (1in)s_i, b_i\ (1 \le i \le n). If sis_i is 00, it means person ii moves counterclockwise; if sis_i is 11, it means person ii moves clockwise. bib_i means the starting position of person ii is the point bib_i meters counterclockwise from exit 11.

Output Format

Output one integer in a single line, representing the answer.

3 2 5
2
2 1
0 1
1 3
0 4
3
3 2 5
2 
1 1
0 0 
0 2 
0 1
5

Hint

Explanation of Sample 1

People 1,2,31, 2, 3 leave through exits 2,1,12, 1, 1, respectively.

Explanation of Sample 2

People 1,21, 2 leave through exits 1,21, 2, respectively, and person 33 cannot leave the park.

Constraints

For 12%12\% of the testdata: n,m,L10n, m, L \le 10.

For 32%32\% of the testdata: n,m100n, m \le 100, L1000L \le 1000.

For 52%52\% of the testdata: n,m1000n, m \le 1000.

For another 20%20\% of the testdata: n,m10000n, m \le 10000, and all si=0s_i = 0.

For 100%100\% of the testdata: 1n,m2×1051 \le n,m \le 2 \times 10^5, 2L1092 \le L \le 10^9, 1ai<L1\le a_i < L, 1lin1\le l_i \le n, si{0,1}s_i\in\{0,1\}, 0bi<L0\le b_i < L.

Translated by ChatGPT 5