33OJ
登录 注册

#P17880. 玉兰 / yulan

    ID: 20669 远端评测题 2000ms 2048MiB 尝试: 0 已通过: 0 显示难度NOI/NOI+/CTS 上传者: 标签>线段树平衡树洛谷原创O2优化分治可持久化线段树洛谷月赛

玉兰 / yulan

Problem Description

Given two sequences of positive integers a,ba,b of length nn, the inverse Cantor expansion sequence of a sequence cc is defined as follows:

  • Let mm be the length of the sequence. For all 1≤i≤m1\le i\le m, set ci←min⁡{ci,i}c_i\gets \min\{c_i,i\};
  • Construct a permutation pp of 1∼m1\sim m such that for all 1≤i≤m1\le i\le m, ∑j=1i[pj≤pi]=ci\sum_{j=1}^{i}[p_j\le p_i]=c_i. It can be proved that such a pp exists and is unique; this permutation pp is the inverse Cantor expansion sequence of cc. Here [P][P] equals 11 if the proposition PP is true, and 00 otherwise.

There are qq queries. Each query gives l,r,kl,r,k; consider the sequence formed by ala_l copies of blb_l, al+1a_{l+1} copies of bl+1b_{l+1}, ⋯\cdots, ara_r copies of brb_r in this order, and find the value of the kk-th element of its inverse Cantor expansion sequence.

The input of this problem is encrypted. The input gives typetype. Let the three numbers read in a query be l′,r′,k′l',r',k', and let the answer to the previous query be lstlst (if this is the first query, lst=0lst=0). Then $l=l'\oplus (lst\times type),r=r' \oplus (lst\times type),k=k'\oplus (lst\times type)$, where ⊕\oplus denotes the bitwise XOR operation.

Input Format

The first line of the input contains two non-negative integers c,typec,type, the testcase number and the encryption parameter, respectively. c=0c=0 means this testcase is a sample.

The second line contains two positive integers n,qn, q, the length of the sequences and the number of queries, respectively.

The third line contains nn positive integers a1,a2,…,ana_1, a_2, \ldots, a_n.

The fourth line contains nn positive integers b1,b2,…,bnb_1, b_2, \ldots, b_n.

The (i+4)(i+4)-th line of the input (1≤i≤q)(1\le i\le q) contains three non-negative integers l′,r′,k′l',r',k', the encrypted l,r,kl,r,k, respectively.

Output Format

For each query, output one line containing a single number, the value of the kk-th element of the inverse Cantor expansion sequence of the sequence formed by ala_l copies of blb_l, al+1a_{l+1} copies of bl+1b_{l+1}, ⋯\cdots, ara_r copies of brb_r in this order.

0 0
4 7
2 1 3 1
2 4 2 1
1 4 2
1 4 5
1 3 2
2 3 1
2 3 4
3 3 2
4 4 1
6
4
5
1
2
3
1
0 1
4 7
2 1 3 1
2 4 2 1
1 4 2
7 2 3
5 7 6
7 6 4
3 2 5
1 1 0
7 7 2
6
4
5
1
2
3
1
0 0
6 5
1000000000 1000000000 1000000000 1000000000 1000000000 2
1 1 1 1 1 1000000000
1 5 1
1 6 5000000000
1 6 5000000002
6 6 2
2 6 2
5000000000
1
1000000000
2
4000000001

Hint

【Sample 1 Explanation】

The intervals of the first two queries are both [1,4][1,4]. After expansion we get [2,2,4,2,2,2,1][2,2,4,2,2,2,1]; taking the minimum of the ii-th term and ii gives [1,2,3,2,2,2,1][1,2,3,2,2,2,1]. The corresponding permutation is [2,6,7,5,4,3,1][2,6,7,5,4,3,1], whose 22-nd and 55-th terms are 66 and 44, respectively.

【Sample 2 Explanation】

This sample satisfies type=1type=1, and the sequences and the decrypted queries are the same as in Sample 1.

