# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
672973 | 2022-12-19T08:31:13 Z | ReLice | Birthday gift (IZhO18_treearray) | C++14 | 1629 ms | 113872 KB |
#include<bits/stdc++.h> using namespace std; #define endl "\n" #define ll long long #define ld long double #define int long long #define pb push_back #define sz size() #define fr first #define sc second void start(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } void fre(string n){freopen((n+".in").c_str(),"r",stdin);freopen((n+".out").c_str(),"w",stdin);} const ll N = 2e5 + 5 ; const ll inf=1e9+7; ll l,a,c=0; ll d[N]; vector <vector <ll>> up(N),g(N); void dfs(ll v,ll pr){ up[v][0]=pr; if(v!=a) { bool flag=false; for(ll i=1;i<=c;i++){ if(flag){ up[v][i]=0; continue; } up[v][i]=up[up[v][i-1]][i-1]; if(up[v][i]==0) flag =true; } } else { for(ll i=0;i<=c;i++){ up[v][i]=0; } } for(auto i : g[v]){ if(i==up[v][0]) continue; d[i]=d[v]+1; dfs(i,v); } } ll lca(ll v,ll u){ if(d[u]<d[v]) swap(u,v); ll i=c; while(d[u]>d[v] && i>=0){ if(d[up[u][i]]<d[v])i--; else { u=up[u][i]; i--; } } i=c; if(u==v) return u; while(i>=0){ if(up[u][i]==up[v][i]) {i--;} else { u=up[u][i]; v=up[v][i]; i--; } } return up[u][0]; } void solve(){ ll n,m,b,b1,k,i,q,j,mx=-1; cin>>n>>m>>q; l=1; vector <map<ll,ll>> mp(n+5); vector <ll> v; set<ll> ans[n+5],ans2[n+5]; while(l<n) {c++;l*=2;} for(i=1;i<=n;i++){ up[i].resize(c+2); } for(i=1;i<n;i++){ cin>>k>>b; g[b].pb(k); g[k].pb(b); } d[0]=-1; d[1]=0; a=1; dfs(1,0); v.pb(0); for(i=0;i<m;i++){ cin>>b; v.pb(b); } for(i=2;i<=m;i++){ b=lca(v[i],v[i-1]); ans2[b].insert(i-1); } for(i=1;i<=m;i++){ ans[v[i]].insert(i); } while(q--){ ll tp; cin>>tp; if(tp==1){ cin>>b>>b1; ans[v[b]].erase(b); ans[b1].insert(b); if(b>0){ ans2[lca(v[b],v[b-1])].erase(b-1); ans2[lca(b1,v[b-1])].insert(b-1); } if(b<m-1){ ans2[lca(v[b],v[b+1])].erase(b); ans2[lca(b1,v[b+1])].insert(b); } v[b]=b1; } else { cin>>b>>b1>>k; auto it = ans[k].lower_bound(b); auto it2 = ans2[k].lower_bound(b); if(*it <= b1 && it!=ans[k].end()) cout<<*it<<' '<<*it<<endl; else if(*it2 < b1 && it2!=ans2[k].end()) cout<<*it2<<' '<<*it2+1<<endl; else cout<<-1<<' '<<-1<<endl; } } } main(){ //fre(""); start(); ll t=1; //cin>>t; while(t--)solve(); } /* 5 4 4 1 2 3 1 3 4 5 3 4 5 2 3 2 1 3 1 1 3 5 2 3 4 5 2 1 3 1 */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 9684 KB | n=5 |
2 | Correct | 6 ms | 9672 KB | n=100 |
3 | Correct | 5 ms | 9672 KB | n=100 |
4 | Correct | 7 ms | 9768 KB | n=100 |
5 | Correct | 5 ms | 9684 KB | n=100 |
6 | Correct | 5 ms | 9684 KB | n=100 |
7 | Correct | 5 ms | 9684 KB | n=100 |
8 | Correct | 5 ms | 9684 KB | n=100 |
9 | Correct | 5 ms | 9736 KB | n=100 |
10 | Correct | 5 ms | 9740 KB | n=100 |
11 | Correct | 5 ms | 9684 KB | n=100 |
12 | Correct | 6 ms | 9732 KB | n=100 |
13 | Correct | 5 ms | 9684 KB | n=100 |
14 | Correct | 6 ms | 9772 KB | n=100 |
15 | Correct | 6 ms | 9684 KB | n=100 |
16 | Correct | 6 ms | 9736 KB | n=100 |
17 | Correct | 5 ms | 9684 KB | n=100 |
18 | Correct | 5 ms | 9732 KB | n=100 |
19 | Correct | 5 ms | 9736 KB | n=100 |
20 | Correct | 5 ms | 9684 KB | n=100 |
21 | Correct | 5 ms | 9648 KB | n=100 |
22 | Correct | 6 ms | 9684 KB | n=100 |
23 | Correct | 5 ms | 9684 KB | n=100 |
24 | Correct | 6 ms | 9684 KB | n=100 |
25 | Correct | 7 ms | 9684 KB | n=100 |
26 | Correct | 5 ms | 9684 KB | n=12 |
27 | Correct | 6 ms | 9684 KB | n=100 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 9684 KB | n=5 |
2 | Correct | 6 ms | 9672 KB | n=100 |
3 | Correct | 5 ms | 9672 KB | n=100 |
4 | Correct | 7 ms | 9768 KB | n=100 |
5 | Correct | 5 ms | 9684 KB | n=100 |
6 | Correct | 5 ms | 9684 KB | n=100 |
7 | Correct | 5 ms | 9684 KB | n=100 |
8 | Correct | 5 ms | 9684 KB | n=100 |
9 | Correct | 5 ms | 9736 KB | n=100 |
10 | Correct | 5 ms | 9740 KB | n=100 |
11 | Correct | 5 ms | 9684 KB | n=100 |
12 | Correct | 6 ms | 9732 KB | n=100 |
13 | Correct | 5 ms | 9684 KB | n=100 |
14 | Correct | 6 ms | 9772 KB | n=100 |
15 | Correct | 6 ms | 9684 KB | n=100 |
16 | Correct | 6 ms | 9736 KB | n=100 |
17 | Correct | 5 ms | 9684 KB | n=100 |
18 | Correct | 5 ms | 9732 KB | n=100 |
19 | Correct | 5 ms | 9736 KB | n=100 |
20 | Correct | 5 ms | 9684 KB | n=100 |
21 | Correct | 5 ms | 9648 KB | n=100 |
22 | Correct | 6 ms | 9684 KB | n=100 |
23 | Correct | 5 ms | 9684 KB | n=100 |
24 | Correct | 6 ms | 9684 KB | n=100 |
25 | Correct | 7 ms | 9684 KB | n=100 |
26 | Correct | 5 ms | 9684 KB | n=12 |
27 | Correct | 6 ms | 9684 KB | n=100 |
28 | Correct | 6 ms | 9812 KB | n=500 |
29 | Correct | 5 ms | 9940 KB | n=500 |
30 | Correct | 6 ms | 9880 KB | n=500 |
31 | Correct | 6 ms | 9872 KB | n=500 |
32 | Correct | 8 ms | 9812 KB | n=500 |
33 | Correct | 8 ms | 9940 KB | n=500 |
34 | Correct | 6 ms | 9812 KB | n=500 |
35 | Correct | 7 ms | 9940 KB | n=500 |
36 | Correct | 6 ms | 9812 KB | n=500 |
37 | Correct | 5 ms | 9872 KB | n=500 |
38 | Correct | 6 ms | 9832 KB | n=500 |
39 | Correct | 7 ms | 9880 KB | n=500 |
40 | Correct | 7 ms | 9940 KB | n=500 |
41 | Correct | 7 ms | 9824 KB | n=500 |
42 | Correct | 6 ms | 9940 KB | n=500 |
43 | Correct | 7 ms | 9872 KB | n=500 |
44 | Correct | 6 ms | 9868 KB | n=500 |
45 | Correct | 5 ms | 9812 KB | n=500 |
46 | Correct | 5 ms | 9940 KB | n=500 |
47 | Correct | 6 ms | 9940 KB | n=500 |
48 | Correct | 6 ms | 9812 KB | n=500 |
49 | Correct | 7 ms | 9940 KB | n=500 |
50 | Correct | 5 ms | 9812 KB | n=500 |
51 | Correct | 6 ms | 9940 KB | n=500 |
52 | Correct | 7 ms | 9872 KB | n=500 |
53 | Correct | 6 ms | 9940 KB | n=500 |
54 | Correct | 5 ms | 9940 KB | n=500 |
55 | Correct | 5 ms | 9868 KB | n=278 |
56 | Correct | 8 ms | 9940 KB | n=500 |
57 | Correct | 6 ms | 9864 KB | n=500 |
58 | Correct | 7 ms | 9984 KB | n=500 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 9684 KB | n=5 |
2 | Correct | 6 ms | 9672 KB | n=100 |
3 | Correct | 5 ms | 9672 KB | n=100 |
4 | Correct | 7 ms | 9768 KB | n=100 |
5 | Correct | 5 ms | 9684 KB | n=100 |
6 | Correct | 5 ms | 9684 KB | n=100 |
7 | Correct | 5 ms | 9684 KB | n=100 |
8 | Correct | 5 ms | 9684 KB | n=100 |
9 | Correct | 5 ms | 9736 KB | n=100 |
10 | Correct | 5 ms | 9740 KB | n=100 |
11 | Correct | 5 ms | 9684 KB | n=100 |
12 | Correct | 6 ms | 9732 KB | n=100 |
13 | Correct | 5 ms | 9684 KB | n=100 |
14 | Correct | 6 ms | 9772 KB | n=100 |
15 | Correct | 6 ms | 9684 KB | n=100 |
16 | Correct | 6 ms | 9736 KB | n=100 |
17 | Correct | 5 ms | 9684 KB | n=100 |
18 | Correct | 5 ms | 9732 KB | n=100 |
19 | Correct | 5 ms | 9736 KB | n=100 |
20 | Correct | 5 ms | 9684 KB | n=100 |
21 | Correct | 5 ms | 9648 KB | n=100 |
22 | Correct | 6 ms | 9684 KB | n=100 |
23 | Correct | 5 ms | 9684 KB | n=100 |
24 | Correct | 6 ms | 9684 KB | n=100 |
25 | Correct | 7 ms | 9684 KB | n=100 |
26 | Correct | 5 ms | 9684 KB | n=12 |
27 | Correct | 6 ms | 9684 KB | n=100 |
28 | Correct | 6 ms | 9812 KB | n=500 |
29 | Correct | 5 ms | 9940 KB | n=500 |
30 | Correct | 6 ms | 9880 KB | n=500 |
31 | Correct | 6 ms | 9872 KB | n=500 |
32 | Correct | 8 ms | 9812 KB | n=500 |
33 | Correct | 8 ms | 9940 KB | n=500 |
34 | Correct | 6 ms | 9812 KB | n=500 |
35 | Correct | 7 ms | 9940 KB | n=500 |
36 | Correct | 6 ms | 9812 KB | n=500 |
37 | Correct | 5 ms | 9872 KB | n=500 |
38 | Correct | 6 ms | 9832 KB | n=500 |
39 | Correct | 7 ms | 9880 KB | n=500 |
40 | Correct | 7 ms | 9940 KB | n=500 |
41 | Correct | 7 ms | 9824 KB | n=500 |
42 | Correct | 6 ms | 9940 KB | n=500 |
43 | Correct | 7 ms | 9872 KB | n=500 |
44 | Correct | 6 ms | 9868 KB | n=500 |
45 | Correct | 5 ms | 9812 KB | n=500 |
46 | Correct | 5 ms | 9940 KB | n=500 |
47 | Correct | 6 ms | 9940 KB | n=500 |
48 | Correct | 6 ms | 9812 KB | n=500 |
49 | Correct | 7 ms | 9940 KB | n=500 |
50 | Correct | 5 ms | 9812 KB | n=500 |
51 | Correct | 6 ms | 9940 KB | n=500 |
52 | Correct | 7 ms | 9872 KB | n=500 |
53 | Correct | 6 ms | 9940 KB | n=500 |
54 | Correct | 5 ms | 9940 KB | n=500 |
55 | Correct | 5 ms | 9868 KB | n=278 |
56 | Correct | 8 ms | 9940 KB | n=500 |
57 | Correct | 6 ms | 9864 KB | n=500 |
58 | Correct | 7 ms | 9984 KB | n=500 |
59 | Correct | 8 ms | 10580 KB | n=2000 |
60 | Correct | 8 ms | 10640 KB | n=2000 |
61 | Correct | 8 ms | 10560 KB | n=2000 |
62 | Correct | 8 ms | 10516 KB | n=2000 |
63 | Correct | 7 ms | 10580 KB | n=2000 |
64 | Correct | 8 ms | 10632 KB | n=2000 |
65 | Correct | 8 ms | 10548 KB | n=2000 |
66 | Correct | 9 ms | 10656 KB | n=2000 |
67 | Correct | 10 ms | 10580 KB | n=2000 |
68 | Correct | 10 ms | 10580 KB | n=2000 |
69 | Correct | 7 ms | 10580 KB | n=2000 |
70 | Correct | 7 ms | 10580 KB | n=2000 |
71 | Correct | 7 ms | 10580 KB | n=2000 |
72 | Correct | 7 ms | 10580 KB | n=2000 |
73 | Correct | 7 ms | 10580 KB | n=2000 |
74 | Correct | 8 ms | 10516 KB | n=1844 |
75 | Correct | 7 ms | 10580 KB | n=2000 |
76 | Correct | 9 ms | 10520 KB | n=2000 |
77 | Correct | 8 ms | 10580 KB | n=2000 |
78 | Correct | 8 ms | 10580 KB | n=2000 |
79 | Correct | 8 ms | 10484 KB | n=2000 |
80 | Correct | 8 ms | 10584 KB | n=2000 |
81 | Correct | 9 ms | 10512 KB | n=2000 |
82 | Correct | 9 ms | 10580 KB | n=2000 |
83 | Correct | 8 ms | 10636 KB | n=2000 |
84 | Correct | 8 ms | 10512 KB | n=2000 |
85 | Correct | 11 ms | 10512 KB | n=2000 |
86 | Correct | 9 ms | 10580 KB | n=2000 |
87 | Correct | 8 ms | 10580 KB | n=2000 |
88 | Correct | 9 ms | 10588 KB | n=2000 |
89 | Correct | 8 ms | 10580 KB | n=2000 |
90 | Correct | 8 ms | 10580 KB | n=2000 |
91 | Correct | 8 ms | 10512 KB | n=2000 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 9684 KB | n=5 |
2 | Correct | 6 ms | 9672 KB | n=100 |
3 | Correct | 5 ms | 9672 KB | n=100 |
4 | Correct | 7 ms | 9768 KB | n=100 |
5 | Correct | 5 ms | 9684 KB | n=100 |
6 | Correct | 5 ms | 9684 KB | n=100 |
7 | Correct | 5 ms | 9684 KB | n=100 |
8 | Correct | 5 ms | 9684 KB | n=100 |
9 | Correct | 5 ms | 9736 KB | n=100 |
10 | Correct | 5 ms | 9740 KB | n=100 |
11 | Correct | 5 ms | 9684 KB | n=100 |
12 | Correct | 6 ms | 9732 KB | n=100 |
13 | Correct | 5 ms | 9684 KB | n=100 |
14 | Correct | 6 ms | 9772 KB | n=100 |
15 | Correct | 6 ms | 9684 KB | n=100 |
16 | Correct | 6 ms | 9736 KB | n=100 |
17 | Correct | 5 ms | 9684 KB | n=100 |
18 | Correct | 5 ms | 9732 KB | n=100 |
19 | Correct | 5 ms | 9736 KB | n=100 |
20 | Correct | 5 ms | 9684 KB | n=100 |
21 | Correct | 5 ms | 9648 KB | n=100 |
22 | Correct | 6 ms | 9684 KB | n=100 |
23 | Correct | 5 ms | 9684 KB | n=100 |
24 | Correct | 6 ms | 9684 KB | n=100 |
25 | Correct | 7 ms | 9684 KB | n=100 |
26 | Correct | 5 ms | 9684 KB | n=12 |
27 | Correct | 6 ms | 9684 KB | n=100 |
28 | Correct | 6 ms | 9812 KB | n=500 |
29 | Correct | 5 ms | 9940 KB | n=500 |
30 | Correct | 6 ms | 9880 KB | n=500 |
31 | Correct | 6 ms | 9872 KB | n=500 |
32 | Correct | 8 ms | 9812 KB | n=500 |
33 | Correct | 8 ms | 9940 KB | n=500 |
34 | Correct | 6 ms | 9812 KB | n=500 |
35 | Correct | 7 ms | 9940 KB | n=500 |
36 | Correct | 6 ms | 9812 KB | n=500 |
37 | Correct | 5 ms | 9872 KB | n=500 |
38 | Correct | 6 ms | 9832 KB | n=500 |
39 | Correct | 7 ms | 9880 KB | n=500 |
40 | Correct | 7 ms | 9940 KB | n=500 |
41 | Correct | 7 ms | 9824 KB | n=500 |
42 | Correct | 6 ms | 9940 KB | n=500 |
43 | Correct | 7 ms | 9872 KB | n=500 |
44 | Correct | 6 ms | 9868 KB | n=500 |
45 | Correct | 5 ms | 9812 KB | n=500 |
46 | Correct | 5 ms | 9940 KB | n=500 |
47 | Correct | 6 ms | 9940 KB | n=500 |
48 | Correct | 6 ms | 9812 KB | n=500 |
49 | Correct | 7 ms | 9940 KB | n=500 |
50 | Correct | 5 ms | 9812 KB | n=500 |
51 | Correct | 6 ms | 9940 KB | n=500 |
52 | Correct | 7 ms | 9872 KB | n=500 |
53 | Correct | 6 ms | 9940 KB | n=500 |
54 | Correct | 5 ms | 9940 KB | n=500 |
55 | Correct | 5 ms | 9868 KB | n=278 |
56 | Correct | 8 ms | 9940 KB | n=500 |
57 | Correct | 6 ms | 9864 KB | n=500 |
58 | Correct | 7 ms | 9984 KB | n=500 |
59 | Correct | 8 ms | 10580 KB | n=2000 |
60 | Correct | 8 ms | 10640 KB | n=2000 |
61 | Correct | 8 ms | 10560 KB | n=2000 |
62 | Correct | 8 ms | 10516 KB | n=2000 |
63 | Correct | 7 ms | 10580 KB | n=2000 |
64 | Correct | 8 ms | 10632 KB | n=2000 |
65 | Correct | 8 ms | 10548 KB | n=2000 |
66 | Correct | 9 ms | 10656 KB | n=2000 |
67 | Correct | 10 ms | 10580 KB | n=2000 |
68 | Correct | 10 ms | 10580 KB | n=2000 |
69 | Correct | 7 ms | 10580 KB | n=2000 |
70 | Correct | 7 ms | 10580 KB | n=2000 |
71 | Correct | 7 ms | 10580 KB | n=2000 |
72 | Correct | 7 ms | 10580 KB | n=2000 |
73 | Correct | 7 ms | 10580 KB | n=2000 |
74 | Correct | 8 ms | 10516 KB | n=1844 |
75 | Correct | 7 ms | 10580 KB | n=2000 |
76 | Correct | 9 ms | 10520 KB | n=2000 |
77 | Correct | 8 ms | 10580 KB | n=2000 |
78 | Correct | 8 ms | 10580 KB | n=2000 |
79 | Correct | 8 ms | 10484 KB | n=2000 |
80 | Correct | 8 ms | 10584 KB | n=2000 |
81 | Correct | 9 ms | 10512 KB | n=2000 |
82 | Correct | 9 ms | 10580 KB | n=2000 |
83 | Correct | 8 ms | 10636 KB | n=2000 |
84 | Correct | 8 ms | 10512 KB | n=2000 |
85 | Correct | 11 ms | 10512 KB | n=2000 |
86 | Correct | 9 ms | 10580 KB | n=2000 |
87 | Correct | 8 ms | 10580 KB | n=2000 |
88 | Correct | 9 ms | 10588 KB | n=2000 |
89 | Correct | 8 ms | 10580 KB | n=2000 |
90 | Correct | 8 ms | 10580 KB | n=2000 |
91 | Correct | 8 ms | 10512 KB | n=2000 |
92 | Correct | 666 ms | 106228 KB | n=200000 |
93 | Correct | 1479 ms | 110056 KB | n=200000 |
94 | Correct | 1406 ms | 112940 KB | n=200000 |
95 | Correct | 686 ms | 106212 KB | n=200000 |
96 | Correct | 688 ms | 106192 KB | n=200000 |
97 | Correct | 1516 ms | 109112 KB | n=200000 |
98 | Correct | 707 ms | 106196 KB | n=200000 |
99 | Correct | 1032 ms | 105868 KB | n=200000 |
100 | Correct | 695 ms | 106164 KB | n=200000 |
101 | Correct | 1381 ms | 113852 KB | n=200000 |
102 | Correct | 478 ms | 107300 KB | n=200000 |
103 | Correct | 531 ms | 107236 KB | n=200000 |
104 | Correct | 476 ms | 107236 KB | n=200000 |
105 | Correct | 524 ms | 107020 KB | n=200000 |
106 | Correct | 453 ms | 107048 KB | n=200000 |
107 | Correct | 477 ms | 107076 KB | n=200000 |
108 | Correct | 911 ms | 106036 KB | n=200000 |
109 | Correct | 865 ms | 106080 KB | n=200000 |
110 | Correct | 840 ms | 106068 KB | n=200000 |
111 | Correct | 703 ms | 106000 KB | n=200000 |
112 | Correct | 1441 ms | 113108 KB | n=200000 |
113 | Correct | 1408 ms | 109064 KB | n=200000 |
114 | Correct | 711 ms | 106060 KB | n=200000 |
115 | Correct | 1629 ms | 107248 KB | n=200000 |
116 | Correct | 666 ms | 105996 KB | n=200000 |
117 | Correct | 1409 ms | 113204 KB | n=200000 |
118 | Correct | 1491 ms | 108028 KB | n=200000 |
119 | Correct | 652 ms | 105860 KB | n=200000 |
120 | Correct | 1399 ms | 113356 KB | n=200000 |
121 | Correct | 1348 ms | 113448 KB | n=200000 |
122 | Correct | 1317 ms | 113872 KB | n=200000 |
123 | Correct | 478 ms | 106692 KB | n=200000 |
124 | Correct | 230 ms | 29448 KB | n=25264 |