#P11745. Dynamic K-th Problem
Dynamic K-th Problem
Background
Fireflies pass through the wind, melt into flying light, and bloom in your eyes.
Problem Description
Xiao D found a group of fireflies. There are fireflies in the group, arranged in a line in order and numbered from to . Xiao D is very capable: at a glance he knows the brightness of these fireflies, and the brightness values form a permutation of . Xiao D wants to pick some fireflies so that they can weave a dreamy, dazzling curtain of light. Specifically, he needs a firefly interval.
Xiao D has strict requirements for a firefly interval: it must contain at least fireflies, and their indices must be consecutive.
Xiao D greatly admires the light of the fireflies. He defines the overall brightness value of the firefly interval from index to as the -th largest number among the brightness values of those fireflies. Xiao D is given thresholds. Each threshold gives a number . You need to find how many firefly intervals have an overall brightness value greater than or equal to . Of course, there can be many such intervals, and you need to help Xiao D count them.
Input Format
The first line contains five integers , where is a given constant, and is the Subtask ID of the current test point.
The second line contains integers separated by spaces, representing the brightness values of the fireflies. They are generated by the given code.
The third line contains an integer , denoting the number of thresholds.
The fourth line contains integers separated by spaces, representing the threshold for each query, generated by the given code.
The input size of this problem is large. The input data can be generated by the following code: The full code can be viewed here.
// 请注意避免整形溢出
#define int long long
const int N = 1e6 + 5, INF = 2147483647;
int n, k, m, B, Q, x, a[N], cas;
// myrand 为数据生成器
struct myrand {
int A, B, P, x;
myrand(int A, int B, int P, int x) {
this->A = A; this->B = B; this->P = P; this->x = x;
} int next() { return x = (A * x + B) % P; }
};
int read_x(int x) { // 不同数据下的 x 不同
if (cas == 7) x = x % 2;
else x = x % (n + 1);
return x;
}
signed main() {
cin >> n >> k >> m >> B >> cas >> Q;
// B 是生成数据是给定常数。在此初始化数据生成器 myrand 参数
myrand rnd(16807, B, INF, 0);
// 伪随机生成 a 序列
for (int i = 1; i <= n; i++) a[i] = i;
for (int i = 1; i <= n; i++) {
int l = rnd.next() % n + 1, r = rnd.next() % n + 1;
swap(a[l], a[r]);
}
// 生成查询指标
for (int i = 1; i <= Q; i++) x = read_x(rnd.next());
}
You only need to generate the input according to the code above. For specific operation explanations, please refer to the sample explanation. The solution to this problem is unrelated to how the data is generated.
Output Format
For each query threshold, you need to compute the number of corresponding firefly intervals.
To avoid excessive output, please output the xor sum of the numbers of firefly intervals over the queries. For specific operation explanations, please refer to the sample explanation.
5 3 2 999 1
5
6
6 3 2 998 1
5
3
1000000 10000 1 998244353 4
1000000
306558155574
1000000 10000 2 998244353 5
1000000
39831215473
1000000 100000 100 1231 8
1000000
170979323511
Hint
[Sample Explanation ]
The brightness values of the fireflies from to are: . There are firefly intervals in total. We take the -nd largest value in each interval; they are:
- The fireflies with indices to are , and the overall brightness value is .
- The fireflies with indices to are , and the overall brightness value is .
- The fireflies with indices to are , and the overall brightness value is .
- The fireflies with indices to are , and the overall brightness value is .
- The fireflies with indices to are , and the overall brightness value is .
- The fireflies with indices to are , and the overall brightness value is .
There are queries. The thresholds are , so the answers are . The total xor value is .
[Sample Explanation ]
The brightness values of the fireflies from to are: .
There are queries. The thresholds are , and the answers are . The total xor value is .
[Sample Explanation ] This testdata satisfies the constraints of Subtask 4. The detailed solution is not explained. Please pay attention to integer overflow issues.
[Sample Explanation ] This testdata satisfies the constraints of Subtask 5. The detailed solution is not explained.
[Sample Explanation ] This testdata satisfies the constraints of Subtask 8. The detailed solution is not explained.
[Constraints and Notes]
This problem uses bundled subtask testing. The input/output size is not very large, but please optimize constants. This problem automatically enables O2 optimization.
- Subtask 1 (10 pts): , .
- Subtask 2 (10 pts): , .
- Subtask 3 (18 pts): , .
- Subtask 4 (9 pts): , .
- Subtask 5 (9 pts): , .
- Subtask 6 (15 pts): , .
- Subtask 7 (7 pts): , , .
- Subtask 8 (22 pts): , .
For all test points: , , , , .
Translated by ChatGPT 5