【Sample 3 Explanation】

The permutation obtained by the first query is [5×109,5×109−1,…,1][5\times 10^9,5\times 10^9-1,\ldots,1], whose first number is 5×1095\times 10^9.

【Sample 4】

See yulan/yulan4.in and yulan/yulan4.ans in the contestant directory.

This sample satisfies the constraints of testcase 11.

【Sample 5】

See yulan/yulan5.in and yulan/yulan5.ans in the contestant directory.

This sample satisfies the constraints of testcase 22.

【Sample 6】

See yulan/yulan6.in and yulan/yulan6.ans in the contestant directory.

This sample satisfies the constraints of testcases 3∼43\sim 4.

【Sample 7】

See yulan/yulan7.in and yulan/yulan7.ans in the contestant directory.

This sample satisfies the constraints of testcases 5∼65\sim 6.

【Sample 8】

See yulan/yulan8.in and yulan/yulan8.ans in the contestant directory.

This sample satisfies the constraints of testcases 7∼97\sim 9.

【Sample 9】

See yulan/yulan9.in and yulan/yulan9.ans in the contestant directory.

This sample satisfies the constraints of testcase 1010.

【Sample 10】

See yulan/yulan10.in and yulan/yulan10.ans in the contestant directory.

This sample satisfies the constraints of testcase 1111.

【Sample 11】

See yulan/yulan11.in and yulan/yulan11.ans in the contestant directory.

This sample satisfies the constraints of testcases 12∼1312\sim 13.

【Sample 12】

See yulan/yulan12.in and yulan/yulan12.ans in the contestant directory.

This sample satisfies the constraints of testcases 14∼1514\sim 15.

【Sample 13】

See yulan/yulan13.in and yulan/yulan13.ans in the contestant directory.

This sample satisfies the constraints of testcase 1616.

【Sample 14】

See yulan/yulan14.in and yulan/yulan14.ans in the contestant directory.

This sample satisfies the constraints of testcase 1717.

【Sample 15】

See yulan/yulan15.in and yulan/yulan15.ans in the contestant directory.

This sample satisfies the constraints of testcases 18∼1918\sim 19.

【Sample 16】

See yulan/yulan16.in and yulan/yulan16.ans in the contestant directory.

This sample satisfies the constraints of testcases 20∼2120\sim 21.

【Sample 17】

See yulan/yulan17.in and yulan/yulan17.ans in the contestant directory.

This sample satisfies the constraints of testcases 22∼2522\sim 25.

【Constraints】

For all testdata:

  • 1≤n≤5×1051\le n\le 5\times10^5;
  • 1≤q≤5×1051\le q\le 5\times10^5;
  • type∈{0,1}type\in\{0,1\};
  • For all 1≤i≤n1\le i\le n, 1≤ai,bi≤1091\le a_i,b_i\le 10^9;
  • For each query, 1≤l≤r≤n1\le l\le r\le n and 1≤k≤∑i=lrai1\le k\le \sum_{i=l}^ra_i.

::cute-table{tuack} |Testcase No. |n,q≤n,q\le |type=type=|Special Property| |:-------:|:--------:|:-----:|:--:| |11 |1818 |00 |A | |22 |500500 |^ |^ | |3,43,4 |2 5002\,500 |^ |^ | |5,65,6 |8 0008\,000 |^ |^ | |7∼97\sim 9|^ |^ |None | |1010 |10510^5 |^ |A | |1111 |^ |^ |B | |12,1312,13 |^ |^ |None | |14,1514,15 |^ |11 |^ | |1616 |5×1055\times 10^5|00 |A | |1717 |^ |^ |B | |18,1918,19 |^ |^ |None | |20,2120,21 |^ |11 |A | |22∼2522\sim 25 |^ |^ |None |

Special Property A: For all 1≤i≤n1\le i\le n, ai=1a_i=1.

Special Property B: For all 1≤i<n1\le i<n, bi≤bi+1b_i\le b_{i+1}.

Translated by QwenWork