Submission #501488

# Submission time Handle Problem Language Result Execution time Memory
501488 2022-01-03T13:20:35 Z tmn2005 Birthday gift (IZhO18_treearray) C++17
0 / 100
12 ms 23756 KB
#include<bits/stdc++.h>
using namespace std;


#define ar array
#define fr first
#define sc second

#define vec vector
#define ret return

#define ins insert
#define mk make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front

#define int long long

#define pii pair<int,int>

#define all(s) s.begin(), s.end()
#define allr(s) s.rbegin(), s.rend()

#define NeedForSpeed ios::sync_with_stdio(0),cin.tie(0);
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const int N=1e6+12,INF=1e9,mod = 1e9+7;
bool iswowel(char n){ n = toupper(n); if(n == 'A' || n == 'O' || n == 'U' || n == 'E' || n == 'I') return true; else return false;}
int n,m,k,x,y,l,ll,r,o,ans,res,timer,ok,mx,mn = INF;
int a[N], tin[N], tout[N];
vec<int>g[N];
int up[N][30];

void dfs(int v, int pred){
	tin[v] = ++timer;
	up[v][0] = pred;
	for(int i=1; i<=l; i++)
		up[v][i] = up[up[v][i-1]][i-1];
	for(int to : g[v]){
		if(to != pred){
			dfs(to, v);
		}
	}
	tout[v] = ++timer;
}
bool upper(int a, int b){
	ret tin[a] <= tin[b] && tout[b] <= tout[a];
}
int lca(int a, int b){
	if(upper(a, b))ret a;
	if(upper(b, a))ret b;
	for(int i=l; i>=0; i--){
		if(!upper(up[a][i], b))
			a = up[a][i];
	}
	ret up[a][0];
}
main(){
	NeedForSpeed
    cin>>m>>n>>o;
    m--;
    while(m--){
    	cin>>x>>y;
    	g[x].pb(y);
    	g[y].pb(x);
	}
	for(int i=1; i<=n; i++)cin>>a[i];
	
	l = 1;
	while((1<<l) <= n)l++;
	dfs(1,1);
	
	while(o--){
		cin>>ok;
		if(ok == 1){
			cin>>ll>>r;
			a[ll] = r;
		}
		else{
			y = 0;
			cin>>ll>>r>>x;
			for(int i=ll; i<r; i++){
				if(lca(a[i], a[i+1]) == x){
					cout<<i<<" "<<i+1<<endl;
					y = 1;
					break;
				}
				else if(lca(a[i], a[i]) == x){
					cout<<i<<" "<<i<<endl;
					y = 1;
					break;
				}
			}
			if(!y)cout<<"-1 -1"<<endl;
		}
	}



	return 0;
}



Compilation message

treearray.cpp:59:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   59 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23756 KB n=5
2 Incorrect 11 ms 23756 KB Jury has the answer but participant has not
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23756 KB n=5
2 Incorrect 11 ms 23756 KB Jury has the answer but participant has not
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23756 KB n=5
2 Incorrect 11 ms 23756 KB Jury has the answer but participant has not
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23756 KB n=5
2 Incorrect 11 ms 23756 KB Jury has the answer but participant has not
3 Halted 0 ms 0 KB -