Submission #173260

# Submission time Handle Problem Language Result Execution time Memory
173260 2020-01-03T16:55:44 Z LinusTorvaldsFan Birthday gift (IZhO18_treearray) C++14
30 / 100
4000 ms 9464 KB
#include <bits/stdc++.h>

using namespace std;


const int maxn=2e5+19;
vector<int>T[maxn];

vector<pair<int,int>>euler_path;
int min_tin[maxn];
int h[maxn];

void gfs(int v, int p){
	min_tin[v]=euler_path.size();
	euler_path.push_back({h[v],v});
	for(auto u:T[v]){
		if(u==p)continue;
		h[u]=h[v]+1;
		gfs(u,v);
		euler_path.push_back({h[v],v});
	}
}

const int Q=1<<18;
pair<int,int>tree[2*Q];

const int inf=1e9;

void update(int p, pair<int,int>x) {
	p+=Q;
	tree[p]=x;
	p/=2;
	while(p>0){
		tree[p]=min(tree[p*2],tree[2*p+1]);
		p/=2;
	}
}

pair<int,int> get(int l, int r) {
	pair<int,int> ans={inf,inf};
	for(l+=Q,r+=Q;l<r;l>>=1,r>>=1){
		if(l&1)ans=min(ans,tree[l++]);
		if(r&1)ans=min(ans,tree[--r]);
	}
	return ans;
}

int lca(int x, int y) {
	if(min_tin[x]>min_tin[y]){
		swap(x,y);
	}
	pair<int,int> ans=get(min_tin[x],min_tin[y]+1);
	return ans.second;
}

int main() {
	fill(tree,tree+2*Q,make_pair(inf,inf));
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	int m;
	cin>>m;
	int q;
	cin>>q;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		T[a].push_back(b);
		T[b].push_back(a);	
	}
	gfs(1,-1);
	for(int i=0;i<euler_path.size();i++){
		update(i,euler_path[i]);
	}
	vector<int>a(m);
	for(int i=0;i<m;i++){
		cin>>a[i];
	}
	for(;q;q--){
		int t;
		cin>>t;
		if(t==1) {
			int pos,v;
			cin>>pos>>v;
			pos--;
			a[pos]=v;
		}
		if(t==2) {
			int l,r,v;
			cin>>l>>r>>v;
			l--;r--;
			int ansL=-1;
			int ansR=-1;
			for(int i=l;i<=r;i++){
				int cur_lca=a[i];
				for(int j=i;j<=r;j++){
					cur_lca=lca(cur_lca,a[j]);
					if(cur_lca==v){
						ansL=i+1;
						ansR=j+1;
						break;
					}
				}
			}
			cout<<ansL<<" "<<ansR<<"\n";
		}
	}
	return 0;
}

Compilation message

