Submission #887384

# Submission time Handle Problem Language Result Execution time Memory
887384 2023-12-14T11:22:19 Z pcc Birthday gift (IZhO18_treearray) C++14
56 / 100
459 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
#define mid ((l+r)>>1)

const int mxn = 2e5+10;
int n,m,q;
pii dfn[mxn];
int par[mxn][20];
int dep[mxn];
vector<int> tree[mxn];
int arr[mxn];
int ppp = 0;
set<pair<int,pii>> segtree[mxn*4];

void dfs(int now){
	for(int i = 1;i<20;i++)par[now][i] = par[par[now][i-1]][i-1];
	for(auto nxt:tree[now]){
		if(nxt == par[now][0])continue;
		dep[nxt] = dep[now]+1;
		par[nxt][0] = now;
		dfs(nxt);
	}
	return;
}

int anc(int a,int b){
	if(dep[a]<dep[b])swap(a,b);
	int d = dep[a]-dep[b];
	for(int i = 19;i>=0;i--){
		if(d&(1<<i))a = par[a][i];
	}
	for(int i = 19;i>=0;i--){
		if(par[a][i] != par[b][i])a = par[a][i],b = par[b][i];
	}
	return a==b?a:par[a][0];
}

void maketree(int now,int l,int r){
	if(l == r){
		segtree[now].insert(make_pair(arr[l],make_pair(l,l)));
		return;
	}
	maketree(now*2+1,l,mid);
	maketree(now*2+2,mid+1,r);
	for(auto &i:segtree[now*2+1])segtree[now].insert(i);
	for(auto &i:segtree[now*2+2])segtree[now].insert(i);
	segtree[now].insert({anc(arr[mid],arr[mid+1]),{mid,mid+1}});
	//cout<<now<<":"<<l<<' '<<r<<":";for(auto &i:segtree[now])cout<<i.fs<<',';cout<<endl;
	return;
}
void modify(int now,int l,int r,int p,int v){
	segtree[now].erase(segtree[now].find({arr[p],{p,p}}));
	segtree[now].insert({v,{p,p}});
	if(p != l){
		segtree[now].erase(segtree[now].find({anc(arr[p-1],arr[p]),{p-1,p}}));
		segtree[now].insert({anc(arr[p-1],v),{p-1,p}});
	}
	if(p != r){
		segtree[now].erase(segtree[now].find({anc(arr[p],arr[p+1]),{p,p+1}}));
		segtree[now].insert({anc(arr[p+1],v),{p,p+1}});
	}
	if(l == r)return;
	if(mid>=p)modify(now*2+1,l,mid,p,v);
	else modify(now*2+2,mid+1,r,p,v);
	return;
}

