QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#404232 | #6330. XOR Reachable | comeintocalm# | WA | 0ms | 3876kb | C++20 | 2.7kb | 2024-05-03 16:32:12 | 2024-05-03 16:32:14 |
Judging History
answer
#include <bits/stdc++.h>
#define LL long long
#define db double
using namespace std;
const int MAXN = 1e5 + 5, N = 9999;
int n, m, K, Q;
int c[MAXN];
int lka[MAXN], lkb[MAXN];
int Rt, tot, ID;
int son[MAXN * 30][2];
vector<int> vec[MAXN * 30];
void ins (int &x, int S, int dep = 29) {
if (!x) x = ++tot;
if (dep == -1) {
vec[x].push_back (ID);
//cout << x << " " << ID << endl;
return ;
}
ins (son[x][(S >> dep) & 1], S, dep - 1);
}
struct Qry {
int d, id;
} q[MAXN];
const int cmp (const Qry t1, const Qry t2) {
return t1.d < t2.d;
}
int top;
LL *stp[MAXN * 30], sta[MAXN * 30];
LL sz[MAXN], fa[MAXN];
LL Ans = 0;
LL calc (int x) {
return (LL) sz[x] * (sz[x] - 1) / 2;
}
int get (int x) { return x == fa[x] ? x : get (fa[x]); }
int chg (LL &u, LL val) {
stp[++top] = &u, sta[top] = u;
u = val;
}
void merge (int x, int y) {
//cout << 'a';
int X = x, Y = y;
//cout << x << " " << y << endl;
x = get (x), y = get (y);
if (x == y) return ;
else {
//cout << Ans << " " << calc (x) << " " << calc (y) << endl;
chg (Ans, Ans - calc (x) - calc (y));
if (sz[x] < sz[y]) swap (x, y);
chg (fa[y], x), chg (sz[x], sz[x] + sz[y]);
//cout << X << " " << sz[x] << " " << calc (x) << " " << Ans << endl;
chg (Ans, Ans + calc (x));
//cout << Ans << endl;
}
}
void bck() {
*stp[top] = sta[top], --top;
}
void psh (int x) {
//cout << 'a';
if (!x) return ;
for (int i = 0; i < vec[x].size(); ++i)
merge (lka[vec[x][i]], lkb[vec[x][i]]);
if (son[x][0]) psh (son[x][0]);
if (son[x][1]) psh (son[x][1]);
}
int ans[MAXN];
void dfs (int x, int l, int r, int dep = 29) {
//cout << 'a';
if (l > r) return ;
if (!x || dep == -1) {
//cout << 'a';
//cout << dep << endl;
//cout << " " << l << " " << r << endl;
for (int i = l; i <= r; ++i)
ans[q[i].id] = Ans;
return ;
}
int pos = l - 1;
while (pos < r && ((q[pos + 1].d >> dep) & 1) == 0)
++pos;
int rec = top;
if ((K >> dep) & 1) {
//cout << 'a';
//if (son[x][0] == 34) cout << 'a';
psh (son[x][1]), dfs (son[x][0], l, pos, dep - 1);
while (top != rec) bck();
psh (son[x][0]), dfs (son[x][1], pos + 1, r, dep - 1);
while (top != rec) bck();
}
else {
dfs (son[x][0], l, pos, dep - 1);
dfs (son[x][1], pos + 1, r, dep - 1);
}
}
int main() {
int i,j,k;
int x, y, z;
scanf ("%d%d%d", &n, &m, &K);
for (i = 1; i <= m; ++i) {
scanf ("%d%d%d", &lka[i], &lkb[i], &c[i]), c[i] ^= K;
ID = i, ins (Rt, c[i]);
}
scanf ("%d", &Q);
for (i = 1; i <= Q; ++i)
scanf ("%d", &q[i].d), q[i].id = i;
sort (q + 1, q + Q + 1, cmp);
for (i = 1; i <= n; ++i) fa[i] = i, sz[i] = 1;
dfs (Rt, 1, Q);
for (i = 1; i <= Q; ++i)
printf ("%d\n", ans[i]);
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3876kb
input:
4 5 5 1 2 17 1 3 4 2 3 20 2 4 3 3 4 5 4 0 7 16 167
output:
0 0 0 0
result:
wrong answer 1st numbers differ - expected: '2', found: '0'