Submission #209259

# Submission time Handle Problem Language Result Execution time Memory
209259 2020-03-13T14:09:33 Z dennisstar Synchronization (JOI13_synchronization) C++17
100 / 100
741 ms 32376 KB
#include <bits/stdc++.h>
#define eb emplace_back
using namespace std;
typedef vector<int> vim;

const int MX = 100005;

int N, M, Q, c, X[MX], Y[MX], Z[MX], lst[MX];
int in[MX], out[MX], chk[MX];
vim adj[MX], spt[MX];

int F[MX];
void upd(int t, int v) { while (t<=N) F[t]+=v, t+=t&-t; }
int get(int t) { int r=0; while (t) r+=F[t], t-=t&-t; return r; }

void dfs(int n, int p) {
	spt[n].eb(p); in[n]=++c;
	for (int i=0; i<spt[spt[n][i]].size(); i++) spt[n].eb(spt[spt[n][i]][i]);
	for (auto &i:adj[n]) if (i!=p) dfs(i, n);
	out[n]=c+1;
}

int gp(int t) {
	int x=get(in[t]);
	for (int i=20; i>=0; i--) if (i<spt[t].size()&&x==get(in[spt[t][i]])) t=spt[t][i];
	return t;
}

int main() {
	cin>>N>>M>>Q;
	for (int i=1; i<N; i++) cin>>X[i]>>Y[i], adj[X[i]].eb(Y[i]), adj[Y[i]].eb(X[i]);
	dfs(1, 0);
	for (int i=1; i<N; i++) if (spt[X[i]][0]==Y[i]) swap(X[i], Y[i]);
	for (int i=1; i<=N; i++) Z[i]=1, upd(in[i], 1), upd(out[i], -1);
	while (M--) {
		int d, p; cin>>d; p=gp(X[d]);
		if (chk[d]==0) {
			upd(in[Y[d]], -1); upd(out[Y[d]], 1);
			Z[p]+=Z[Y[d]]-lst[d];
		}
		if (chk[d]==1) {
			upd(in[Y[d]], 1); upd(out[Y[d]], -1);
			Z[Y[d]]=lst[d]=Z[p];
		}
		chk[d]=1-chk[d];
	}
	for (int i=1; i<=N; i++) Z[i]=Z[gp(i)];
	while (Q--) cin>>c, cout<<Z[c]<<'\n';
	return 0;
}

Compilation message

synchronization.cpp: In function 'void dfs(int, int)':
synchronization.cpp:18:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0; i<spt[spt[n][i]].size(); i++) spt[n].eb(spt[spt[n][i]][i]);
                ~^~~~~~~~~~~~~~~~~~~~~~
synchronization.cpp: In function 'int gp(int)':
synchronization.cpp:25:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=20; i>=0; i--) if (i<spt[t].size()&&x==get(in[spt[t][i]])) t=spt[t][i];
                                ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4984 KB Output is correct
2 Correct 7 ms 4984 KB Output is correct
3 Correct 7 ms 4984 KB Output is correct
4 Correct 8 ms 4984 KB Output is correct
5 Correct 8 ms 5112 KB Output is correct
6 Correct 10 ms 5240 KB Output is correct
7 Correct 34 ms 6392 KB Output is correct
8 Correct 32 ms 6264 KB Output is correct
9 Correct 35 ms 6264 KB Output is correct
10 Correct 419 ms 18100 KB Output is correct
11 Correct 406 ms 18168 KB Output is correct
12 Correct 486 ms 31484 KB Output is correct
13 Correct 212 ms 16764 KB Output is correct
14 Correct 290 ms 17400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 248 ms 21752 KB Output is correct
2 Correct 251 ms 23744 KB Output is correct
3 Correct 286 ms 30460 KB Output is correct
4 Correct 284 ms 30444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5116 KB Output is correct
2 Correct 8 ms 5112 KB Output is correct
3 Correct 8 ms 5112 KB Output is correct
4 Correct 8 ms 4984 KB Output is correct
5 Correct 8 ms 5112 KB Output is correct
6 Correct 14 ms 5240 KB Output is correct
7 Correct 62 ms 7544 KB Output is correct
8 Correct 741 ms 32376 KB Output is correct
9 Correct 728 ms 32376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 730 ms 29304 KB Output is correct
2 Correct 532 ms 31480 KB Output is correct
3 Correct 538 ms 31740 KB Output is correct
4 Correct 517 ms 31736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4984 KB Output is correct
2 Correct 7 ms 4984 KB Output is correct
3 Correct 8 ms 5112 KB Output is correct
4 Correct 8 ms 4984 KB Output is correct
5 Correct 12 ms 5112 KB Output is correct
6 Correct 59 ms 6392 KB Output is correct
7 Correct 717 ms 19064 KB Output is correct
8 Correct 725 ms 32248 KB Output is correct
9 Correct 455 ms 17904 KB Output is correct
10 Correct 516 ms 18424 KB Output is correct
11 Correct 507 ms 25080 KB Output is correct
12 Correct 500 ms 24952 KB Output is correct
13 Correct 515 ms 31696 KB Output is correct