Submission #545693

# Submission time Handle Problem Language Result Execution time Memory
545693 2022-04-05T07:56:59 Z dostigator Birthday gift (IZhO18_treearray) C++17
100 / 100
1562 ms 85760 KB
#include <bits/stdc++.h>
using namespace std;

/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
*/

#define all(a) a.begin(),a.end()
#define vt vector
#define pb push_back
#define endl '\n'
#define Y second
#define X first
typedef long long ll;
typedef long double ld;
const ll mod=1e9+7;
const ll INF=1e18;
const int inf=1e9;
const int N=2e5+777;
const int M=2e3;

vt<int>g[N];
set<int>pos1[N],pos2[N];
int a[N],b[N],n,m,q,tin[N],tout[N],tim,up[30][N];

void dfs(int x,int pr){
	tin[x]=tim++;
	up[0][x]=pr;
	for(int i=1; i<20; ++i) up[i][x]=up[i-1][up[i-1][x]];
	for(int to:g[x]) if(to!=pr){
		dfs(to,x);
	}tout[x]=tim++;
}

bool isparent(int lol,int kek){
	return (tin[lol]<=tin[kek] && tout[kek]<=tout[lol]);
}

int lca(int lol,int kek){
	if(isparent(lol,kek))return lol;
	if(isparent(kek,lol))return kek;
	for(int i=19;i>=0;--i)if(!isparent(up[i][lol],kek))lol=up[i][lol];
	return up[0][lol];
}

void solve(){
	cin>>n>>m>>q;
	while(--n){
		int u,v;
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}
	dfs(1,1);
	for(int i=1; i<=m; ++i){
		cin>>a[i];
		pos1[a[i]].insert(i);
		if(i>1){
			b[i]=lca(a[i],a[i-1]);
			pos2[b[i]].insert(i);
		}
	}
	for(int i=1; i<=q; ++i){
		int tp;
		cin>>tp;
		if(tp==2){
			int l,r,v;
			cin>>l>>r>>v;
			if(pos1[v].empty() || *pos1[v].rbegin()<l){}
			else {
				int h=*pos1[v].lower_bound(l);
				if(h<=r){
					cout<<h<<' '<<h<<endl;
					continue;
				}
			}
			if(pos2[v].empty() || *pos2[v].rbegin()<=l){}
			else {
				int h=*pos2[v].upper_bound(l);
				if(h<=r){
					cout<<h-1<<' '<<h<<endl;
					continue;
				}
			}
			cout<<-1<<' '<<-1<<endl;
			continue;
		}
		int pos,v;
		cin>>pos>>v;
		pos1[a[pos]].erase(pos);
		pos1[v].insert(pos);
		if(pos>1)pos2[b[pos]].erase(pos);
		if(pos<m)pos2[b[pos+1]].erase(pos+1);
		a[pos]=v;
		if(pos>1)pos2[lca(a[pos],a[pos-1])].insert(pos);
		if(pos<m)pos2[lca(a[pos],a[pos+1])].insert(pos+1);
		if(pos>1) b[pos]=lca(a[pos],a[pos-1]);
		if(pos<m)b[pos+1]=lca(a[pos+1],a[pos]);
	}
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll tt=1;
    //cin>>tt;
    while(tt--)solve();
}

