Submission #334901

# Submission time Handle Problem Language Result Execution time Memory
334901 2020-12-10T07:21:28 Z amunduzbaev Birthday gift (IZhO18_treearray) C++14
30 / 100
3111 ms 620 KB
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ll long long 
#define ld long double 
#define pii pair<int, int>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define prc(n) fixed << setprecision(n)
#define fastios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi acos(-1);
const int inf = 1e9+7;
const int N = 505;

int n, m, q, a[N], tin[N], tout[N], l;
vector<int>edges[N];
vector<int>order;
vector<pii>tree;
int t;
int up[N][32];
void dfs(int u, int p){
	tin[u] = ++t;
	up[u][0] = p;
	for(int i=1; i<=l; i++){
		up[u][i] = up[up[u][i-1]][i-1];
	}
	for(auto x:edges[u]){
		if(x == p) continue;
		dfs(x, u);
	}
	tout[u] = ++t;
}

bool upper(int a, int b){
	return tin[a] <= tin[b] && tout[a] >= tout[b];
}

int lca(int a, int b){
	if(upper(a, b)) return a;
	if(upper(b, a)) return b;
	for(int i=l; i>=0; i--){
		if(!upper(up[a][i], b)) a = up[a][i];
	}
	return up[a][0];
}

void solve(){
	cin>>n>>m>>q;
	for(int i=1;i<n;i++){
		int a, b;
		cin>>a>>b;
		edges[a].pb(b);
		edges[b].pb(a);
	}
	l = 1;
	while((1<<l) <= n) l++; 
	dfs(1, 1);
	for(int i=1;i<=m;i++) cin>>a[i];
	while(q--){
		int t;
		cin>>t;
		if(t == 1){
			int pos, val;
			cin>>pos>>val;
			a[pos] = val;
		}
		else{
			int l, r, val, rr;
			cin>>l>>r>>val;
			int la = -1, ra = -1;
			for(;l<= r; l++){
				int prev = -1;
				for(rr = l; rr <= r; rr++){
					int lx = a[l], rx = a[rr];
					int res = lca(lx, rx);
					if(prev != -1) res = lca(prev, res);
					//cout<<res<<" ";
					if(res == val){
						if(ra == -1 || ra - la +1 < rr - l +1) ra = rr, la = l;
					}
					prev = res;
				}
			}
			cout<<la<<" "<<ra<<"\n";
		}
	}
	
	return;
}

