#P15107. 【模板】Wavelet Matrix / 小波矩阵
【模板】Wavelet Matrix / 小波矩阵
Background
Please note that this problem has unusual Constraints and time/memory limits.
Problem Description
Given a sequence of length . There are queries, each given :
- If , query how many numbers in the range are less than .
- If , query the -th smallest number in the range .
Forced online.
Input Format
Because the IO volume is too large, the testdata is generated randomly. You can use the following method to obtain and each query’s :
typedef unsigned uint;
const int MAXN = 4e6 + 10;
const uint mask = 0x5f3759dfu;
uint seed, lst;
inline uint rnd() {
seed ^= lst ^ mask;
seed ^= seed << 13;
seed ^= seed >> 7;
seed ^= seed << 17;
seed ^= lst ^ mask;
return seed;
}
int n, m; uint a[MAXN];
int main() {
scanf("%d%d%u", &n, &m, &seed);
for (int i = 1; i <= n; i++) a[i] = rnd();
for (int i = 1; i <= m; i++) {
uint op = rnd() & 1, l = rnd() % n + 1, r = rnd() % n + 1;
if (l > r) swap(l, r);
if (op) {
uint k = rnd() % (r - l + 1) + 1;
// do sth...
} else {
uint k = rnd();
// do sth...
}
}
}
Here, denotes the answer of the previous query, and its initial value is .
Output Format
Output one non-negative integer per line, which is the XOR sum of the answers to all queries.
5 5 114514
1562674565
114 514 1919
903488587
5000 5000 998244353
1845377756
2000000 2000000 1004535809
1498751009
4000000 4000000 1000000007
981318194
Hint
Sample 1 Explanation
The decrypted input is as follows:
5 5
3453473247 1341133007 2686835293 4244725722 2878739094
0 3 5 4197138810
1 2 5 2
1 2 3 2
1 1 5 2
1 3 5 3
The first line is , the second line is , and the next lines are the queries.
Constraints
This problem uses bundled testdata.
| Score | ||
|---|---|---|
For of the testdata, , . Within the same Subtask, the testdata has multiple levels.
Please pay attention to the effect of constant factors on time and memory efficiency. In particular, note that there are also differences between and .
Translated by ChatGPT 5