QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#384953 | #4405. 普罗霍洛夫卡 | alpha1022 | 100 ✓ | 6786ms | 44208kb | C++14 | 4.3kb | 2024-04-10 14:06:36 | 2024-04-10 14:06:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int BUFF_SIZE = 1 << 20;
char BUFF[BUFF_SIZE], *BB, *BE;
char gc() { return BB == BE ? (BE = (BB = BUFF) + fread(BUFF, 1, BUFF_SIZE, stdin), BB == BE ? EOF : *BB++) : *BB++; }
void read() {}
template<class T, class ...Ts>
void read(T &x, Ts &...args) {
x = 0; char ch = 0, w = 0;
while (ch < '0' || ch > '9') w |= ch == '-', ch = gc();
while (ch >= '0' && ch <= '9') x = x * 10 + (ch ^ '0'), ch = gc();
if (w) x = -x;
read(args...);
}
const int N = 4e5;
const int W = 8;
const int B = 1 << W;
const int CNT = (N + B - 1) >> W;
int n, m;
int a[N + 5], las[N + 5];
int ans[N + 5];
vector<pair<int, int>> qry[N + 5];
struct SqrtDecompositon {
int pos[N + 5];
int a[N + 5], sav[N + 5], add[CNT + 5];
bool vis[CNT + 5];
int val[2][N + 5], sum[2][CNT + 5];
int del[CNT + 5][B][2], tag[2][CNT + 5][B][2];
int t0[B << 1], t1[B << 1];
void build(int p) {
int l = ((p - 1) << W) + 1, r = min(p << W, n);
if (add[p]) {
vis[p] = 1;
for (int i = l; i <= r; ++i) a[i] += add[p];
add[p] = 0;
}
if (vis[p]) {
memset(t0, 0, sizeof t0), memset(t1, 0, sizeof t1);
for (int i = l; i <= r; ++i) t0[B ^ (a[i] & (B - 1))] ^= 1;
for (int i = 0; i < B; ++i) del[p][(B - 1) ^ i][1] = t0[B ^ i];
for (int k = W - 1; k >= 0; --k)
for (int i = 0; i < 1 << k; ++i)
t0[(1 << k) ^ i] = t0[(2 << k) ^ i] ^ t0[(3 << k) ^ i];
for (int k = 0; k < W; ++k)
for (int i = 0; i < 1 << k; ++i)
t1[(2 << k) ^ i] = t1[(3 << k) ^ i] = t1[(1 << k) ^ i] ^= t0[((2 << k) - 1) ^ i] << k;
for (int i = 0; i < B; ++i) del[p][i][0] = t1[B ^ i] ^= t0[((B << 1) - 1) ^ i] << W;
vis[p] = 0;
}
for (int op = 0; op < 2; ++op) {
memset(t0, 0, sizeof t0), memset(t1, 0, sizeof t1);
for (int i = 0; i < B; ++i) t0[((B << 1) - 1) ^ i] = ((t1[B ^ i] = tag[op][p][i][0]) << W) ^ tag[op][p][i][1];
for (int i = 0; i < B; ++i) tag[op][p][i][0] = tag[op][p][i][1] = 0;
for (int k = W - 1; k >= 0; --k)
for (int i = 0; i < 1 << k; ++i)
t0[((2 << k) - 1) ^ i] ^= (t1[(1 << k) ^ i] = t1[(2 << k) ^ i] ^ t1[(3 << k) ^ i]) << k;
for (int k = 0; k < W; ++k)
for (int i = 0; i < 1 << k; ++i)
t0[(2 << k) ^ i] ^= t0[(1 << k) ^ i], t0[(3 << k) ^ i] ^= t0[(1 << k) ^ i];
sum[op][p] = 0;
for (int i = l; i <= r; ++i) sum[op][p] ^= val[op][i] ^= t0[B ^ (sav[i] & (B - 1))];
}
for (int i = l; i <= r; ++i) sav[i] = a[i];
}
void update(bool op, int l, int r) {
for (int i = l; i <= min(pos[l] << W, r); ++i) val[op][i] ^= (a[i] + add[pos[l]]) ^ (a[i] + add[pos[l]] + 1), ++a[i];
vis[pos[l]] = 1, build(pos[l]);
if (pos[l] == pos[r]) return ;
for (int i = ((pos[r] - 1) << W) + 1; i <= r; ++i) val[op][i] ^= (a[i] + add[pos[r]]) ^ (a[i] + add[pos[r]] + 1), ++a[i];
vis[pos[r]] = 1, build(pos[r]);
for (int p = pos[l] + 1; p < pos[r]; ++p) {
int l = ((p - 1) << W) + 1, r = p << W;
if (((a[l] + add[p] + 1) ^ (a[r] + add[p])) >> W) {
int v = (a[l] + add[p] + 1) >> W; v = (v ^ (v - 1) ^ 1) << W;
if (del[p][add[p] & (B - 1)][1]) sum[op][p] ^= v;
tag[op][p][add[p] & (B - 1)][1] ^= v;
}
sum[op][p] ^= del[p][add[p] & (B - 1)][0], tag[op][p][add[p] & (B - 1)][0] ^= 1, ++add[p];
}
}
int query(bool op, int l, int r) {
int ret = 0;
build(pos[l]);
for (int i = l; i <= min(pos[l] << W, r); ++i) ret ^= val[op][i];
if (pos[l] == pos[r]) return ret;
build(pos[r]);
for (int i = ((pos[r] - 1) << W) + 1; i <= r; ++i) ret ^= val[op][i];
for (int p = pos[l] + 1; p < pos[r]; ++p) ret ^= sum[op][p];
return ret;
}
void init() {
for (int i = 1; i <= n; ++i) pos[i] = (i + B - 1) >> W;
for (int p = 1; p <= pos[n]; ++p) build(p);
}
} sd;
int main() {
read(n, m);
for (int i = 1; i <= n; ++i) read(a[i]);
for (int i = 1; i <= m; ++i) {
int l, r; read(l, r), qry[r].emplace_back(l, i);
}
sd.init();
for (int i = 1; i <= n; ++i) {
sd.update(i & 1, las[a[i]] + 1, i), las[a[i]] = i;
for (auto [l, id]: qry[i]) ans[id] = sd.query(i & 1, l, i);
}
for (int i = 1; i <= m; ++i) printf("%d\n", ans[i]);
}
详细
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 0ms
memory: 22288kb
Test #2:
score: 0
Accepted
time: 3ms
memory: 18160kb
Test #3:
score: 0
Accepted
time: 2ms
memory: 22320kb
Test #4:
score: 0
Accepted
time: 4ms
memory: 20192kb
Test #5:
score: 0
Accepted
time: 3ms
memory: 18208kb
Subtask #2:
score: 5
Accepted
Dependency #1:
100%
Accepted
Test #6:
score: 5
Accepted
time: 58ms
memory: 22580kb
Test #7:
score: 0
Accepted
time: 58ms
memory: 18548kb
Test #8:
score: 0
Accepted
time: 70ms
memory: 20680kb
Test #9:
score: 0
Accepted
time: 59ms
memory: 18624kb
Test #10:
score: 0
Accepted
time: 59ms
memory: 22508kb
Subtask #3:
score: 10
Accepted
Dependency #2:
100%
Accepted
Test #11:
score: 10
Accepted
time: 1283ms
memory: 26676kb
Test #12:
score: 0
Accepted
time: 1274ms
memory: 26852kb
Test #13:
score: 0
Accepted
time: 1285ms
memory: 28384kb
Test #14:
score: 0
Accepted
time: 1295ms
memory: 27920kb
Test #15:
score: 0
Accepted
time: 1288ms
memory: 28204kb
Subtask #4:
score: 10
Accepted
Dependency #3:
100%
Accepted
Test #16:
score: 10
Accepted
time: 2777ms
memory: 33556kb
Test #17:
score: 0
Accepted
time: 2777ms
memory: 33992kb
Test #18:
score: 0
Accepted
time: 2793ms
memory: 33568kb
Test #19:
score: 0
Accepted
time: 2802ms
memory: 33608kb
Test #20:
score: 0
Accepted
time: 2800ms
memory: 33672kb
Subtask #5:
score: 10
Accepted
Dependency #4:
100%
Accepted
Test #21:
score: 10
Accepted
time: 4526ms
memory: 38952kb
Test #22:
score: 0
Accepted
time: 4517ms
memory: 39032kb
Test #23:
score: 0
Accepted
time: 4565ms
memory: 39104kb
Test #24:
score: 0
Accepted
time: 4572ms
memory: 38768kb
Test #25:
score: 0
Accepted
time: 4571ms
memory: 38904kb
Subtask #6:
score: 10
Accepted
Dependency #5:
100%
Accepted
Test #26:
score: 10
Accepted
time: 5495ms
memory: 41476kb
Test #27:
score: 0
Accepted
time: 5542ms
memory: 41368kb
Test #28:
score: 0
Accepted
time: 5513ms
memory: 41936kb
Test #29:
score: 0
Accepted
time: 5558ms
memory: 41336kb
Test #30:
score: 0
Accepted
time: 5593ms
memory: 41412kb
Subtask #7:
score: 10
Accepted
Test #31:
score: 10
Accepted
time: 1337ms
memory: 26000kb
Test #32:
score: 0
Accepted
time: 1329ms
memory: 27160kb
Test #33:
score: 0
Accepted
time: 1327ms
memory: 25792kb
Test #34:
score: 0
Accepted
time: 1329ms
memory: 27556kb
Test #35:
score: 0
Accepted
time: 1343ms
memory: 24772kb
Subtask #8:
score: 10
Accepted
Test #36:
score: 10
Accepted
time: 3177ms
memory: 42988kb
Test #37:
score: 0
Accepted
time: 3173ms
memory: 42944kb
Test #38:
score: 0
Accepted
time: 3166ms
memory: 43308kb
Test #39:
score: 0
Accepted
time: 3185ms
memory: 44076kb
Test #40:
score: 0
Accepted
time: 3180ms
memory: 44052kb
Subtask #9:
score: 10
Accepted
Dependency #8:
100%
Accepted
Test #41:
score: 10
Accepted
time: 3263ms
memory: 42836kb
Test #42:
score: 0
Accepted
time: 3257ms
memory: 42848kb
Test #43:
score: 0
Accepted
time: 3247ms
memory: 42824kb
Test #44:
score: 0
Accepted
time: 3281ms
memory: 43112kb
Test #45:
score: 0
Accepted
time: 3264ms
memory: 42916kb
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: 6583ms
memory: 44060kb
Test #47:
score: 0
Accepted
time: 6593ms
memory: 44092kb
Test #48:
score: 0
Accepted
time: 6604ms
memory: 44088kb
Test #49:
score: 0
Accepted
time: 6671ms
memory: 44208kb
Test #50:
score: 0
Accepted
time: 6786ms
memory: 43968kb