QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#71758 | #3279. 经典游戏 | He_Ren | 0 | 200ms | 198344kb | C++14 | 3.6kb | 2023-01-12 00:57:22 | 2023-01-12 00:57:25 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 1e6 + 5;
#define bbit(i) (1<<(i))
#define bdig(x,i) (((x)>>(i))&1)
namespace Trie
{
const int lb = 20;
const int MAXP = MAXN * lb;
int son[MAXP][2], siz[MAXP], pool;
void init(void)
{
for(int i=1; i+1<MAXP; ++i) son[i][0] = i+1;
pool = 1;
}
int new_Node(void)
{
int u = pool; pool = son[pool][0];
son[u][0] = son[u][1] = siz[u] = 0;
return u;
}
void del_Node(int &u)
{
son[u][0] = pool;
pool = u; u = 0;
}
void update(int &u,int dep,int x,int k)
{
if(!u) u = new_Node();
if(dep == -1) siz[u] += k;
else update(son[u][bdig(x,dep)], dep-1, x, k);
if(!siz[u]) del_Node(u);
}
void update(int &rt,int x,int k)
{
update(rt, lb-1, x, k);
}
int query(int u,int dep,int x,int k)
{
if(!siz[u] || dep == -1) return 0;
if(bdig(x,dep))
return query(son[u][bdig(k,dep)^1], dep-1, x, k);
else
{
int kk = bdig(k,dep);
return siz[son[u][kk^1]] + query(son[u][kk], dep-1, x, k);
}
}
int query(int rt,int x,int k)
{
return query(rt, lb-1, x, k);
}
}
struct BIT
{
int tree[MAXN], n;
#define lowbit(x) ((x)&-(x))
inline void update(int x,int k)
{
while(x<=n) tree[x] ^= k, x += lowbit(x);
}
inline void update(int l,int r,int k)
{
update(l,k); update(r+1,k);
}
inline int query(int x)
{
int res=0;
while(x) res ^= tree[x], x ^= lowbit(x);
return res;
}
}tree;
int n;
vector<int> g[MAXN];
int anc[MAXN], siz[MAXN], sub[MAXN], dfn[MAXN], curdfn = 0;
void dfs_tree(int u,int fa)
{
anc[u] = fa;
siz[u] = 1; sub[u] = 0;
dfn[u] = ++curdfn;
for(int v: g[u]) if(v != fa)
{
dfs_tree(v,u);
siz[u] += siz[v];
sub[u] = max(sub[u], sub[v] + 1);
}
}
void dfs_dep(int u,int fa,int dep[])
{
for(int v: g[u]) if(v != fa)
dep[v] = dep[u] + 1, dfs_dep(v,u,dep);
}
inline int getfar(int rt)
{
static int dep[MAXN];
dep[rt] = 0; dfs_dep(rt,0,dep);
return max_element(dep+1,dep+n+1) - dep;
}
int main(void)
{
int testid,Q;
scanf("%d%d%d",&testid,&n,&Q);
for(int i=1; i<n; ++i)
{
int u,v;
scanf("%d%d",&u,&v);
g[u].push_back(v); g[v].push_back(u);
}
if(n == 1)
{
while(Q--) printf("0\n");
return 0;
}
int ep1 = getfar(1), ep2 = getfar(ep1);
static int dep[2][MAXN];
dfs_dep(ep1, 0, dep[0]);
dfs_dep(ep2, 0, dep[1]);
static int type[MAXN], h[MAXN];
for(int i=1; i<=n; ++i)
{
type[i] = dep[0][i] >= dep[1][i]? 0: 1;
h[i] = max(dep[0][i], dep[1][i]);
}
int rt1 = -1, rt2 = -1;
for(int u=1; u<=n; ++u) for(int v: g[u])
if(type[u] == 0 && type[v] == 1)
rt1 = u, rt2 = v;
assert(rt1 != -1);
dfs_tree(rt1, rt2);
dfs_tree(rt2, rt1);
tree.n = n;
Trie::init();
using Trie::update;
using Trie::query;
static int rt[MAXN];
for(int i=1; i<=n; ++i) if(i != rt1 && i != rt2)
update(rt[anc[i]], 0, 1);
static int val[MAXN];
auto oper = [&] (int u,int k)
{
bool flag = u != rt1 && u != rt2;
if(flag) update(rt[anc[u]], val[u], -1);
val[u] ^= k;
if(flag) update(rt[anc[u]], val[u], 1);
tree.update(dfn[u], dfn[u]+siz[u]-1, k);
};
auto checkone = [&] (int u) -> int
{
return tree.query(dfn[u]) > h[u];
};
auto xor_one = [&] (int u)
{
oper(rt1, sub[u]); oper(rt2, sub[u]);
oper(u, sub[u] ^ h[u]);
};
for(int i=1; i<=n; ++i)
{
int x;
scanf("%d",&x);
if(x&1) xor_one(i);
}
while(Q--)
{
int x,u;
scanf("%d%d",&x,&u);
xor_one(x);
int ans = checkone(u) + checkone(anc[u])
+ query(rt[u], h[u]+1, tree.query(dfn[u]));
printf("%d\n",ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 16
Accepted
time: 23ms
memory: 183688kb
input:
16 5 5 4 3 3 2 3 5 3 1 0 1 1 0 1 5 2 5 5 4 2 2 1 3 2
output:
1 1 1 0 0
result:
ok 5 number(s): "1 1 1 0 0"
Test #2:
score: -16
Wrong Answer
time: 27ms
memory: 184836kb
input:
16 5 5 2 4 4 3 3 5 2 1 0 1 1 0 1 3 2 3 5 1 2 4 1 5 3
output:
0 1 0 0 0
result:
wrong answer 3rd numbers differ - expected: '1', found: '0'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #9:
score: 0
Wrong Answer
time: 186ms
memory: 198344kb
input:
13 100000 100000 91699 52443 52443 41748 41748 32330 32330 42277 42277 80707 80707 97074 97074 84439 84439 73656 73656 94232 94232 19271 19271 64725 64725 68032 68032 15074 15074 98785 98785 84234 84234 63617 63617 85713 85713 32965 32965 90099 90099 95398 95398 84273 84273 90891 90891 89305 89305 9...
output:
2 2 0 0 0 1 0 0 0 2 0 1 0 1 1 1 0 2 1 0 0 2 0 0 0 2 1 0 0 0 1 0 1 0 2 0 1 1 0 0 1 1 0 0 0 2 0 1 0 1 1 2 0 1 0 1 1 0 0 0 0 0 2 1 1 0 0 1 0 2 2 0 0 0 0 2 2 1 0 1 1 0 2 1 0 1 2 1 1 0 0 2 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 1 1 1 1 1 1 1 1 2 0 1 0 0 0 0 0 0 0 1 2 2 0 2 1 0 2 1 0 0 1 0 1 1 2 1 1 0 ...
result:
wrong answer 6th numbers differ - expected: '2', found: '1'
Subtask #5:
score: 0
Wrong Answer
Test #13:
score: 0
Wrong Answer
time: 161ms
memory: 192876kb
input:
12 100000 100000 93214 84598 93214 56491 93214 84251 93214 79335 93214 71720 93214 77307 93214 95507 93214 95410 93214 40328 93214 86071 93214 45088 93214 66766 93214 79723 93214 88378 93214 89470 93214 88357 93214 88637 93214 30576 93214 90846 93214 53961 93214 41155 93214 46341 93214 83568 93214 9...
output:
1 0 0 0 1 1 0 1 0 1 1 0 0 1 1 1 0 1 1 1 1 1 0 1 1 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 0 0 1 1 0 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 0 1 1 0 1 1 1 1 0 1 0 0 0 1 1 1 1 0 0 1 0 0 1 1 1 1 1 0 1 1 1 0 1 0 1 1 0 1 1 1 0 1 1 1 1 1 1 1 1 1 0 0 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1 1 0 1 0 ...
result:
wrong answer 1st numbers differ - expected: '50089', found: '1'
Subtask #6:
score: 0
Wrong Answer
Test #17:
score: 0
Wrong Answer
time: 200ms
memory: 194080kb
input:
11 100000 100000 2 29108 3 77506 4 7190 5 41884 7 9630 14 78381 15 10036 16 13569 19 80204 20 17573 24 86568 26 88304 28 91742 31 50889 32 29659 33 7909 37 61160 38 88144 40 36396 41 8142 43 20787 46 75458 48 23406 50 56495 61 74778 63 97662 70 75429 73 52031 76 49902 77 56882 81 13357 85 70152 89 3...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 245th numbers differ - expected: '6', found: '1'
Subtask #7:
score: 0
Skipped
Dependency #1:
0%
Subtask #8:
score: 0
Skipped
Dependency #1:
0%