treearray.cpp: In function 'int main()':
treearray.cpp:73:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<euler_path.size();i++){
              ~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 9080 KB n=5
2 Correct 11 ms 9080 KB n=100
3 Correct 11 ms 9080 KB n=100
4 Correct 11 ms 9080 KB n=100
5 Correct 11 ms 9080 KB n=100
6 Correct 23 ms 9080 KB n=100
7 Correct 23 ms 9080 KB n=100
8 Correct 11 ms 9080 KB n=100
9 Correct 11 ms 9080 KB n=100
10 Correct 17 ms 9212 KB n=100
11 Correct 17 ms 9080 KB n=100
12 Correct 10 ms 9208 KB n=100
13 Correct 11 ms 9208 KB n=100
14 Correct 10 ms 9208 KB n=100
15 Correct 10 ms 9212 KB n=100
16 Correct 10 ms 9080 KB n=100
17 Correct 13 ms 9232 KB n=100
18 Correct 11 ms 9080 KB n=100
19 Correct 10 ms 9208 KB n=100
20 Correct 11 ms 9080 KB n=100
21 Correct 12 ms 9080 KB n=100
22 Correct 10 ms 9180 KB n=100
23 Correct 12 ms 9208 KB n=100
24 Correct 12 ms 9080 KB n=100
25 Correct 12 ms 9084 KB n=100
26 Correct 10 ms 9080 KB n=12
27 Correct 16 ms 9080 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 9 ms 9080 KB n=5
2 Correct 11 ms 9080 KB n=100
3 Correct 11 ms 9080 KB n=100
4 Correct 11 ms 9080 KB n=100
5 Correct 11 ms 9080 KB n=100
6 Correct 23 ms 9080 KB n=100
7 Correct 23 ms 9080 KB n=100
8 Correct 11 ms 9080 KB n=100
9 Correct 11 ms 9080 KB n=100
10 Correct 17 ms 9212 KB n=100
11 Correct 17 ms 9080 KB n=100
12 Correct 10 ms 9208 KB n=100
13 Correct 11 ms 9208 KB n=100
14 Correct 10 ms 9208 KB n=100
15 Correct 10 ms 9212 KB n=100
16 Correct 10 ms 9080 KB n=100
17 Correct 13 ms 9232 KB n=100
18 Correct 11 ms 9080 KB n=100
19 Correct 10 ms 9208 KB n=100
20 Correct 11 ms 9080 KB n=100
21 Correct 12 ms 9080 KB n=100
22 Correct 10 ms 9180 KB n=100
23 Correct 12 ms 9208 KB n=100
24 Correct 12 ms 9080 KB n=100
25 Correct 12 ms 9084 KB n=100
26 Correct 10 ms 9080 KB n=12
27 Correct 16 ms 9080 KB n=100
28 Correct 18 ms 9208 KB n=500
29 Correct 315 ms 9248 KB n=500
30 Correct 259 ms 9340 KB n=500
31 Correct 270 ms 9236 KB n=500
32 Correct 27 ms 9336 KB n=500
33 Correct 287 ms 9208 KB n=500
34 Correct 15 ms 9208 KB n=500
35 Correct 281 ms 9208 KB n=500
36 Correct 2989 ms 9224 KB n=500
37 Correct 3033 ms 9212 KB n=500
38 Correct 3001 ms 9272 KB n=500
39 Correct 207 ms 9208 KB n=500
40 Correct 200 ms 9208 KB n=500
41 Correct 192 ms 9112 KB n=500
42 Correct 1460 ms 9208 KB n=500
43 Correct 1469 ms 9336 KB n=500
44 Correct 1443 ms 9208 KB n=500
45 Correct 27 ms 9208 KB n=500
46 Correct 312 ms 9208 KB n=500
47 Correct 249 ms 9208 KB n=500
48 Correct 15 ms 9208 KB n=500
49 Correct 239 ms 9208 KB n=500
50 Correct 268 ms 9208 KB n=500
51 Correct 299 ms 9208 KB n=500
52 Correct 351 ms 9268 KB n=500
53 Correct 318 ms 9208 KB n=500
54 Correct 501 ms 9208 KB n=500
55 Correct 84 ms 9336 KB n=278
56 Correct 1094 ms 9264 KB n=500
57 Correct 1083 ms 9300 KB n=500
58 Correct 898 ms 9336 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 9 ms 9080 KB n=5
2 Correct 11 ms 9080 KB n=100
3 Correct 11 ms 9080 KB n=100
4 Correct 11 ms 9080 KB n=100
5 Correct 11 ms 9080 KB n=100
6 Correct 23 ms 9080 KB n=100
7 Correct 23 ms 9080 KB n=100
8 Correct 11 ms 9080 KB n=100
9 Correct 11 ms 9080 KB n=100
10 Correct 17 ms 9212 KB n=100
11 Correct 17 ms 9080 KB n=100
12 Correct 10 ms 9208 KB n=100
13 Correct 11 ms 9208 KB n=100
14 Correct 10 ms 9208 KB n=100
15 Correct 10 ms 9212 KB n=100
16 Correct 10 ms 9080 KB n=100
17 Correct 13 ms 9232 KB n=100
18 Correct 11 ms 9080 KB n=100
19 Correct 10 ms 9208 KB n=100
20 Correct 11 ms 9080 KB n=100
21 Correct 12 ms 9080 KB n=100
22 Correct 10 ms 9180 KB n=100
23 Correct 12 ms 9208 KB n=100
24 Correct 12 ms 9080 KB n=100
25 Correct 12 ms 9084 KB n=100
26 Correct 10 ms 9080 KB n=12
27 Correct 16 ms 9080 KB n=100
28 Correct 18 ms 9208 KB n=500
29 Correct 315 ms 9248 KB n=500
30 Correct 259 ms 9340 KB n=500
31 Correct 270 ms 9236 KB n=500
32 Correct 27 ms 9336 KB n=500
33 Correct 287 ms 9208 KB n=500
34 Correct 15 ms 9208 KB n=500
35 Correct 281 ms 9208 KB n=500
36 Correct 2989 ms 9224 KB n=500
37 Correct 3033 ms 9212 KB n=500
38 Correct 3001 ms 9272 KB n=500
39 Correct 207 ms 9208 KB n=500
40 Correct 200 ms 9208 KB n=500
41 Correct 192 ms 9112 KB n=500
42 Correct 1460 ms 9208 KB n=500
43 Correct 1469 ms 9336 KB n=500
44 Correct 1443 ms 9208 KB n=500
45 Correct 27 ms 9208 KB n=500
46 Correct 312 ms 9208 KB n=500
47 Correct 249 ms 9208 KB n=500
48 Correct 15 ms 9208 KB n=500
49 Correct 239 ms 9208 KB n=500
50 Correct 268 ms 9208 KB n=500
51 Correct 299 ms 9208 KB n=500
52 Correct 351 ms 9268 KB n=500
53 Correct 318 ms 9208 KB n=500
54 Correct 501 ms 9208 KB n=500
55 Correct 84 ms 9336 KB n=278
56 Correct 1094 ms 9264 KB n=500
57 Correct 1083 ms 9300 KB n=500
58 Correct 898 ms 9336 KB n=500
59 Correct 1168 ms 9400 KB n=2000
60 Execution timed out 4098 ms 9464 KB Time limit exceeded
61 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 9080 KB n=5
2 Correct 11 ms 9080 KB n=100
3 Correct 11 ms 9080 KB n=100
4 Correct 11 ms 9080 KB n=100
5 Correct 11 ms 9080 KB n=100
6 Correct 23 ms 9080 KB n=100
7 Correct 23 ms 9080 KB n=100
8 Correct 11 ms 9080 KB n=100
9 Correct 11 ms 9080 KB n=100
10 Correct 17 ms 9212 KB n=100
11 Correct 17 ms 9080 KB n=100
12 Correct 10 ms 9208 KB n=100
13 Correct 11 ms 9208 KB n=100
14 Correct 10 ms 9208 KB n=100
15 Correct 10 ms 9212 KB n=100
16 Correct 10 ms 9080 KB n=100
17 Correct 13 ms 9232 KB n=100
18 Correct 11 ms 9080 KB n=100
19 Correct 10 ms 9208 KB n=100
20 Correct 11 ms 9080 KB n=100
21 Correct 12 ms 9080 KB n=100
22 Correct 10 ms 9180 KB n=100
23 Correct 12 ms 9208 KB n=100
24 Correct 12 ms 9080 KB n=100
25 Correct 12 ms 9084 KB n=100
26 Correct 10 ms 9080 KB n=12
27 Correct 16 ms 9080 KB n=100
28 Correct 18 ms 9208 KB n=500
29 Correct 315 ms 9248 KB n=500
30 Correct 259 ms 9340 KB n=500
31 Correct 270 ms 9236 KB n=500
32 Correct 27 ms 9336 KB n=500
33 Correct 287 ms 9208 KB n=500
34 Correct 15 ms 9208 KB n=500
35 Correct 281 ms 9208 KB n=500
36 Correct 2989 ms 9224 KB n=500
37 Correct 3033 ms 9212 KB n=500
38 Correct 3001 ms 9272 KB n=500
39 Correct 207 ms 9208 KB n=500
40 Correct 200 ms 9208 KB n=500
41 Correct 192 ms 9112 KB n=500
42 Correct 1460 ms 9208 KB n=500
43 Correct 1469 ms 9336 KB n=500
44 Correct 1443 ms 9208 KB n=500
45 Correct 27 ms 9208 KB n=500
46 Correct 312 ms 9208 KB n=500
47 Correct 249 ms 9208 KB n=500
48 Correct 15 ms 9208 KB n=500
49 Correct 239 ms 9208 KB n=500
50 Correct 268 ms 9208 KB n=500
51 Correct 299 ms 9208 KB n=500
52 Correct 351 ms 9268 KB n=500
53 Correct 318 ms 9208 KB n=500
54 Correct 501 ms 9208 KB n=500
55 Correct 84 ms 9336 KB n=278
56 Correct 1094 ms 9264 KB n=500
57 Correct 1083 ms 9300 KB n=500
58 Correct 898 ms 9336 KB n=500
59 Correct 1168 ms 9400 KB n=2000
60 Execution timed out 4098 ms 9464 KB Time limit exceeded
61 Halted 0 ms 0 KB -