int main(){
	fastios
	int t = 1;
	//cin>>t;
	while(t--) solve();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=5
2 Correct 4 ms 364 KB n=100
3 Correct 4 ms 364 KB n=100
4 Correct 4 ms 364 KB n=100
5 Correct 4 ms 364 KB n=100
6 Correct 20 ms 364 KB n=100
7 Correct 19 ms 364 KB n=100
8 Correct 3 ms 364 KB n=100
9 Correct 3 ms 364 KB n=100
10 Correct 13 ms 492 KB n=100
11 Correct 11 ms 364 KB n=100
12 Correct 3 ms 364 KB n=100
13 Correct 3 ms 364 KB n=100
14 Correct 3 ms 364 KB n=100
15 Correct 2 ms 364 KB n=100
16 Correct 4 ms 364 KB n=100
17 Correct 2 ms 364 KB n=100
18 Correct 1 ms 364 KB n=100
19 Correct 3 ms 364 KB n=100
20 Correct 1 ms 364 KB n=100
21 Correct 2 ms 364 KB n=100
22 Correct 3 ms 364 KB n=100
23 Correct 2 ms 364 KB n=100
24 Correct 2 ms 364 KB n=100
25 Correct 2 ms 364 KB n=100
26 Correct 1 ms 364 KB n=12
27 Correct 7 ms 384 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=5
2 Correct 4 ms 364 KB n=100
3 Correct 4 ms 364 KB n=100
4 Correct 4 ms 364 KB n=100
5 Correct 4 ms 364 KB n=100
6 Correct 20 ms 364 KB n=100
7 Correct 19 ms 364 KB n=100
8 Correct 3 ms 364 KB n=100
9 Correct 3 ms 364 KB n=100
10 Correct 13 ms 492 KB n=100
11 Correct 11 ms 364 KB n=100
12 Correct 3 ms 364 KB n=100
13 Correct 3 ms 364 KB n=100
14 Correct 3 ms 364 KB n=100
15 Correct 2 ms 364 KB n=100
16 Correct 4 ms 364 KB n=100
17 Correct 2 ms 364 KB n=100
18 Correct 1 ms 364 KB n=100
19 Correct 3 ms 364 KB n=100
20 Correct 1 ms 364 KB n=100
21 Correct 2 ms 364 KB n=100
22 Correct 3 ms 364 KB n=100
23 Correct 2 ms 364 KB n=100
24 Correct 2 ms 364 KB n=100
25 Correct 2 ms 364 KB n=100
26 Correct 1 ms 364 KB n=12
27 Correct 7 ms 384 KB n=100
28 Correct 388 ms 492 KB n=500
29 Correct 82 ms 620 KB n=500
30 Correct 191 ms 492 KB n=500
31 Correct 158 ms 620 KB n=500
32 Correct 440 ms 492 KB n=500
33 Correct 261 ms 492 KB n=500
34 Correct 435 ms 620 KB n=500
35 Correct 78 ms 620 KB n=500
36 Correct 3111 ms 492 KB n=500
37 Correct 3108 ms 492 KB n=500
38 Correct 3075 ms 496 KB n=500
39 Correct 273 ms 492 KB n=500
40 Correct 263 ms 620 KB n=500
41 Correct 252 ms 492 KB n=500
42 Correct 1568 ms 492 KB n=500
43 Correct 1557 ms 492 KB n=500
44 Correct 1519 ms 492 KB n=500
45 Correct 322 ms 620 KB n=500
46 Correct 75 ms 492 KB n=500
47 Correct 99 ms 492 KB n=500
48 Correct 287 ms 620 KB n=500
49 Correct 70 ms 492 KB n=500
50 Correct 325 ms 620 KB n=500
51 Correct 229 ms 492 KB n=500
52 Correct 86 ms 492 KB n=500
53 Correct 283 ms 492 KB n=500
54 Correct 259 ms 620 KB n=500
55 Correct 73 ms 364 KB n=278
56 Correct 254 ms 512 KB n=500
57 Correct 255 ms 620 KB n=500
58 Correct 1129 ms 620 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=5
2 Correct 4 ms 364 KB n=100
3 Correct 4 ms 364 KB n=100
4 Correct 4 ms 364 KB n=100
5 Correct 4 ms 364 KB n=100
6 Correct 20 ms 364 KB n=100
7 Correct 19 ms 364 KB n=100
8 Correct 3 ms 364 KB n=100
9 Correct 3 ms 364 KB n=100
10 Correct 13 ms 492 KB n=100
11 Correct 11 ms 364 KB n=100
12 Correct 3 ms 364 KB n=100
13 Correct 3 ms 364 KB n=100
14 Correct 3 ms 364 KB n=100
15 Correct 2 ms 364 KB n=100
16 Correct 4 ms 364 KB n=100
17 Correct 2 ms 364 KB n=100
18 Correct 1 ms 364 KB n=100
19 Correct 3 ms 364 KB n=100
20 Correct 1 ms 364 KB n=100
21 Correct 2 ms 364 KB n=100
22 Correct 3 ms 364 KB n=100
23 Correct 2 ms 364 KB n=100
24 Correct 2 ms 364 KB n=100
25 Correct 2 ms 364 KB n=100
26 Correct 1 ms 364 KB n=12
27 Correct 7 ms 384 KB n=100
28 Correct 388 ms 492 KB n=500
29 Correct 82 ms 620 KB n=500
30 Correct 191 ms 492 KB n=500
31 Correct 158 ms 620 KB n=500
32 Correct 440 ms 492 KB n=500
33 Correct 261 ms 492 KB n=500
34 Correct 435 ms 620 KB n=500
35 Correct 78 ms 620 KB n=500
36 Correct 3111 ms 492 KB n=500
37 Correct 3108 ms 492 KB n=500
38 Correct 3075 ms 496 KB n=500
39 Correct 273 ms 492 KB n=500
40 Correct 263 ms 620 KB n=500
41 Correct 252 ms 492 KB n=500
42 Correct 1568 ms 492 KB n=500
43 Correct 1557 ms 492 KB n=500
44 Correct 1519 ms 492 KB n=500
45 Correct 322 ms 620 KB n=500
46 Correct 75 ms 492 KB n=500
47 Correct 99 ms 492 KB n=500
48 Correct 287 ms 620 KB n=500
49 Correct 70 ms 492 KB n=500
50 Correct 325 ms 620 KB n=500
51 Correct 229 ms 492 KB n=500
52 Correct 86 ms 492 KB n=500
53 Correct 283 ms 492 KB n=500
54 Correct 259 ms 620 KB n=500
55 Correct 73 ms 364 KB n=278
56 Correct 254 ms 512 KB n=500
57 Correct 255 ms 620 KB n=500
58 Correct 1129 ms 620 KB n=500
59 Runtime error 1 ms 524 KB Execution killed with signal 11 (could be triggered by violating memory limits)
60 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=5
2 Correct 4 ms 364 KB n=100
3 Correct 4 ms 364 KB n=100
4 Correct 4 ms 364 KB n=100
5 Correct 4 ms 364 KB n=100
6 Correct 20 ms 364 KB n=100
7 Correct 19 ms 364 KB n=100
8 Correct 3 ms 364 KB n=100
9 Correct 3 ms 364 KB n=100
10 Correct 13 ms 492 KB n=100
11 Correct 11 ms 364 KB n=100
12 Correct 3 ms 364 KB n=100
13 Correct 3 ms 364 KB n=100
14 Correct 3 ms 364 KB n=100
15 Correct 2 ms 364 KB n=100
16 Correct 4 ms 364 KB n=100
17 Correct 2 ms 364 KB n=100
18 Correct 1 ms 364 KB n=100
19 Correct 3 ms 364 KB n=100
20 Correct 1 ms 364 KB n=100
21 Correct 2 ms 364 KB n=100
22 Correct 3 ms 364 KB n=100
23 Correct 2 ms 364 KB n=100
24 Correct 2 ms 364 KB n=100
25 Correct 2 ms 364 KB n=100
26 Correct 1 ms 364 KB n=12
27 Correct 7 ms 384 KB n=100
28 Correct 388 ms 492 KB n=500
29 Correct 82 ms 620 KB n=500
30 Correct 191 ms 492 KB n=500
31 Correct 158 ms 620 KB n=500
32 Correct 440 ms 492 KB n=500
33 Correct 261 ms 492 KB n=500
34 Correct 435 ms 620 KB n=500
35 Correct 78 ms 620 KB n=500
36 Correct 3111 ms 492 KB n=500
37 Correct 3108 ms 492 KB n=500
38 Correct 3075 ms 496 KB n=500
39 Correct 273 ms 492 KB n=500
40 Correct 263 ms 620 KB n=500
41 Correct 252 ms 492 KB n=500
42 Correct 1568 ms 492 KB n=500
43 Correct 1557 ms 492 KB n=500
44 Correct 1519 ms 492 KB n=500
45 Correct 322 ms 620 KB n=500
46 Correct 75 ms 492 KB n=500
47 Correct 99 ms 492 KB n=500
48 Correct 287 ms 620 KB n=500
49 Correct 70 ms 492 KB n=500
50 Correct 325 ms 620 KB n=500
51 Correct 229 ms 492 KB n=500
52 Correct 86 ms 492 KB n=500
53 Correct 283 ms 492 KB n=500
54 Correct 259 ms 620 KB n=500
55 Correct 73 ms 364 KB n=278
56 Correct 254 ms 512 KB n=500
57 Correct 255 ms 620 KB n=500
58 Correct 1129 ms 620 KB n=500
59 Runtime error 1 ms 524 KB Execution killed with signal 11 (could be triggered by violating memory limits)
60 Halted 0 ms 0 KB -