QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#837794 | #4405. 普罗霍洛夫卡 | hhoppitree | 100 ✓ | 14206ms | 62720kb | C++23 | 3.6kb | 2024-12-30 13:39:22 | 2024-12-30 13:39:23 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5, B = 256, S = N / B + 5;
int tr[B], _lg[B];
int wh(int x) {
return ((x - 1) >> 8) + 1;
}
int n, c[N];
int f(int x) {
return ((~x) & (-~x)) * 2 - 1;
}
int b[2][N], lz[S], sum[2][S];
int wgt[S][B];
bool cnt[S][2][B];
vector<int> hv[S][B];
int ct[B << 1], g[2][B << 1];
void push(int x) {
for (int i = 0; i < 2; ++i) {
memset(ct, 0, sizeof(ct));
for (int j = 0; j < B; ++j) {
if (cnt[x][i][j]) ct[tr[j] + B] = 1;
}
for (int j = B - 1; j; --j) ct[j] = ct[j << 1] ^ ct[j << 1 | 1];
g[i][1] = ct[1];
for (int j = 2; j < B * 2; ++j) {
g[i][j] = g[i][j >> 1];
if (j < B && ct[j]) g[i][j] ^= 1 << _lg[j];
}
}
for (int i = (x - 1) * B + 1; i <= x * B && i <= n; ++i) {
for (int j = 0; j < 2; ++j) {
b[j][i] ^= g[j][tr[~c[i] & (B - 1)] + B];
}
c[i] += lz[x];
}
lz[x] = 0;
}
void build(int x) {
sum[0][x] = sum[1][x] = 0;
memset(cnt[x], 0, sizeof(cnt[x]));
memset(wgt[x], 0, sizeof(wgt[x]));
for (int i = 0; i < B; ++i) hv[x][i].clear();
memset(ct, 0, sizeof(ct));
for (int i = (x - 1) * B + 1; i <= x * B && i <= n; ++i) {
sum[0][x] ^= b[0][i], sum[1][x] ^= b[1][i];
ct[tr[c[i] & (B - 1)] + B] ^= 1;
hv[x][~c[i] & (B - 1)].push_back(i);
}
for (int j = B - 1; j; --j) ct[j] = ct[j << 1] ^ ct[j << 1 | 1];
g[0][1] = ct[1];
for (int j = 2; j < B * 2; ++j) {
g[0][j] = g[0][j >> 1];
if (j < B && ct[j]) g[0][j] ^= 1 << _lg[j];
}
for (int j = 0; j < B; ++j) wgt[x][j] = g[0][tr[~j & (B - 1)] + B];
}
void opt(int z, int x) {
sum[z][x] ^= wgt[x][lz[x] & (B - 1)], cnt[x][z][lz[x] & (B - 1)] ^= 1;
for (auto v : hv[x][lz[x] & (B - 1)]) {
b[z][v] ^= f(c[v] + lz[x]) ^ (B - 1);
sum[z][x] ^= f(c[v] + lz[x]) ^ (B - 1);
}
++lz[x];
}
void modify(int z, int l, int r) {
if (wh(l) == wh(r)) {
push(wh(l));
for (int i = l; i <= r; ++i) b[z][i] ^= f(c[i]++);
build(wh(l));
return;
}
int L = wh(l), R = wh(r);
push(L), push(R);
for (int i = l; i <= L * B; ++i) b[z][i] ^= f(c[i]++);
for (int i = (R - 1) * B + 1; i <= r; ++i) b[z][i] ^= f(c[i]++);
build(L), build(R);
for (int i = L + 1; i <= R - 1; ++i) opt(z, i);
}
int query(int z, int l, int r) {
int res = 0;
if (wh(l) == wh(r)) {
push(wh(l));
for (int i = l; i <= r; ++i) res ^= b[z][i];
build(wh(l));
return res;
}
int L = wh(l), R = wh(r);
push(L), push(R);
for (int i = l; i <= L * B; ++i) res ^= b[z][i];
for (int i = (R - 1) * B + 1; i <= r; ++i) res ^= b[z][i];
build(L), build(R);
for (int i = L + 1; i <= R - 1; ++i) res ^= sum[z][i];
return res;
}
int a[N], pre[N], lst[N], res[N];
vector< pair<int, int> > qr[N];
signed main() {
for (int i = 1; i < B; ++i) {
tr[i] = (tr[i >> 1] >> 1) | ((i & 1) ? B >> 1 : 0);
if (i != 1) _lg[i] = _lg[i >> 1] + 1;
}
int q; scanf("%d%d", &n, &q);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
lst[i] = pre[a[i]] + 1;
pre[a[i]] = i;
}
for (int i = 1, l, r; i <= q; ++i) {
scanf("%d%d", &l, &r);
qr[r].push_back({i, l});
}
for (int i = 1; i <= n; ++i) {
modify(i & 1, lst[i], i);
for (auto [x, y] : qr[i]) res[x] = query(i & 1, y, i);
}
for (int i = 1; i <= q; ++i) printf("%d\n", res[i]);
return 0;
}
詳細信息
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 3ms
memory: 11992kb
Test #2:
score: 5
Accepted
time: 3ms
memory: 12032kb
Test #3:
score: 5
Accepted
time: 4ms
memory: 14080kb
Test #4:
score: 5
Accepted
time: 0ms
memory: 12120kb
Test #5:
score: 5
Accepted
time: 3ms
memory: 12180kb
Subtask #2:
score: 5
Accepted
Dependency #1:
100%
Accepted
Test #6:
score: 5
Accepted
time: 81ms
memory: 10624kb
Test #7:
score: 5
Accepted
time: 86ms
memory: 14708kb
Test #8:
score: 5
Accepted
time: 82ms
memory: 12544kb
Test #9:
score: 5
Accepted
time: 78ms
memory: 12580kb
Test #10:
score: 5
Accepted
time: 82ms
memory: 12736kb
Subtask #3:
score: 10
Accepted
Dependency #2:
100%
Accepted
Test #11:
score: 10
Accepted
time: 2243ms
memory: 25064kb
Test #12:
score: 10
Accepted
time: 2234ms
memory: 25052kb
Test #13:
score: 10
Accepted
time: 2224ms
memory: 24408kb
Test #14:
score: 10
Accepted
time: 2208ms
memory: 23312kb
Test #15:
score: 10
Accepted
time: 2214ms
memory: 26424kb
Subtask #4:
score: 10
Accepted
Dependency #3:
100%
Accepted
Test #16:
score: 10
Accepted
time: 5148ms
memory: 36412kb
Test #17:
score: 10
Accepted
time: 5218ms
memory: 39056kb
Test #18:
score: 10
Accepted
time: 5183ms
memory: 37232kb
Test #19:
score: 10
Accepted
time: 5197ms
memory: 38932kb
Test #20:
score: 10
Accepted
time: 5173ms
memory: 37328kb
Subtask #5:
score: 10
Accepted
Dependency #4:
100%
Accepted
Test #21:
score: 10
Accepted
time: 9014ms
memory: 51872kb
Test #22:
score: 10
Accepted
time: 9094ms
memory: 52444kb
Test #23:
score: 10
Accepted
time: 9051ms
memory: 51764kb
Test #24:
score: 10
Accepted
time: 8957ms
memory: 52212kb
Test #25:
score: 10
Accepted
time: 8883ms
memory: 50196kb
Subtask #6:
score: 10
Accepted
Dependency #5:
100%
Accepted
Test #26:
score: 10
Accepted
time: 11343ms
memory: 57468kb
Test #27:
score: 10
Accepted
time: 11271ms
memory: 57268kb
Test #28:
score: 10
Accepted
time: 11370ms
memory: 57368kb
Test #29:
score: 10
Accepted
time: 11388ms
memory: 57448kb
Test #30:
score: 10
Accepted
time: 11397ms
memory: 57252kb
Subtask #7:
score: 10
Accepted
Test #31:
score: 10
Accepted
time: 2166ms
memory: 16936kb
Test #32:
score: 10
Accepted
time: 2147ms
memory: 18564kb
Test #33:
score: 10
Accepted
time: 2151ms
memory: 16576kb
Test #34:
score: 10
Accepted
time: 2139ms
memory: 17024kb
Test #35:
score: 10
Accepted
time: 2138ms
memory: 15036kb
Subtask #8:
score: 10
Accepted
Test #36:
score: 10
Accepted
time: 4389ms
memory: 44936kb
Test #37:
score: 10
Accepted
time: 4367ms
memory: 42780kb
Test #38:
score: 10
Accepted
time: 4360ms
memory: 42764kb
Test #39:
score: 10
Accepted
time: 4331ms
memory: 44124kb
Test #40:
score: 10
Accepted
time: 4340ms
memory: 42604kb
Subtask #9:
score: 10
Accepted
Dependency #8:
100%
Accepted
Test #41:
score: 10
Accepted
time: 4522ms
memory: 45920kb
Test #42:
score: 10
Accepted
time: 4533ms
memory: 45004kb
Test #43:
score: 10
Accepted
time: 4526ms
memory: 45432kb
Test #44:
score: 10
Accepted
time: 4517ms
memory: 44732kb
Test #45:
score: 10
Accepted
time: 4578ms
memory: 45528kb
Subtask #10:
score: 15
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Dependency #5:
100%
Accepted
Dependency #6:
100%
Accepted
Dependency #7:
100%
Accepted
Dependency #8:
100%
Accepted
Dependency #9:
100%
Accepted
Test #46:
score: 15
Accepted
time: 13812ms
memory: 62620kb
Test #47:
score: 15
Accepted
time: 14085ms
memory: 62576kb
Test #48:
score: 15
Accepted
time: 13695ms
memory: 62544kb
Test #49:
score: 15
Accepted
time: 13791ms
memory: 62720kb
Test #50:
score: 15
Accepted
time: 14206ms
memory: 62632kb