Submission #651207

# Submission time Handle Problem Language Result Execution time Memory
651207 2022-10-18T02:44:54 Z peter940324 Birthday gift (IZhO18_treearray) C++17
0 / 100
8 ms 14436 KB
#include<bits/stdc++.h>
using namespace std;

#define double long double
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define pii pair<int,int>
#define ff first
#define ss second
#define mp make_pair

#define pb push_back
#define pf push_front
#define all(x) x.begin(),x.end()

#define de(x) cout << #x << ' ' << x << '\n';
template<class T> void prt(T l,T r){
  while(l!=r) cout << *l << ' ',l++;
  cout << '\n';
}

const int N=2e5+5,M=1e9+7,INF=1e9;

vector<int> G[N];
int dep[N],fa[N],jump[N];
void dfs(int u){
	if(dep[jump[fa[u]]]-dep[fa[u]]==dep[jump[jump[fa[u]]]]-dep[jump[fa[u]]]) jump[u]=jump[jump[fa[u]]];
	else jump[u]=fa[u];
	for(auto v:G[u]){
		if(v==fa[u]) continue;
		fa[v]=u;
		dep[v]=dep[u]+1;
		dfs(v);
	}
}
int lca(int u,int v){
	if(dep[u]<dep[v]) swap(u,v);
	while(dep[u]>dep[v]){
		if(dep[jump[u]]>=dep[v]) u=jump[u];
		else u=fa[u];
	}
	while(u!=v){
		if(jump[u]!=jump[v]){
			u=jump[u];
			v=jump[v];
		}else{
			u=fa[u];
			v=fa[v];
		}
	}
	return u;
}

/*
multiset<pii> s[4*N];
void ins(int l,int r,int cur,int ind,int val){
	if(r-l<=1){
		s[cur].insert(mp(val,ind));
		return;
	}
	s[cur].insert(mp(val,ind));
	int mid=(l+r)/2;
	if(ind<mid) ins(l,mid,cur*2,ind,val);
	else ins(mid,r,cur*2+1,ind,val);
}
void del(int l,int r,int cur,int ind,int val){
	s[cur].erase(s[cur].lower_bound(mp(val,ind)));
	if(r-l<=1){
		return;
	}
	int mid=(l+r)/2;
	if(ind<mid) del(l,mid,cur*2,ind,val);
	else del(mid,r,cur*2+1,ind,val);
}
int fi(int l,int r,int cur,int ql,int qr,int val){
	if(ql>=r||qr<=l) return 0;
	if(ql<=l&&qr>=r){
		auto it=s[cur].lower_bound(mp(val,0));
		if(it->ff==val) return it->ss;
		else return 0;
	}
	int mid=(l+r)/2;
	return max(fi(l,mid,cur*2,ql,qr,val),fi(mid,r,cur*2+1,ql,qr,val));
}
*/

multiset<int> s[N];

signed main(){
  IO
	int n,m,q;cin >> n >> m >> q;
	for(int i=0,u,v;i<n-1;i++){
		cin >> u >> v;
		G[u].pb(v);
		G[v].pb(u);
	}
	fa[1]=jump[1]=dep[1]=1;
	dfs(1);
	vector<int> a(m+1),lc(m+1);
	for(int i=1;i<=m;i++) cin >> a[i],s[a[i]].insert(i);
	for(int i=1;i<m;i++){
		lc[i]=lca(a[i],a[i+1]);
		//ins(1,m,1,i,lc[i]);
		//ins(1,m,1,i,a[i]);
		s[lc[i]].insert(i);
	}
	int t,pos,l,r,v;
	while(q--){
		cin >> t;
		if(t==1){
			cin >> pos >> v;
			if(pos!=1){
				//del(1,m,1,pos-1,lc[pos-1]);
				s[lc[pos-1]].erase(s[lc[pos-1]].lower_bound(pos-1));
			}
			if(pos!=m){
				//del(1,m,1,pos,lc[pos]);
				//del(1,m,1,pos,a[pos]);
				s[lc[pos]].erase(s[lc[pos]].lower_bound(pos));
			}
			s[a[pos]].erase(s[a[pos]].lower_bound(pos));
			a[pos]=v;
			s[a[pos]].insert(pos);
			if(pos!=1){
				lc[pos-1]=lca(a[pos-1],a[pos]);
				//ins(1,m,1,pos-1,lc[pos-1]);
				s[lc[pos-1]].insert(pos-1);
			}
			if(pos!=m){
				lc[pos]=lca(a[pos],a[pos+1]);
				//ins(1,m,1,pos,lc[pos]);
				//ins(1,m,1,pos,a[pos]);
				s[lc[pos]].insert(pos);
			}
		}else{
			cin >> l >> r >> v;
			auto it=s[v].lower_bound(l);
			int x=0;
			if(it!=s[v].end()&&(*it)<=r) x=*it;
			if(x){
				if(a[x]==v) cout << x << ' ' << x << '\n';
				else cout << x << ' ' << x+1 << '\n';
			}else cout << "-1 -1\n";
		}
	}
  return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 8 ms 14420 KB n=5
2 Correct 8 ms 14420 KB n=100
3 Correct 8 ms 14364 KB n=100
4 Correct 8 ms 14436 KB n=100
5 Correct 8 ms 14420 KB n=100
6 Correct 8 ms 14420 KB n=100
7 Correct 7 ms 14420 KB n=100
8 Correct 8 ms 14324 KB n=100
9 Correct 8 ms 14420 KB n=100
10 Correct 8 ms 14428 KB n=100
11 Correct 8 ms 14420 KB n=100
12 Incorrect 8 ms 14420 KB Wrong output format.
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14420 KB n=5
2 Correct 8 ms 14420 KB n=100
3 Correct 8 ms 14364 KB n=100
4 Correct 8 ms 14436 KB n=100
5 Correct 8 ms 14420 KB n=100
6 Correct 8 ms 14420 KB n=100
7 Correct 7 ms 14420 KB n=100
8 Correct 8 ms 14324 KB n=100
9 Correct 8 ms 14420 KB n=100
10 Correct 8 ms 14428 KB n=100
11 Correct 8 ms 14420 KB n=100
12 Incorrect 8 ms 14420 KB Wrong output format.
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14420 KB n=5
2 Correct 8 ms 14420 KB n=100
3 Correct 8 ms 14364 KB n=100
4 Correct 8 ms 14436 KB n=100
5 Correct 8 ms 14420 KB n=100
6 Correct 8 ms 14420 KB n=100
7 Correct 7 ms 14420 KB n=100
8 Correct 8 ms 14324 KB n=100
9 Correct 8 ms 14420 KB n=100
10 Correct 8 ms 14428 KB n=100
11 Correct 8 ms 14420 KB n=100
12 Incorrect 8 ms 14420 KB Wrong output format.
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14420 KB n=5
2 Correct 8 ms 14420 KB n=100
3 Correct 8 ms 14364 KB n=100
4 Correct 8 ms 14436 KB n=100
5 Correct 8 ms 14420 KB n=100
6 Correct 8 ms 14420 KB n=100
7 Correct 7 ms 14420 KB n=100
8 Correct 8 ms 14324 KB n=100
9 Correct 8 ms 14420 KB n=100
10 Correct 8 ms 14428 KB n=100
11 Correct 8 ms 14420 KB n=100
12 Incorrect 8 ms 14420 KB Wrong output format.
13 Halted 0 ms 0 KB -