pii getval(int now,int l,int r,int s,int e,int tar){
	if(l>=s&&e>=r){
		auto it = segtree[now].lower_bound({tar,{0,0}});
		if(it != segtree[now].end()&&it->fs == tar){
			return it->sc;
		}
		else return {-1,-1};
	}
	if(mid>=e)return getval(now*2+1,l,mid,s,e,tar);
	else if(mid<s)return getval(now*2+2,mid+1,r,s,e,tar);
	else{
		if(anc(arr[mid],arr[mid+1]) == tar)return {mid,mid+1};
		auto re = getval(now*2+1,l,mid,s,e,tar);
		if(re.fs != -1)return re;
		else return getval(now*2+2,mid+1,r,s,e,tar);
	}
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m>>q;
	for(int i = 1;i<n;i++){
		int a,b;
		cin>>a>>b;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}
	for(int i = 1;i<=m;i++){
		cin>>arr[i];
	}
	par[1][0] = 1;
	dfs(1);
	maketree(0,1,m);
	//for(auto &i:segtree[0])cout<<i.fs<<' '<<i.sc.fs<<','<<i.sc.sc<<';';
	while(q--){
		int tp;
		cin>>tp;
		if(tp == 1){
			int p,v;
			cin>>p>>v;
			modify(0,1,m,p,v);
			arr[p] = v;
		}
		else{
			int l,r,v;
			cin>>l>>r>>v;
			auto re = getval(0,1,m,l,r,v);
			cout<<re.fs<<' '<<re.sc<<'\n';
		}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 45660 KB n=5
2 Correct 9 ms 45660 KB n=100
3 Correct 10 ms 45660 KB n=100
4 Correct 11 ms 45660 KB n=100
5 Correct 10 ms 45660 KB n=100
6 Correct 9 ms 45660 KB n=100
7 Correct 9 ms 45688 KB n=100
8 Correct 10 ms 45660 KB n=100
9 Correct 9 ms 45656 KB n=100
10 Correct 10 ms 45660 KB n=100
11 Correct 10 ms 45660 KB n=100
12 Correct 9 ms 45656 KB n=100
13 Correct 9 ms 45660 KB n=100
14 Correct 9 ms 45660 KB n=100
15 Correct 9 ms 45660 KB n=100
16 Correct 9 ms 45660 KB n=100
17 Correct 9 ms 45660 KB n=100
18 Correct 9 ms 45660 KB n=100
19 Correct 9 ms 45660 KB n=100
20 Correct 9 ms 45660 KB n=100
21 Correct 9 ms 45656 KB n=100
22 Correct 9 ms 45660 KB n=100
23 Correct 9 ms 45660 KB n=100
24 Correct 9 ms 45656 KB n=100
25 Correct 9 ms 45660 KB n=100
26 Correct 9 ms 45660 KB n=12
27 Correct 9 ms 45660 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 9 ms 45660 KB n=5
2 Correct 9 ms 45660 KB n=100
3 Correct 10 ms 45660 KB n=100
4 Correct 11 ms 45660 KB n=100
5 Correct 10 ms 45660 KB n=100
6 Correct 9 ms 45660 KB n=100
7 Correct 9 ms 45688 KB n=100
8 Correct 10 ms 45660 KB n=100
9 Correct 9 ms 45656 KB n=100
10 Correct 10 ms 45660 KB n=100
11 Correct 10 ms 45660 KB n=100
12 Correct 9 ms 45656 KB n=100
13 Correct 9 ms 45660 KB n=100
14 Correct 9 ms 45660 KB n=100
15 Correct 9 ms 45660 KB n=100
16 Correct 9 ms 45660 KB n=100
17 Correct 9 ms 45660 KB n=100
18 Correct 9 ms 45660 KB n=100
19 Correct 9 ms 45660 KB n=100
20 Correct 9 ms 45660 KB n=100
21 Correct 9 ms 45656 KB n=100
22 Correct 9 ms 45660 KB n=100
23 Correct 9 ms 45660 KB n=100
24 Correct 9 ms 45656 KB n=100
25 Correct 9 ms 45660 KB n=100
26 Correct 9 ms 45660 KB n=12
27 Correct 9 ms 45660 KB n=100
28 Correct 12 ms 46172 KB n=500
29 Correct 13 ms 46388 KB n=500
30 Correct 13 ms 46184 KB n=500
31 Correct 13 ms 46168 KB n=500
32 Correct 12 ms 46172 KB n=500
33 Correct 14 ms 46172 KB n=500
34 Correct 12 ms 46172 KB n=500
35 Correct 13 ms 46328 KB n=500
36 Correct 10 ms 46172 KB n=500
37 Correct 10 ms 46172 KB n=500
38 Correct 10 ms 46172 KB n=500
39 Correct 11 ms 46172 KB n=500
40 Correct 10 ms 46168 KB n=500
41 Correct 11 ms 46172 KB n=500
42 Correct 12 ms 46172 KB n=500
43 Correct 13 ms 46172 KB n=500
44 Correct 13 ms 46356 KB n=500
45 Correct 12 ms 46168 KB n=500
46 Correct 12 ms 46168 KB n=500
47 Correct 13 ms 46172 KB n=500
48 Correct 13 ms 46292 KB n=500
49 Correct 12 ms 46200 KB n=500
50 Correct 12 ms 46172 KB n=500
51 Correct 13 ms 46172 KB n=500
52 Correct 13 ms 46168 KB n=500
53 Correct 13 ms 46172 KB n=500
54 Correct 12 ms 46192 KB n=500
55 Correct 11 ms 46172 KB n=278
56 Correct 14 ms 46168 KB n=500
57 Correct 13 ms 46172 KB n=500
58 Correct 11 ms 46312 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 9 ms 45660 KB n=5
2 Correct 9 ms 45660 KB n=100
3 Correct 10 ms 45660 KB n=100
4 Correct 11 ms 45660 KB n=100
5 Correct 10 ms 45660 KB n=100
6 Correct 9 ms 45660 KB n=100
7 Correct 9 ms 45688 KB n=100
8 Correct 10 ms 45660 KB n=100
9 Correct 9 ms 45656 KB n=100
10 Correct 10 ms 45660 KB n=100
11 Correct 10 ms 45660 KB n=100
12 Correct 9 ms 45656 KB n=100
13 Correct 9 ms 45660 KB n=100
14 Correct 9 ms 45660 KB n=100
15 Correct 9 ms 45660 KB n=100
16 Correct 9 ms 45660 KB n=100
17 Correct 9 ms 45660 KB n=100
18 Correct 9 ms 45660 KB n=100
19 Correct 9 ms 45660 KB n=100
20 Correct 9 ms 45660 KB n=100
21 Correct 9 ms 45656 KB n=100
22 Correct 9 ms 45660 KB n=100
23 Correct 9 ms 45660 KB n=100
24 Correct 9 ms 45656 KB n=100
25 Correct 9 ms 45660 KB n=100
26 Correct 9 ms 45660 KB n=12
27 Correct 9 ms 45660 KB n=100
28 Correct 12 ms 46172 KB n=500
29 Correct 13 ms 46388 KB n=500
30 Correct 13 ms 46184 KB n=500
31 Correct 13 ms 46168 KB n=500
32 Correct 12 ms 46172 KB n=500
33 Correct 14 ms 46172 KB n=500
34 Correct 12 ms 46172 KB n=500
35 Correct 13 ms 46328 KB n=500
36 Correct 10 ms 46172 KB n=500
37 Correct 10 ms 46172 KB n=500
38 Correct 10 ms 46172 KB n=500
39 Correct 11 ms 46172 KB n=500
40 Correct 10 ms 46168 KB n=500
41 Correct 11 ms 46172 KB n=500
42 Correct 12 ms 46172 KB n=500
43 Correct 13 ms 46172 KB n=500
44 Correct 13 ms 46356 KB n=500
45 Correct 12 ms 46168 KB n=500
46 Correct 12 ms 46168 KB n=500
47 Correct 13 ms 46172 KB n=500
48 Correct 13 ms 46292 KB n=500
49 Correct 12 ms 46200 KB n=500
50 Correct 12 ms 46172 KB n=500
51 Correct 13 ms 46172 KB n=500
52 Correct 13 ms 46168 KB n=500
53 Correct 13 ms 46172 KB n=500
54 Correct 12 ms 46192 KB n=500
55 Correct 11 ms 46172 KB n=278
56 Correct 14 ms 46168 KB n=500
57 Correct 13 ms 46172 KB n=500
58 Correct 11 ms 46312 KB n=500
59 Correct 31 ms 48536 KB n=2000
60 Correct 30 ms 48732 KB n=2000
61 Correct 33 ms 48476 KB n=2000
62 Correct 29 ms 48476 KB n=2000
63 Correct 26 ms 48476 KB n=2000
64 Correct 29 ms 48572 KB n=2000
65 Correct 26 ms 48472 KB n=2000
66 Correct 30 ms 48676 KB n=2000
67 Correct 27 ms 48628 KB n=2000
68 Correct 30 ms 48512 KB n=2000
69 Correct 19 ms 48472 KB n=2000
70 Correct 16 ms 48476 KB n=2000
71 Correct 17 ms 48476 KB n=2000
72 Correct 18 ms 48476 KB n=2000
73 Correct 19 ms 48472 KB n=2000
74 Correct 23 ms 48728 KB n=1844
75 Correct 18 ms 48476 KB n=2000
76 Correct 27 ms 48472 KB n=2000
77 Correct 27 ms 48476 KB n=2000
78 Correct 26 ms 48472 KB n=2000
79 Correct 27 ms 48476 KB n=2000
80 Correct 30 ms 48472 KB n=2000
81 Correct 31 ms 48476 KB n=2000
82 Correct 26 ms 48472 KB n=2000
83 Correct 30 ms 48472 KB n=2000
84 Correct 27 ms 48476 KB n=2000
85 Correct 35 ms 48728 KB n=2000
86 Correct 30 ms 48472 KB n=2000
87 Correct 27 ms 48476 KB n=2000
88 Correct 34 ms 48728 KB n=2000
89 Correct 32 ms 48744 KB n=2000
90 Correct 30 ms 48732 KB n=2000
91 Correct 21 ms 48728 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 9 ms 45660 KB n=5
2 Correct 9 ms 45660 KB n=100
3 Correct 10 ms 45660 KB n=100
4 Correct 11 ms 45660 KB n=100
5 Correct 10 ms 45660 KB n=100
6 Correct 9 ms 45660 KB n=100
7 Correct 9 ms 45688 KB n=100
8 Correct 10 ms 45660 KB n=100
9 Correct 9 ms 45656 KB n=100
10 Correct 10 ms 45660 KB n=100
11 Correct 10 ms 45660 KB n=100
12 Correct 9 ms 45656 KB n=100
13 Correct 9 ms 45660 KB n=100
14 Correct 9 ms 45660 KB n=100
15 Correct 9 ms 45660 KB n=100
16 Correct 9 ms 45660 KB n=100
17 Correct 9 ms 45660 KB n=100
18 Correct 9 ms 45660 KB n=100
19 Correct 9 ms 45660 KB n=100
20 Correct 9 ms 45660 KB n=100
21 Correct 9 ms 45656 KB n=100
22 Correct 9 ms 45660 KB n=100
23 Correct 9 ms 45660 KB n=100
24 Correct 9 ms 45656 KB n=100
25 Correct 9 ms 45660 KB n=100
26 Correct 9 ms 45660 KB n=12
27 Correct 9 ms 45660 KB n=100
28 Correct 12 ms 46172 KB n=500
29 Correct 13 ms 46388 KB n=500
30 Correct 13 ms 46184 KB n=500
31 Correct 13 ms 46168 KB n=500
32 Correct 12 ms 46172 KB n=500
33 Correct 14 ms 46172 KB n=500
34 Correct 12 ms 46172 KB n=500
35 Correct 13 ms 46328 KB n=500
36 Correct 10 ms 46172 KB n=500
37 Correct 10 ms 46172 KB n=500
38 Correct 10 ms 46172 KB n=500
39 Correct 11 ms 46172 KB n=500
40 Correct 10 ms 46168 KB n=500
41 Correct 11 ms 46172 KB n=500
42 Correct 12 ms 46172 KB n=500
43 Correct 13 ms 46172 KB n=500
44 Correct 13 ms 46356 KB n=500
45 Correct 12 ms 46168 KB n=500
46 Correct 12 ms 46168 KB n=500
47 Correct 13 ms 46172 KB n=500
48 Correct 13 ms 46292 KB n=500
49 Correct 12 ms 46200 KB n=500
50 Correct 12 ms 46172 KB n=500
51 Correct 13 ms 46172 KB n=500
52 Correct 13 ms 46168 KB n=500
53 Correct 13 ms 46172 KB n=500
54 Correct 12 ms 46192 KB n=500
55 Correct 11 ms 46172 KB n=278
56 Correct 14 ms 46168 KB n=500
57 Correct 13 ms 46172 KB n=500
58 Correct 11 ms 46312 KB n=500
59 Correct 31 ms 48536 KB n=2000
60 Correct 30 ms 48732 KB n=2000
61 Correct 33 ms 48476 KB n=2000
62 Correct 29 ms 48476 KB n=2000
63 Correct 26 ms 48476 KB n=2000
64 Correct 29 ms 48572 KB n=2000
65 Correct 26 ms 48472 KB n=2000
66 Correct 30 ms 48676 KB n=2000
67 Correct 27 ms 48628 KB n=2000
68 Correct 30 ms 48512 KB n=2000
69 Correct 19 ms 48472 KB n=2000
70 Correct 16 ms 48476 KB n=2000
71 Correct 17 ms 48476 KB n=2000
72 Correct 18 ms 48476 KB n=2000
73 Correct 19 ms 48472 KB n=2000
74 Correct 23 ms 48728 KB n=1844
75 Correct 18 ms 48476 KB n=2000
76 Correct 27 ms 48472 KB n=2000
77 Correct 27 ms 48476 KB n=2000
78 Correct 26 ms 48472 KB n=2000
79 Correct 27 ms 48476 KB n=2000
80 Correct 30 ms 48472 KB n=2000
81 Correct 31 ms 48476 KB n=2000
82 Correct 26 ms 48472 KB n=2000
83 Correct 30 ms 48472 KB n=2000
84 Correct 27 ms 48476 KB n=2000
85 Correct 35 ms 48728 KB n=2000
86 Correct 30 ms 48472 KB n=2000
87 Correct 27 ms 48476 KB n=2000
88 Correct 34 ms 48728 KB n=2000
89 Correct 32 ms 48744 KB n=2000
90 Correct 30 ms 48732 KB n=2000
91 Correct 21 ms 48728 KB n=2000
92 Runtime error 459 ms 262144 KB Execution killed with signal 9
93 Halted 0 ms 0 KB -