Submission #334862

# Submission time Handle Problem Language Result Execution time Memory
334862 2020-12-10T05:50:15 Z tengiz05 Birthday gift (IZhO18_treearray) C++17
0 / 100
36 ms 5132 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
const int mod = 1e9+7, N = 2e5+5;
int msb(int val){return sizeof(int)*8-__builtin_clzll(val);}
int sz, n, m, k;
vector<int> edges[N];
int tin[N], tout[N];
int up[N][19];
int timer;
int depth[N];
void dfs(int u, int p, int d=0){
	tin[u] = timer++;
	depth[u] = d;
	up[u][0] = p;
	for(int i=1;i<19;i++)up[u][i] = up[up[u][i-1]][i-1];
	for(auto v : edges[u]){
		if(v != p){
			dfs(v, u,d+1);
		}
	}tout[u] = timer++;
}
bool isancestor(int u, int v){
	return tin[u] <= tin[v] && tout[u] >= tout[v];
}
int lca(int u, int v){
	if(isancestor(u,v))return u;
	if(isancestor(v,u))return v;
	for(int i=18;i>=0;i--){
		if(!isancestor(up[u][i], v))u = up[u][i];
	}return up[u][0];
}

int t[N*4];
void update(int p, int val){
	for(t[p+=sz] = val; p>1; p>>=1)t[p>>1] = lca(t[p], t[p^1]);
}
int rangelca(int l, int r){
	int ans = 0;
	for(l+=sz,r+=sz;l<=r;l>>=1,r>>=1){
		if(l%2 == 1){
			if(ans == 0)ans = t[l++];
			else ans = lca(ans, t[l++]);
		}if(r%2==0){
			if(ans == 0)ans = t[r--];
			else ans = lca(ans, t[r--]);
		}
	}return ans;
}
/*int lef(int l, int r, int L, int R, int node, int v){
	if(L >= r || R <= l)return -1;
	if(depth[t[node]] > depth[v])return -1;
	int mid = (L+R)/2;
	if(L >= l && R <= r){
		
	}else {
		return max(lef(l,r,L, mid, node*2, v), lef(l,r, mid, R, node*2+1, v));
	}
}*/
void solve(int test_case){
	int i, j, q;
	cin >> n >> m >> q;
	for(i=1;i<n;i++){
		int u, v;
		cin >> u >> v;
		edges[u].pb(v);
		edges[v].pb(u);
	}dfs(1,1);
	sz=1;
	while(sz < n)sz<<=1;
	for(i=0;i<m;i++){
		cin >> t[i+sz];
	}for(i=sz-1;i>0;i--){
		t[i] = lca(t[i*2], t[i*2+1]);
	}
	while(q--){
		int type;
		cin >> type;
		if(type == 1){
			int pos, val;
			cin >> pos >> val;
			update(pos-1, val);
		}else {
			int l, r, v;
			cin >> l >> r >> v;
			l--,r--;
			bool flag = true;
			int L, R;
			int ansl=-2, ansr=-2;
			for(L=l; L <= r&&flag; L++){
				for(R=L; R <= r&&flag; R++){
					if(rangelca(L, R) == v){
						ansl = L, ansr = R;
						flag = false;
					}
				}
			}cout << ansl+1 << ' ' << ansr+1 << '\n';
		/*	int L=l, R=l;
		
			for(;L <= r; L++){
				R = max(R, L);
				if(rangelca(L,R) == v){L++;break;}
				while(R+1 <= r && depth[lca(v, rangelca(L, R+1))] <= depth[v]){
					if(rangelca(L,R) == v){L++;break;}
					R++;
				}
				if(rangelca(L,R) == v){L++;break;}	
			}L--;
		//	cout << rangelca(L, R) << '\n';
			if(rangelca(L,R) == v)cout << L+1 << ' ' << R+1 << '\n';
			else cout << "-1 -1\n";*/
		}
	}
	return;
}

signed main(){
	FASTIO;
#define MULTITEST 0
#if MULTITEST
	int ___T;
	cin >> ___T;
	for(int T_CASE = 1; T_CASE <= ___T; T_CASE++)
		solve(T_CASE);
#else
	solve(1);
#endif
	return 0;
}




Compilation message