# Verdict Execution time Memory Grader output
1 Correct 12 ms 24020 KB n=5
2 Correct 14 ms 24020 KB n=100
3 Correct 13 ms 24044 KB n=100
4 Correct 13 ms 24020 KB n=100
5 Correct 13 ms 24020 KB n=100
6 Correct 14 ms 24020 KB n=100
7 Correct 14 ms 24020 KB n=100
8 Correct 14 ms 24028 KB n=100
9 Correct 13 ms 24020 KB n=100
10 Correct 14 ms 24020 KB n=100
11 Correct 12 ms 24060 KB n=100
12 Correct 14 ms 23972 KB n=100
13 Correct 13 ms 24024 KB n=100
14 Correct 13 ms 24036 KB n=100
15 Correct 12 ms 24020 KB n=100
16 Correct 15 ms 24044 KB n=100
17 Correct 13 ms 24020 KB n=100
18 Correct 13 ms 24012 KB n=100
19 Correct 14 ms 23948 KB n=100
20 Correct 14 ms 24040 KB n=100
21 Correct 14 ms 24032 KB n=100
22 Correct 16 ms 24020 KB n=100
23 Correct 15 ms 23960 KB n=100
24 Correct 15 ms 24020 KB n=100
25 Correct 14 ms 23988 KB n=100
26 Correct 13 ms 23972 KB n=12
27 Correct 14 ms 24040 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 12 ms 24020 KB n=5
2 Correct 14 ms 24020 KB n=100
3 Correct 13 ms 24044 KB n=100
4 Correct 13 ms 24020 KB n=100
5 Correct 13 ms 24020 KB n=100
6 Correct 14 ms 24020 KB n=100
7 Correct 14 ms 24020 KB n=100
8 Correct 14 ms 24028 KB n=100
9 Correct 13 ms 24020 KB n=100
10 Correct 14 ms 24020 KB n=100
11 Correct 12 ms 24060 KB n=100
12 Correct 14 ms 23972 KB n=100
13 Correct 13 ms 24024 KB n=100
14 Correct 13 ms 24036 KB n=100
15 Correct 12 ms 24020 KB n=100
16 Correct 15 ms 24044 KB n=100
17 Correct 13 ms 24020 KB n=100
18 Correct 13 ms 24012 KB n=100
19 Correct 14 ms 23948 KB n=100
20 Correct 14 ms 24040 KB n=100
21 Correct 14 ms 24032 KB n=100
22 Correct 16 ms 24020 KB n=100
23 Correct 15 ms 23960 KB n=100
24 Correct 15 ms 24020 KB n=100
25 Correct 14 ms 23988 KB n=100
26 Correct 13 ms 23972 KB n=12
27 Correct 14 ms 24040 KB n=100
28 Correct 14 ms 24092 KB n=500
29 Correct 14 ms 24148 KB n=500
30 Correct 14 ms 24148 KB n=500
31 Correct 13 ms 24176 KB n=500
32 Correct 14 ms 24040 KB n=500
33 Correct 14 ms 24064 KB n=500
34 Correct 13 ms 24040 KB n=500
35 Correct 14 ms 24148 KB n=500
36 Correct 14 ms 24120 KB n=500
37 Correct 13 ms 24080 KB n=500
38 Correct 15 ms 24084 KB n=500
39 Correct 15 ms 24052 KB n=500
40 Correct 15 ms 24148 KB n=500
41 Correct 14 ms 24104 KB n=500
42 Correct 16 ms 24100 KB n=500
43 Correct 14 ms 24044 KB n=500
44 Correct 16 ms 24172 KB n=500
45 Correct 15 ms 24148 KB n=500
46 Correct 13 ms 24180 KB n=500
47 Correct 14 ms 24148 KB n=500
48 Correct 13 ms 24112 KB n=500
49 Correct 13 ms 24148 KB n=500
50 Correct 14 ms 24068 KB n=500
51 Correct 14 ms 24148 KB n=500
52 Correct 15 ms 24148 KB n=500
53 Correct 15 ms 24108 KB n=500
54 Correct 14 ms 24148 KB n=500
55 Correct 13 ms 24020 KB n=278
56 Correct 13 ms 24148 KB n=500
57 Correct 13 ms 24148 KB n=500
58 Correct 13 ms 24080 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 12 ms 24020 KB n=5
2 Correct 14 ms 24020 KB n=100
3 Correct 13 ms 24044 KB n=100
4 Correct 13 ms 24020 KB n=100
5 Correct 13 ms 24020 KB n=100
6 Correct 14 ms 24020 KB n=100
7 Correct 14 ms 24020 KB n=100
8 Correct 14 ms 24028 KB n=100
9 Correct 13 ms 24020 KB n=100
10 Correct 14 ms 24020 KB n=100
11 Correct 12 ms 24060 KB n=100
12 Correct 14 ms 23972 KB n=100
13 Correct 13 ms 24024 KB n=100
14 Correct 13 ms 24036 KB n=100
15 Correct 12 ms 24020 KB n=100
16 Correct 15 ms 24044 KB n=100
17 Correct 13 ms 24020 KB n=100
18 Correct 13 ms 24012 KB n=100
19 Correct 14 ms 23948 KB n=100
20 Correct 14 ms 24040 KB n=100
21 Correct 14 ms 24032 KB n=100
22 Correct 16 ms 24020 KB n=100
23 Correct 15 ms 23960 KB n=100
24 Correct 15 ms 24020 KB n=100
25 Correct 14 ms 23988 KB n=100
26 Correct 13 ms 23972 KB n=12
27 Correct 14 ms 24040 KB n=100
28 Correct 14 ms 24092 KB n=500
29 Correct 14 ms 24148 KB n=500
30 Correct 14 ms 24148 KB n=500
31 Correct 13 ms 24176 KB n=500
32 Correct 14 ms 24040 KB n=500
33 Correct 14 ms 24064 KB n=500
34 Correct 13 ms 24040 KB n=500
35 Correct 14 ms 24148 KB n=500
36 Correct 14 ms 24120 KB n=500
37 Correct 13 ms 24080 KB n=500
38 Correct 15 ms 24084 KB n=500
39 Correct 15 ms 24052 KB n=500
40 Correct 15 ms 24148 KB n=500
41 Correct 14 ms 24104 KB n=500
42 Correct 16 ms 24100 KB n=500
43 Correct 14 ms 24044 KB n=500
44 Correct 16 ms 24172 KB n=500
45 Correct 15 ms 24148 KB n=500
46 Correct 13 ms 24180 KB n=500
47 Correct 14 ms 24148 KB n=500
48 Correct 13 ms 24112 KB n=500
49 Correct 13 ms 24148 KB n=500
50 Correct 14 ms 24068 KB n=500
51 Correct 14 ms 24148 KB n=500
52 Correct 15 ms 24148 KB n=500
53 Correct 15 ms 24108 KB n=500
54 Correct 14 ms 24148 KB n=500
55 Correct 13 ms 24020 KB n=278
56 Correct 13 ms 24148 KB n=500
57 Correct 13 ms 24148 KB n=500
58 Correct 13 ms 24080 KB n=500
59 Correct 17 ms 24432 KB n=2000
60 Correct 19 ms 24660 KB n=2000
61 Correct 19 ms 24560 KB n=2000
62 Correct 17 ms 24660 KB n=2000
63 Correct 17 ms 24532 KB n=2000
64 Correct 17 ms 24560 KB n=2000
65 Correct 17 ms 24432 KB n=2000
66 Correct 16 ms 24524 KB n=2000
67 Correct 16 ms 24532 KB n=2000
68 Correct 16 ms 24472 KB n=2000
69 Correct 15 ms 24544 KB n=2000
70 Correct 17 ms 24504 KB n=2000
71 Correct 16 ms 24432 KB n=2000
72 Correct 15 ms 24532 KB n=2000
73 Correct 17 ms 24508 KB n=2000
74 Correct 18 ms 24504 KB n=1844
75 Correct 16 ms 24532 KB n=2000
76 Correct 18 ms 24488 KB n=2000
77 Correct 22 ms 24432 KB n=2000
78 Correct 18 ms 24532 KB n=2000
79 Correct 17 ms 24532 KB n=2000
80 Correct 16 ms 24532 KB n=2000
81 Correct 16 ms 24556 KB n=2000
82 Correct 16 ms 24432 KB n=2000
83 Correct 16 ms 24592 KB n=2000
84 Correct 18 ms 24432 KB n=2000
85 Correct 18 ms 24524 KB n=2000
86 Correct 20 ms 24448 KB n=2000
87 Correct 19 ms 24436 KB n=2000
88 Correct 15 ms 24560 KB n=2000
89 Correct 15 ms 24532 KB n=2000
90 Correct 15 ms 24532 KB n=2000
91 Correct 19 ms 24432 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 12 ms 24020 KB n=5
2 Correct 14 ms 24020 KB n=100
3 Correct 13 ms 24044 KB n=100
4 Correct 13 ms 24020 KB n=100
5 Correct 13 ms 24020 KB n=100
6 Correct 14 ms 24020 KB n=100
7 Correct 14 ms 24020 KB n=100
8 Correct 14 ms 24028 KB n=100
9 Correct 13 ms 24020 KB n=100
10 Correct 14 ms 24020 KB n=100
11 Correct 12 ms 24060 KB n=100
12 Correct 14 ms 23972 KB n=100
13 Correct 13 ms 24024 KB n=100
14 Correct 13 ms 24036 KB n=100
15 Correct 12 ms 24020 KB n=100
16 Correct 15 ms 24044 KB n=100
17 Correct 13 ms 24020 KB n=100
18 Correct 13 ms 24012 KB n=100
19 Correct 14 ms 23948 KB n=100
20 Correct 14 ms 24040 KB n=100
21 Correct 14 ms 24032 KB n=100
22 Correct 16 ms 24020 KB n=100
23 Correct 15 ms 23960 KB n=100
24 Correct 15 ms 24020 KB n=100
25 Correct 14 ms 23988 KB n=100
26 Correct 13 ms 23972 KB n=12
27 Correct 14 ms 24040 KB n=100
28 Correct 14 ms 24092 KB n=500
29 Correct 14 ms 24148 KB n=500
30 Correct 14 ms 24148 KB n=500
31 Correct 13 ms 24176 KB n=500
32 Correct 14 ms 24040 KB n=500
33 Correct 14 ms 24064 KB n=500
34 Correct 13 ms 24040 KB n=500
35 Correct 14 ms 24148 KB n=500
36 Correct 14 ms 24120 KB n=500
37 Correct 13 ms 24080 KB n=500
38 Correct 15 ms 24084 KB n=500
39 Correct 15 ms 24052 KB n=500
40 Correct 15 ms 24148 KB n=500
41 Correct 14 ms 24104 KB n=500
42 Correct 16 ms 24100 KB n=500
43 Correct 14 ms 24044 KB n=500
44 Correct 16 ms 24172 KB n=500
45 Correct 15 ms 24148 KB n=500
46 Correct 13 ms 24180 KB n=500
47 Correct 14 ms 24148 KB n=500
48 Correct 13 ms 24112 KB n=500
49 Correct 13 ms 24148 KB n=500
50 Correct 14 ms 24068 KB n=500
51 Correct 14 ms 24148 KB n=500
52 Correct 15 ms 24148 KB n=500
53 Correct 15 ms 24108 KB n=500
54 Correct 14 ms 24148 KB n=500
55 Correct 13 ms 24020 KB n=278
56 Correct 13 ms 24148 KB n=500
57 Correct 13 ms 24148 KB n=500
58 Correct 13 ms 24080 KB n=500
59 Correct 17 ms 24432 KB n=2000
60 Correct 19 ms 24660 KB n=2000
61 Correct 19 ms 24560 KB n=2000
62 Correct 17 ms 24660 KB n=2000
63 Correct 17 ms 24532 KB n=2000
64 Correct 17 ms 24560 KB n=2000
65 Correct 17 ms 24432 KB n=2000
66 Correct 16 ms 24524 KB n=2000
67 Correct 16 ms 24532 KB n=2000
68 Correct 16 ms 24472 KB n=2000
69 Correct 15 ms 24544 KB n=2000
70 Correct 17 ms 24504 KB n=2000
71 Correct 16 ms 24432 KB n=2000
72 Correct 15 ms 24532 KB n=2000
73 Correct 17 ms 24508 KB n=2000
74 Correct 18 ms 24504 KB n=1844
75 Correct 16 ms 24532 KB n=2000
76 Correct 18 ms 24488 KB n=2000
77 Correct 22 ms 24432 KB n=2000
78 Correct 18 ms 24532 KB n=2000
79 Correct 17 ms 24532 KB n=2000
80 Correct 16 ms 24532 KB n=2000
81 Correct 16 ms 24556 KB n=2000
82 Correct 16 ms 24432 KB n=2000
83 Correct 16 ms 24592 KB n=2000
84 Correct 18 ms 24432 KB n=2000
85 Correct 18 ms 24524 KB n=2000
86 Correct 20 ms 24448 KB n=2000
87 Correct 19 ms 24436 KB n=2000
88 Correct 15 ms 24560 KB n=2000
89 Correct 15 ms 24532 KB n=2000
90 Correct 15 ms 24532 KB n=2000
91 Correct 19 ms 24432 KB n=2000
92 Correct 1532 ms 76200 KB n=200000
93 Correct 1051 ms 81176 KB n=200000
94 Correct 657 ms 84576 KB n=200000
95 Correct 1549 ms 76112 KB n=200000
96 Correct 1425 ms 76192 KB n=200000
97 Correct 1162 ms 80320 KB n=200000
98 Correct 1495 ms 76124 KB n=200000
99 Correct 1431 ms 76416 KB n=200000
100 Correct 1438 ms 76172 KB n=200000
101 Correct 514 ms 85760 KB n=200000
102 Correct 712 ms 77300 KB n=200000
103 Correct 694 ms 77216 KB n=200000
104 Correct 723 ms 77220 KB n=200000
105 Correct 734 ms 77708 KB n=200000
106 Correct 717 ms 77740 KB n=200000
107 Correct 737 ms 77680 KB n=200000
108 Correct 1442 ms 76180 KB n=200000
109 Correct 1407 ms 76180 KB n=200000
110 Correct 1407 ms 76184 KB n=200000
111 Correct 1283 ms 75668 KB n=200000
112 Correct 624 ms 84836 KB n=200000
113 Correct 1121 ms 80184 KB n=200000
114 Correct 1370 ms 75600 KB n=200000
115 Correct 1562 ms 78096 KB n=200000
116 Correct 1494 ms 76248 KB n=200000
117 Correct 576 ms 85160 KB n=200000
118 Correct 1312 ms 79148 KB n=200000
119 Correct 1524 ms 76364 KB n=200000
120 Correct 509 ms 84700 KB n=200000
121 Correct 508 ms 84752 KB n=200000
122 Correct 462 ms 85108 KB n=200000
123 Correct 806 ms 77424 KB n=200000
124 Correct 215 ms 39344 KB n=25264