Submission #501189

# Submission time Handle Problem Language Result Execution time Memory
501189 2022-01-02T15:04:17 Z beksultan04 Birthday gift (IZhO18_treearray) C++14
0 / 100
19 ms 35660 KB
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define pii pair<int,int>
#define ret return
#define fr first
#define sc second
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define nosol puts("-1");
#define pb push_back
#define endi puts("");
#define ordered_set tree <int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const int N = 5e5+12,INF = 1e9+7;
int a[N],der[N],cnt,up[20][N],tin[N],tout[N];
vector <int> g[N];
set <pii> s[N];
void dfs(int x,int p){
	up[0][x] = p;
	tin[x] = cnt++;
	for (int i=1;i<20;++i)
		up[i][x] = up[i-1][up[i-1][x]];
	
	for (auto to: g[x]){
		if (to == p)continue;
		dfs(to,x);
	}
	tout[x] = cnt++;
}

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

int lca(int a,int b){
	
	if (is_up(a,b))ret a;
	if (is_up(b,a))ret b;
	
	for (int i=19;i>=0;--i){
		if (!is_up(up[i][a],b)){
			a = up[i][a];
		}
	}
	ret up[0][a];
}



main(){
	int n,m,i,j,t;
	cin>>n>>m>>t;
	for (i=1;i<n;++i){
		int x,y;
		cin>>x>>y;
		g[x].pb(y);
		g[y].pb(x);
	}
	dfs(1,1);
	for (i=1;i<=m;++i){	
		cin>>a[i];
		if (i > 1){
			int lc = lca(a[i],a[i-1]);
			s[lc].insert({i-1,i});
		}
		s[a[i]].insert({i,i});
	}
	while (t--){
		int type;
		cin>>type;
		if (type == 2){
			int l,r,v;
			cin>>l>>r>>v;
			
			auto it = s[v].lower_bound({l,0});
			if (it == s[v].end()){
				cout <<"-1 -1\n";
			}
			else {
				cout <<it->fr<<" "<<it->sc<<"\n";
			}
		}
		else {
			int pos,x;
			cin>>pos>>x;
			s[a[pos]].erase({pos,pos});
			if (pos > 1){
				int lc = lca(a[pos],a[pos-1]);
				s[lc].erase({pos-1,pos});
			}
			if (pos < m){
				int lc = lca(a[pos],a[pos+1]);
				s[lc].erase({pos,pos+1});
			}
			
			a[pos] = x;
			
			s[a[pos]].insert({pos,pos});
			if (pos > 1){
				int lc = lca(a[pos],a[pos-1]);
				s[lc].insert({pos-1,pos});
			}
			if (pos < m){
				int lc = lca(a[pos],a[pos+1]);
				s[lc].insert({pos,pos+1});
			}
		}
	}
	
	
	
	
	
}








Compilation message

treearray.cpp:56:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   56 | main(){
      | ^~~~
treearray.cpp: In function 'int main()':
treearray.cpp:57:12: warning: unused variable 'j' [-Wunused-variable]
   57 |  int n,m,i,j,t;
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 18 ms 35660 KB n=5
2 Incorrect 19 ms 35652 KB Wrong output format.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 35660 KB n=5
2 Incorrect 19 ms 35652 KB Wrong output format.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 35660 KB n=5
2 Incorrect 19 ms 35652 KB Wrong output format.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 35660 KB n=5
2 Incorrect 19 ms 35652 KB Wrong output format.
3 Halted 0 ms 0 KB -