treearray.cpp: In function 'void solve(long long int)':
treearray.cpp:69:9: warning: unused variable 'j' [-Wunused-variable]
   69 |  int i, j, q;
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB n=5
2 Correct 8 ms 5100 KB n=100
3 Correct 7 ms 5100 KB n=100
4 Correct 5 ms 5100 KB n=100
5 Correct 4 ms 5132 KB n=100
6 Correct 36 ms 5100 KB n=100
7 Correct 33 ms 5100 KB n=100
8 Correct 7 ms 5100 KB n=100
9 Correct 6 ms 5100 KB n=100
10 Correct 21 ms 5100 KB n=100
11 Correct 23 ms 5100 KB n=100
12 Correct 4 ms 5100 KB n=100
13 Correct 4 ms 5100 KB n=100
14 Correct 4 ms 5100 KB n=100
15 Correct 4 ms 5100 KB n=100
16 Correct 4 ms 5100 KB n=100
17 Correct 7 ms 5100 KB n=100
18 Correct 6 ms 5100 KB n=100
19 Correct 4 ms 5100 KB n=100
20 Correct 6 ms 5100 KB n=100
21 Correct 5 ms 5100 KB n=100
22 Correct 4 ms 5100 KB n=100
23 Correct 8 ms 5100 KB n=100
24 Correct 9 ms 5100 KB n=100
25 Correct 5 ms 5100 KB n=100
26 Incorrect 4 ms 5100 KB Wrong range.
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB n=5
2 Correct 8 ms 5100 KB n=100
3 Correct 7 ms 5100 KB n=100
4 Correct 5 ms 5100 KB n=100
5 Correct 4 ms 5132 KB n=100
6 Correct 36 ms 5100 KB n=100
7 Correct 33 ms 5100 KB n=100
8 Correct 7 ms 5100 KB n=100
9 Correct 6 ms 5100 KB n=100
10 Correct 21 ms 5100 KB n=100
11 Correct 23 ms 5100 KB n=100
12 Correct 4 ms 5100 KB n=100
13 Correct 4 ms 5100 KB n=100
14 Correct 4 ms 5100 KB n=100
15 Correct 4 ms 5100 KB n=100
16 Correct 4 ms 5100 KB n=100
17 Correct 7 ms 5100 KB n=100
18 Correct 6 ms 5100 KB n=100
19 Correct 4 ms 5100 KB n=100
20 Correct 6 ms 5100 KB n=100
21 Correct 5 ms 5100 KB n=100
22 Correct 4 ms 5100 KB n=100
23 Correct 8 ms 5100 KB n=100
24 Correct 9 ms 5100 KB n=100
25 Correct 5 ms 5100 KB n=100
26 Incorrect 4 ms 5100 KB Wrong range.
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB n=5
2 Correct 8 ms 5100 KB n=100
3 Correct 7 ms 5100 KB n=100
4 Correct 5 ms 5100 KB n=100
5 Correct 4 ms 5132 KB n=100
6 Correct 36 ms 5100 KB n=100
7 Correct 33 ms 5100 KB n=100
8 Correct 7 ms 5100 KB n=100
9 Correct 6 ms 5100 KB n=100
10 Correct 21 ms 5100 KB n=100
11 Correct 23 ms 5100 KB n=100
12 Correct 4 ms 5100 KB n=100
13 Correct 4 ms 5100 KB n=100
14 Correct 4 ms 5100 KB n=100
15 Correct 4 ms 5100 KB n=100
16 Correct 4 ms 5100 KB n=100
17 Correct 7 ms 5100 KB n=100
18 Correct 6 ms 5100 KB n=100
19 Correct 4 ms 5100 KB n=100
20 Correct 6 ms 5100 KB n=100
21 Correct 5 ms 5100 KB n=100
22 Correct 4 ms 5100 KB n=100
23 Correct 8 ms 5100 KB n=100
24 Correct 9 ms 5100 KB n=100
25 Correct 5 ms 5100 KB n=100
26 Incorrect 4 ms 5100 KB Wrong range.
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB n=5
2 Correct 8 ms 5100 KB n=100
3 Correct 7 ms 5100 KB n=100
4 Correct 5 ms 5100 KB n=100
5 Correct 4 ms 5132 KB n=100
6 Correct 36 ms 5100 KB n=100
7 Correct 33 ms 5100 KB n=100
8 Correct 7 ms 5100 KB n=100
9 Correct 6 ms 5100 KB n=100
10 Correct 21 ms 5100 KB n=100
11 Correct 23 ms 5100 KB n=100
12 Correct 4 ms 5100 KB n=100
13 Correct 4 ms 5100 KB n=100
14 Correct 4 ms 5100 KB n=100
15 Correct 4 ms 5100 KB n=100
16 Correct 4 ms 5100 KB n=100
17 Correct 7 ms 5100 KB n=100
18 Correct 6 ms 5100 KB n=100
19 Correct 4 ms 5100 KB n=100
20 Correct 6 ms 5100 KB n=100
21 Correct 5 ms 5100 KB n=100
22 Correct 4 ms 5100 KB n=100
23 Correct 8 ms 5100 KB n=100
24 Correct 9 ms 5100 KB n=100
25 Correct 5 ms 5100 KB n=100
26 Incorrect 4 ms 5100 KB Wrong range.
27 Halted 0 ms 0 KB -