QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#385404 | #7441. rpxleqxq | alpha1022 | 0 | 653ms | 78780kb | C++14 | 2.4kb | 2024-04-10 18:54:22 | 2024-04-10 18:54:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5;
const int Q = 1e6;
const int LG = 18;
const int W = 9;
int n, q, v;
int a[N + 5], pos[N + 5], block;
struct Query {
int l, r, id;
bool operator<(const Query &o) const {
return pos[l] != pos[o.l] ? pos[l] < pos[o.l] : pos[l] & 1 ? r < o.r : r > o.r;
}
} qry[Q + 5];
struct SqrtDecomposition {
int add[1 << W], val[1 << LG];
void clear() { memset(add, 0, sizeof add), memset(val, 0, sizeof val); }
int query(int x) { return add[x >> W] + val[x]; }
void insert(int x) {
for (int k = LG - 1; k >= W; --k)
if (v >> k & 1) {
int l = (x ^ v ^ (1 << k)) & ~((1 << k) - 1);
int r = l + (1 << k) - 1;
for (int i = l >> W; i < (r + 1) >> W; ++i) ++add[i];
}
for (int k = W - 1; k >= 0; --k)
if (v >> k & 1) {
int l = (x ^ v ^ (1 << k)) & ~((1 << k) - 1);
int r = l + (1 << k) - 1;
for (int i = l; i <= r; ++i) ++val[i];
}
}
} sd;
int f[N + 5];
vector<tuple<int, int, int, int>> upd[N + 5];
ll ans[Q + 5];
int main() {
scanf("%d%d", &n, &v), ++v;
for (int i = 1; i <= n; ++i)
scanf("%d", a + i), f[i] = sd.query(a[i]), sd.insert(a[i]), printf("%d%c", f[i], " \n"[i == n]);
scanf("%d", &q), block = ceil(n / sqrt(q));
for (int i = 1; i <= n; ++i) pos[i] = (i - 1) / block + 1;
for (int i = 1; i <= q; ++i) scanf("%d%d", &qry[i].l, &qry[i].r), qry[i].id = i;
sort(qry + 1, qry + q + 1);
for (int i = 1, l = 1, r = 0; i <= q; ++i) {
if (r < qry[i].r) upd[l - 1].emplace_back(r + 1, qry[i].r, -1, qry[i].id);
while (r < qry[i].r) ans[qry[i].id] += f[++r];
if (l > qry[i].l) upd[r].emplace_back(qry[i].l, l - 1, 1, qry[i].id);
while (l > qry[i].l) ans[qry[i].id] -= f[--l] + 1;
if (r > qry[i].r) upd[l - 1].emplace_back(qry[i].r + 1, r, 1, qry[i].id);
while (r > qry[i].r) ans[qry[i].id] -= f[r--];
if (l < qry[i].l) upd[r].emplace_back(l, qry[i].l - 1, -1, qry[i].id);
while (l < qry[i].l) ans[qry[i].id] += f[l++] + 1;
}
sd.clear();
for (int i = 1; i <= n; ++i) {
sd.insert(a[i]);
for (auto [l, r, w, id] : upd[i])
for (int j = l; j <= r; ++j) ans[id] += sd.query(a[j]) * w;
}
for (int i = 1; i <= q; ++i) ans[qry[i].id] += ans[qry[i - 1].id];
for (int i = 1; i <= q; ++i) printf("%lld\n", ans[i]);
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 12204kb
input:
11 4 11 4 5 1 4 1 9 1 9 8 10 5 1 4 1 9 1 9 8 10 8 10
output:
0 0 1 1 2 2 1 3 2 3 4 2 12 12 1 1
result:
wrong answer 1st numbers differ - expected: '2', found: '0'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #2:
0%
Subtask #5:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 653ms
memory: 78780kb
input:
200000 50 4 83 4 57 16 32 21 19 19 30 10 84 62 10 21 59 14 72 60 38 90 26 23 4 10 59 43 1 82 9 94 27 3 58 12 8 54 97 30 74 63 44 15 22 17 20 45 100 55 3 65 23 18 53 53 4 28 90 1 31 88 15 64 42 3 83 12 84 19 8 56 85 49 6 57 97 97 22 59 14 64 3 22 17 61 22 92 79 5 88 53 20 83 13 28 85 28 77 44 19 1 85...
output:
0 0 1 0 3 4 4 5 6 7 8 1 7 9 11 11 12 2 11 10 3 15 17 15 17 17 15 18 4 22 5 23 21 20 24 25 21 2 28 7 21 25 28 32 33 34 25 4 26 31 9 37 38 32 33 37 43 8 36 44 9 40 12 35 40 12 43 13 47 45 41 14 41 46 40 8 9 54 43 49 18 48 58 59 46 61 15 20 54 17 49 64 21 56 67 20 68 24 53 67 59 22 15 16 23 23 30 31 32...
result:
wrong answer 1st numbers differ - expected: '342347193', found: '0'
Subtask #6:
score: 0
Skipped
Dependency #1:
0%