版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hhhhhhxh/article/details/81569157
题意:n个数,通过一个算法和生成器X,Y,Z生成m组更新。每次将
中小于v的数更新为v。
求m次更新后
的值。其中
为异或。
题目中的主要矛盾是要快速的将区间内的值进行更新。参照了dls的代码,可以巧妙的通过st表来实现。
由于更新操作是区间取max,若将 分为 和 并且 然后分这两个区间更新是完全可以的。联系到st表的初始化和查询过程。可以将初始化和查询的过程倒过来。
对于一般的st表查询操作,若要查询[l, r]的值,一般是查询 和 两者然后合并。这里可以将其视为打标记的过程。
m次更新后,再将每个大的子区间更新到它的左右子区间内,一直更新到叶子节点。然后算一遍就行。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 100000 + 5;
int T, n, m, st[25][maxn], Log[maxn];
unsigned X, Y, Z;
unsigned RNG61() {
unsigned W;
X = X ^ (X << 11);
X = X ^ (X >> 4);
X = X ^ (X << 5);
X = X ^ (X >> 14);
W = X ^ (Y ^ Z);
X = Y;
Y = Z;
Z = W;
return Z;
}
void update(int l, int r, int v) {
int d = Log[r - l + 1];
st[d][l] = max(st[d][l], v);
st[d][r - (1 << d) + 1] = max(st[d][r - (1 << d) + 1], v);
}
int main() {
#ifdef __APPLE__
freopen("1.in", "r", stdin);
freopen("1.out", "w", stdout);
#endif
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
Log[2] = 1;
for (int i = 3; i <= 100003; i++) {
Log[i] = Log[i >> 1] + 1;
// cout << Log[i] << endl;
}
cin >> T;
while (T--) {
cin >> n >> m >> X >> Y >> Z;
for (int j = 0; j < 20; j++) {
for (int i = 1; i <= n; i++) {
st[j][i] = 0;
}
}
while (m--) {
int x = RNG61() % n + 1, y = RNG61() % n + 1, z = RNG61() % (1 << 30);
update(min(x, y), max(x, y), z);
// cout << x << " " << y << " " << z << endl;
}
for (int j = 19; j >= 1; j--) {
for (int i = 1; i + (1 << j) - 1 <= n; i++) {
st[j - 1][i] = max(st[j - 1][i], st[j][i]);
st[j - 1][i + (1 << j - 1)] = max(st[j - 1][i + (1 << j - 1)], st[j][i]);
}
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
// cout << st[0][i] << endl;
ans ^= 1ll * i * (ll)st[0][i];
}
cout << ans << endl;
}
}