# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
542384 | 2022-03-26T10:31:42 Z | krit3379 | Birthday gift (IZhO18_treearray) | C++17 | 1107 ms | 77592 KB |
#include<bits/stdc++.h> using namespace std; #define N 200005 int dep[N],bp[20][N],val[N]; vector<int> g[N]; set<int> s[N],ss[N]; void dfs(int s,int f){ dep[s]=dep[f]+1; bp[0][s]=f; for(auto x:g[s])if(x!=f)dfs(x,s); } int lca(int a,int b){ if(dep[a]>dep[b])swap(a,b); int i,dif=dep[b]-dep[a]; for(i=0;i<20;i++)if(dif&(1<<i))b=bp[i][b]; if(a==b)return a; for(i=19;i>=0;i--)if(bp[i][a]!=bp[i][b]){ a=bp[i][a]; b=bp[i][b]; } return bp[0][a]; } int main(){ int n,m,q,i,j,a,b,op,pos,v,l,r; scanf("%d %d %d",&n,&m,&q); for(i=1;i<n;i++){ scanf("%d %d",&a,&b); g[a].push_back(b); g[b].push_back(a); } for(i=1;i<=m;i++)scanf("%d",&val[i]),s[val[i]].insert(i); dfs(1,1); for(i=1;i<20;i++)for(j=1;j<=n;j++)bp[i][j]=bp[i-1][bp[i-1][j]]; for(i=1;i<m;i++)ss[lca(val[i],val[i+1])].insert(i); while(q--){ scanf("%d",&op); if(op==1){ scanf("%d %d",&pos,&v); s[val[pos]].erase(pos); s[v].insert(pos); if(pos>1){ ss[lca(val[pos],val[pos-1])].erase(pos-1); ss[lca(v,val[pos-1])].insert(pos-1); } if(pos<m){ ss[lca(val[pos],val[pos+1])].erase(pos); ss[lca(v,val[pos+1])].insert(pos); } val[pos]=v; } else{ scanf("%d %d %d",&l,&r,&v); auto it1=s[v].lower_bound(l),it2=ss[v].lower_bound(l); if(it1!=s[v].end()&&*it1<=r)printf("%d %d\n",*it1,*it1); else if(it2!=ss[v].end()&&*it2<r)printf("%d %d\n",*it2,*it2+1); else printf("-1 -1\n"); } } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 23796 KB | n=5 |
2 | Correct | 13 ms | 23892 KB | n=100 |
3 | Correct | 13 ms | 23924 KB | n=100 |
4 | Correct | 13 ms | 23892 KB | n=100 |
5 | Correct | 13 ms | 23892 KB | n=100 |
6 | Correct | 13 ms | 23812 KB | n=100 |
7 | Correct | 12 ms | 23916 KB | n=100 |
8 | Correct | 12 ms | 23868 KB | n=100 |
9 | Correct | 14 ms | 23892 KB | n=100 |
10 | Correct | 14 ms | 23892 KB | n=100 |
11 | Correct | 13 ms | 23892 KB | n=100 |
12 | Correct | 14 ms | 23892 KB | n=100 |
13 | Correct | 14 ms | 23920 KB | n=100 |
14 | Correct | 14 ms | 23892 KB | n=100 |
15 | Correct | 12 ms | 23892 KB | n=100 |
16 | Correct | 12 ms | 23892 KB | n=100 |
17 | Correct | 14 ms | 23892 KB | n=100 |
18 | Correct | 13 ms | 23848 KB | n=100 |
19 | Correct | 13 ms | 23892 KB | n=100 |
20 | Correct | 25 ms | 23876 KB | n=100 |
21 | Correct | 14 ms | 23892 KB | n=100 |
22 | Correct | 13 ms | 23892 KB | n=100 |
23 | Correct | 12 ms | 23920 KB | n=100 |
24 | Correct | 13 ms | 23892 KB | n=100 |
25 | Correct | 25 ms | 23860 KB | n=100 |
26 | Correct | 13 ms | 23852 KB | n=12 |
27 | Correct | 14 ms | 23892 KB | n=100 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 23796 KB | n=5 |
2 | Correct | 13 ms | 23892 KB | n=100 |
3 | Correct | 13 ms | 23924 KB | n=100 |
4 | Correct | 13 ms | 23892 KB | n=100 |
5 | Correct | 13 ms | 23892 KB | n=100 |
6 | Correct | 13 ms | 23812 KB | n=100 |
7 | Correct | 12 ms | 23916 KB | n=100 |
8 | Correct | 12 ms | 23868 KB | n=100 |
9 | Correct | 14 ms | 23892 KB | n=100 |
10 | Correct | 14 ms | 23892 KB | n=100 |
11 | Correct | 13 ms | 23892 KB | n=100 |
12 | Correct | 14 ms | 23892 KB | n=100 |
13 | Correct | 14 ms | 23920 KB | n=100 |
14 | Correct | 14 ms | 23892 KB | n=100 |
15 | Correct | 12 ms | 23892 KB | n=100 |
16 | Correct | 12 ms | 23892 KB | n=100 |
17 | Correct | 14 ms | 23892 KB | n=100 |
18 | Correct | 13 ms | 23848 KB | n=100 |
19 | Correct | 13 ms | 23892 KB | n=100 |
20 | Correct | 25 ms | 23876 KB | n=100 |
21 | Correct | 14 ms | 23892 KB | n=100 |
22 | Correct | 13 ms | 23892 KB | n=100 |
23 | Correct | 12 ms | 23920 KB | n=100 |
24 | Correct | 13 ms | 23892 KB | n=100 |
25 | Correct | 25 ms | 23860 KB | n=100 |
26 | Correct | 13 ms | 23852 KB | n=12 |
27 | Correct | 14 ms | 23892 KB | n=100 |
28 | Correct | 12 ms | 24000 KB | n=500 |
29 | Correct | 12 ms | 24020 KB | n=500 |
30 | Correct | 23 ms | 23932 KB | n=500 |
31 | Correct | 14 ms | 24020 KB | n=500 |
32 | Correct | 12 ms | 24020 KB | n=500 |
33 | Correct | 15 ms | 23932 KB | n=500 |
34 | Correct | 14 ms | 23932 KB | n=500 |
35 | Correct | 14 ms | 24020 KB | n=500 |
36 | Correct | 20 ms | 23976 KB | n=500 |
37 | Correct | 13 ms | 23936 KB | n=500 |
38 | Correct | 13 ms | 23912 KB | n=500 |
39 | Correct | 15 ms | 24020 KB | n=500 |
40 | Correct | 13 ms | 24032 KB | n=500 |
41 | Correct | 14 ms | 23920 KB | n=500 |
42 | Correct | 13 ms | 23928 KB | n=500 |
43 | Correct | 13 ms | 23932 KB | n=500 |
44 | Correct | 13 ms | 24020 KB | n=500 |
45 | Correct | 25 ms | 24020 KB | n=500 |
46 | Correct | 13 ms | 24020 KB | n=500 |
47 | Correct | 14 ms | 23984 KB | n=500 |
48 | Correct | 14 ms | 24020 KB | n=500 |
49 | Correct | 14 ms | 24020 KB | n=500 |
50 | Correct | 13 ms | 24020 KB | n=500 |
51 | Correct | 13 ms | 23940 KB | n=500 |
52 | Correct | 13 ms | 24020 KB | n=500 |
53 | Correct | 16 ms | 24020 KB | n=500 |
54 | Correct | 15 ms | 24020 KB | n=500 |
55 | Correct | 13 ms | 23916 KB | n=278 |
56 | Correct | 14 ms | 23928 KB | n=500 |
57 | Correct | 14 ms | 24028 KB | n=500 |
58 | Correct | 13 ms | 24020 KB | n=500 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 23796 KB | n=5 |
2 | Correct | 13 ms | 23892 KB | n=100 |
3 | Correct | 13 ms | 23924 KB | n=100 |
4 | Correct | 13 ms | 23892 KB | n=100 |
5 | Correct | 13 ms | 23892 KB | n=100 |
6 | Correct | 13 ms | 23812 KB | n=100 |
7 | Correct | 12 ms | 23916 KB | n=100 |
8 | Correct | 12 ms | 23868 KB | n=100 |
9 | Correct | 14 ms | 23892 KB | n=100 |
10 | Correct | 14 ms | 23892 KB | n=100 |
11 | Correct | 13 ms | 23892 KB | n=100 |
12 | Correct | 14 ms | 23892 KB | n=100 |
13 | Correct | 14 ms | 23920 KB | n=100 |
14 | Correct | 14 ms | 23892 KB | n=100 |
15 | Correct | 12 ms | 23892 KB | n=100 |
16 | Correct | 12 ms | 23892 KB | n=100 |
17 | Correct | 14 ms | 23892 KB | n=100 |
18 | Correct | 13 ms | 23848 KB | n=100 |
19 | Correct | 13 ms | 23892 KB | n=100 |
20 | Correct | 25 ms | 23876 KB | n=100 |
21 | Correct | 14 ms | 23892 KB | n=100 |
22 | Correct | 13 ms | 23892 KB | n=100 |
23 | Correct | 12 ms | 23920 KB | n=100 |
24 | Correct | 13 ms | 23892 KB | n=100 |
25 | Correct | 25 ms | 23860 KB | n=100 |
26 | Correct | 13 ms | 23852 KB | n=12 |
27 | Correct | 14 ms | 23892 KB | n=100 |
28 | Correct | 12 ms | 24000 KB | n=500 |
29 | Correct | 12 ms | 24020 KB | n=500 |
30 | Correct | 23 ms | 23932 KB | n=500 |
31 | Correct | 14 ms | 24020 KB | n=500 |
32 | Correct | 12 ms | 24020 KB | n=500 |
33 | Correct | 15 ms | 23932 KB | n=500 |
34 | Correct | 14 ms | 23932 KB | n=500 |
35 | Correct | 14 ms | 24020 KB | n=500 |
36 | Correct | 20 ms | 23976 KB | n=500 |
37 | Correct | 13 ms | 23936 KB | n=500 |
38 | Correct | 13 ms | 23912 KB | n=500 |
39 | Correct | 15 ms | 24020 KB | n=500 |
40 | Correct | 13 ms | 24032 KB | n=500 |
41 | Correct | 14 ms | 23920 KB | n=500 |
42 | Correct | 13 ms | 23928 KB | n=500 |
43 | Correct | 13 ms | 23932 KB | n=500 |
44 | Correct | 13 ms | 24020 KB | n=500 |
45 | Correct | 25 ms | 24020 KB | n=500 |
46 | Correct | 13 ms | 24020 KB | n=500 |
47 | Correct | 14 ms | 23984 KB | n=500 |
48 | Correct | 14 ms | 24020 KB | n=500 |
49 | Correct | 14 ms | 24020 KB | n=500 |
50 | Correct | 13 ms | 24020 KB | n=500 |
51 | Correct | 13 ms | 23940 KB | n=500 |
52 | Correct | 13 ms | 24020 KB | n=500 |
53 | Correct | 16 ms | 24020 KB | n=500 |
54 | Correct | 15 ms | 24020 KB | n=500 |
55 | Correct | 13 ms | 23916 KB | n=278 |
56 | Correct | 14 ms | 23928 KB | n=500 |
57 | Correct | 14 ms | 24028 KB | n=500 |
58 | Correct | 13 ms | 24020 KB | n=500 |
59 | Correct | 16 ms | 24332 KB | n=2000 |
60 | Correct | 15 ms | 24412 KB | n=2000 |
61 | Correct | 17 ms | 24412 KB | n=2000 |
62 | Correct | 16 ms | 24404 KB | n=2000 |
63 | Correct | 15 ms | 24284 KB | n=2000 |
64 | Correct | 31 ms | 24408 KB | n=2000 |
65 | Correct | 16 ms | 24328 KB | n=2000 |
66 | Correct | 16 ms | 24448 KB | n=2000 |
67 | Correct | 23 ms | 24280 KB | n=2000 |
68 | Correct | 16 ms | 24324 KB | n=2000 |
69 | Correct | 15 ms | 24360 KB | n=2000 |
70 | Correct | 14 ms | 24276 KB | n=2000 |
71 | Correct | 30 ms | 24272 KB | n=2000 |
72 | Correct | 20 ms | 24356 KB | n=2000 |
73 | Correct | 16 ms | 24276 KB | n=2000 |
74 | Correct | 15 ms | 24276 KB | n=1844 |
75 | Correct | 15 ms | 24280 KB | n=2000 |
76 | Correct | 16 ms | 24276 KB | n=2000 |
77 | Correct | 16 ms | 24340 KB | n=2000 |
78 | Correct | 16 ms | 24276 KB | n=2000 |
79 | Correct | 15 ms | 24276 KB | n=2000 |
80 | Correct | 17 ms | 24404 KB | n=2000 |
81 | Correct | 19 ms | 24404 KB | n=2000 |
82 | Correct | 15 ms | 24276 KB | n=2000 |
83 | Correct | 15 ms | 24372 KB | n=2000 |
84 | Correct | 26 ms | 24284 KB | n=2000 |
85 | Correct | 16 ms | 24404 KB | n=2000 |
86 | Correct | 23 ms | 24376 KB | n=2000 |
87 | Correct | 17 ms | 24268 KB | n=2000 |
88 | Correct | 16 ms | 24416 KB | n=2000 |
89 | Correct | 16 ms | 24416 KB | n=2000 |
90 | Correct | 16 ms | 24448 KB | n=2000 |
91 | Correct | 16 ms | 24280 KB | n=2000 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 23796 KB | n=5 |
2 | Correct | 13 ms | 23892 KB | n=100 |
3 | Correct | 13 ms | 23924 KB | n=100 |
4 | Correct | 13 ms | 23892 KB | n=100 |
5 | Correct | 13 ms | 23892 KB | n=100 |
6 | Correct | 13 ms | 23812 KB | n=100 |
7 | Correct | 12 ms | 23916 KB | n=100 |
8 | Correct | 12 ms | 23868 KB | n=100 |
9 | Correct | 14 ms | 23892 KB | n=100 |
10 | Correct | 14 ms | 23892 KB | n=100 |
11 | Correct | 13 ms | 23892 KB | n=100 |
12 | Correct | 14 ms | 23892 KB | n=100 |
13 | Correct | 14 ms | 23920 KB | n=100 |
14 | Correct | 14 ms | 23892 KB | n=100 |
15 | Correct | 12 ms | 23892 KB | n=100 |
16 | Correct | 12 ms | 23892 KB | n=100 |
17 | Correct | 14 ms | 23892 KB | n=100 |
18 | Correct | 13 ms | 23848 KB | n=100 |
19 | Correct | 13 ms | 23892 KB | n=100 |
20 | Correct | 25 ms | 23876 KB | n=100 |
21 | Correct | 14 ms | 23892 KB | n=100 |
22 | Correct | 13 ms | 23892 KB | n=100 |
23 | Correct | 12 ms | 23920 KB | n=100 |
24 | Correct | 13 ms | 23892 KB | n=100 |
25 | Correct | 25 ms | 23860 KB | n=100 |
26 | Correct | 13 ms | 23852 KB | n=12 |
27 | Correct | 14 ms | 23892 KB | n=100 |
28 | Correct | 12 ms | 24000 KB | n=500 |
29 | Correct | 12 ms | 24020 KB | n=500 |
30 | Correct | 23 ms | 23932 KB | n=500 |
31 | Correct | 14 ms | 24020 KB | n=500 |
32 | Correct | 12 ms | 24020 KB | n=500 |
33 | Correct | 15 ms | 23932 KB | n=500 |
34 | Correct | 14 ms | 23932 KB | n=500 |
35 | Correct | 14 ms | 24020 KB | n=500 |
36 | Correct | 20 ms | 23976 KB | n=500 |
37 | Correct | 13 ms | 23936 KB | n=500 |
38 | Correct | 13 ms | 23912 KB | n=500 |
39 | Correct | 15 ms | 24020 KB | n=500 |
40 | Correct | 13 ms | 24032 KB | n=500 |
41 | Correct | 14 ms | 23920 KB | n=500 |
42 | Correct | 13 ms | 23928 KB | n=500 |
43 | Correct | 13 ms | 23932 KB | n=500 |
44 | Correct | 13 ms | 24020 KB | n=500 |
45 | Correct | 25 ms | 24020 KB | n=500 |
46 | Correct | 13 ms | 24020 KB | n=500 |
47 | Correct | 14 ms | 23984 KB | n=500 |
48 | Correct | 14 ms | 24020 KB | n=500 |
49 | Correct | 14 ms | 24020 KB | n=500 |
50 | Correct | 13 ms | 24020 KB | n=500 |
51 | Correct | 13 ms | 23940 KB | n=500 |
52 | Correct | 13 ms | 24020 KB | n=500 |
53 | Correct | 16 ms | 24020 KB | n=500 |
54 | Correct | 15 ms | 24020 KB | n=500 |
55 | Correct | 13 ms | 23916 KB | n=278 |
56 | Correct | 14 ms | 23928 KB | n=500 |
57 | Correct | 14 ms | 24028 KB | n=500 |
58 | Correct | 13 ms | 24020 KB | n=500 |
59 | Correct | 16 ms | 24332 KB | n=2000 |
60 | Correct | 15 ms | 24412 KB | n=2000 |
61 | Correct | 17 ms | 24412 KB | n=2000 |
62 | Correct | 16 ms | 24404 KB | n=2000 |
63 | Correct | 15 ms | 24284 KB | n=2000 |
64 | Correct | 31 ms | 24408 KB | n=2000 |
65 | Correct | 16 ms | 24328 KB | n=2000 |
66 | Correct | 16 ms | 24448 KB | n=2000 |
67 | Correct | 23 ms | 24280 KB | n=2000 |
68 | Correct | 16 ms | 24324 KB | n=2000 |
69 | Correct | 15 ms | 24360 KB | n=2000 |
70 | Correct | 14 ms | 24276 KB | n=2000 |
71 | Correct | 30 ms | 24272 KB | n=2000 |
72 | Correct | 20 ms | 24356 KB | n=2000 |
73 | Correct | 16 ms | 24276 KB | n=2000 |
74 | Correct | 15 ms | 24276 KB | n=1844 |
75 | Correct | 15 ms | 24280 KB | n=2000 |
76 | Correct | 16 ms | 24276 KB | n=2000 |
77 | Correct | 16 ms | 24340 KB | n=2000 |
78 | Correct | 16 ms | 24276 KB | n=2000 |
79 | Correct | 15 ms | 24276 KB | n=2000 |
80 | Correct | 17 ms | 24404 KB | n=2000 |
81 | Correct | 19 ms | 24404 KB | n=2000 |
82 | Correct | 15 ms | 24276 KB | n=2000 |
83 | Correct | 15 ms | 24372 KB | n=2000 |
84 | Correct | 26 ms | 24284 KB | n=2000 |
85 | Correct | 16 ms | 24404 KB | n=2000 |
86 | Correct | 23 ms | 24376 KB | n=2000 |
87 | Correct | 17 ms | 24268 KB | n=2000 |
88 | Correct | 16 ms | 24416 KB | n=2000 |
89 | Correct | 16 ms | 24416 KB | n=2000 |
90 | Correct | 16 ms | 24448 KB | n=2000 |
91 | Correct | 16 ms | 24280 KB | n=2000 |
92 | Correct | 919 ms | 68884 KB | n=200000 |
93 | Correct | 1084 ms | 72804 KB | n=200000 |
94 | Correct | 959 ms | 76128 KB | n=200000 |
95 | Correct | 875 ms | 68844 KB | n=200000 |
96 | Correct | 886 ms | 68968 KB | n=200000 |
97 | Correct | 1107 ms | 71864 KB | n=200000 |
98 | Correct | 861 ms | 69068 KB | n=200000 |
99 | Correct | 1092 ms | 68484 KB | n=200000 |
100 | Correct | 930 ms | 68976 KB | n=200000 |
101 | Correct | 940 ms | 77592 KB | n=200000 |
102 | Correct | 514 ms | 70240 KB | n=200000 |
103 | Correct | 441 ms | 70136 KB | n=200000 |
104 | Correct | 504 ms | 70056 KB | n=200000 |
105 | Correct | 476 ms | 69744 KB | n=200000 |
106 | Correct | 454 ms | 69836 KB | n=200000 |
107 | Correct | 445 ms | 69524 KB | n=200000 |
108 | Correct | 886 ms | 68336 KB | n=200000 |
109 | Correct | 931 ms | 67920 KB | n=200000 |
110 | Correct | 885 ms | 67844 KB | n=200000 |
111 | Correct | 799 ms | 68292 KB | n=200000 |
112 | Correct | 837 ms | 75672 KB | n=200000 |
113 | Correct | 960 ms | 71260 KB | n=200000 |
114 | Correct | 783 ms | 68280 KB | n=200000 |
115 | Correct | 1077 ms | 69036 KB | n=200000 |
116 | Correct | 717 ms | 68096 KB | n=200000 |
117 | Correct | 822 ms | 76168 KB | n=200000 |
118 | Correct | 973 ms | 70172 KB | n=200000 |
119 | Correct | 759 ms | 68120 KB | n=200000 |
120 | Correct | 777 ms | 76116 KB | n=200000 |
121 | Correct | 815 ms | 76076 KB | n=200000 |
122 | Correct | 764 ms | 76444 KB | n=200000 |
123 | Correct | 447 ms | 68168 KB | n=200000 |
124 | Correct | 195 ms | 36980 KB | n=25264 |