Submission #922845

# Submission time Handle Problem Language Result Execution time Memory
922845 2024-02-06T08:00:11 Z Aiperiii Birthday gift (IZhO18_treearray) C++14
56 / 100
342 ms 5724 KB
#include <bits/stdc++.h>
//#include "boxes.h"
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N=1e5+5;
vector <int> g[N];
int p[N],d[N],jmp[N][20];
void dfs(int v,int par){
   p[v]=par;
   for(auto to : g[v]){
      if(to!=par){
         d[to]=d[v]+1;
         dfs(to,v);
      }
   }
}
int lca(int a,int b){
   if(d[a]<d[b])swap(a,b);
   for(int i=19;i>=0;i--){
      if(d[jmp[a][i]]>=d[b]){
         a=jmp[a][i];
      }
   }
   if(a==b)return a;
   for(int i=19;i>=0;i--){
      if(jmp[a][i]!=jmp[b][i]){
         a=jmp[a][i];
         b=jmp[b][i];
      }
   }
   return p[a];
}
signed main(){
   ios_base::sync_with_stdio();
   cin.tie(0);cout.tie(0);
   int n,m,q;
   cin>>n>>m>>q;
   for(int i=0;i<n-1;i++){
      int u,v;
      cin>>u>>v;
      g[u].pb(v);g[v].pb(u);
   }
   dfs(1,1);
   for(int i=1;i<=n;i++){
      jmp[i][0]=p[i];
   }
   for(int i=1;i<20;i++){
      for(int j=1;j<=n;j++){
         jmp[j][i]=jmp[jmp[j][i-1]][i-1];
      }
   }
   /*for(int i=1;i<=n;i++)cout<<d[i]<<" ";
   cout<<"\n";
   for(int i=1;i<=n;i++){
      for(int j=0;j<20;j++){
         cout<<jmp[i][j]<<" ";
      }
      cout<<"\n";
   }
   cout<<"\n";*/
   vector <int> a(m+1);
   for(int i=1;i<=m;i++)cin>>a[i];
   while(q--){
      int type,l,r,v,pos;
      cin>>type;
      if(type==1){
         cin>>pos>>v;
         a[pos]=v;
      }
      else{
         cin>>l>>r>>v;
         int st=l,x=a[l];
         int L=-1,R=-1;
         for(int i=l;i<=r;i++){
            if(lca(a[i],v)!=v){
               if(st<i && x==v){
                  L=st;R=i-1;break;
               }
               st=i+1;
               if(i+1<=m)x=a[st];
               continue;
            }
            x=lca(x,a[i]);
         }
         if(x==v && st<=r && L==-1 && R==-1){
            L=st;R=r;
         }
         cout<<L<<" "<<R<<"\n";
      }
   }
}

/*
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
 */
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB n=5
2 Correct 2 ms 4952 KB n=100
3 Correct 1 ms 5064 KB n=100
4 Correct 2 ms 4956 KB n=100
5 Correct 1 ms 4956 KB n=100
6 Correct 2 ms 4956 KB n=100
7 Correct 2 ms 4956 KB n=100
8 Correct 2 ms 4956 KB n=100
9 Correct 2 ms 4956 KB n=100
10 Correct 2 ms 4956 KB n=100
11 Correct 2 ms 4956 KB n=100
12 Correct 1 ms 4956 KB n=100
13 Correct 1 ms 4956 KB n=100
14 Correct 2 ms 4956 KB n=100
15 Correct 2 ms 4952 KB n=100
16 Correct 2 ms 4956 KB n=100
17 Correct 2 ms 4956 KB n=100
18 Correct 2 ms 4952 KB n=100
19 Correct 2 ms 4952 KB n=100
20 Correct 2 ms 4956 KB n=100
21 Correct 1 ms 4956 KB n=100
22 Correct 1 ms 4952 KB n=100
23 Correct 2 ms 4956 KB n=100
24 Correct 2 ms 4956 KB n=100
25 Correct 2 ms 4956 KB n=100
26 Correct 1 ms 4956 KB n=12
27 Correct 2 ms 4956 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB n=5
2 Correct 2 ms 4952 KB n=100
3 Correct 1 ms 5064 KB n=100
4 Correct 2 ms 4956 KB n=100
5 Correct 1 ms 4956 KB n=100
6 Correct 2 ms 4956 KB n=100
7 Correct 2 ms 4956 KB n=100
8 Correct 2 ms 4956 KB n=100
9 Correct 2 ms 4956 KB n=100
10 Correct 2 ms 4956 KB n=100
11 Correct 2 ms 4956 KB n=100
12 Correct 1 ms 4956 KB n=100
13 Correct 1 ms 4956 KB n=100
14 Correct 2 ms 4956 KB n=100
15 Correct 2 ms 4952 KB n=100
16 Correct 2 ms 4956 KB n=100
17 Correct 2 ms 4956 KB n=100
18 Correct 2 ms 4952 KB n=100
19 Correct 2 ms 4952 KB n=100
20 Correct 2 ms 4956 KB n=100
21 Correct 1 ms 4956 KB n=100
22 Correct 1 ms 4952 KB n=100
23 Correct 2 ms 4956 KB n=100
24 Correct 2 ms 4956 KB n=100
25 Correct 2 ms 4956 KB n=100
26 Correct 1 ms 4956 KB n=12
27 Correct 2 ms 4956 KB n=100
28 Correct 9 ms 5140 KB n=500
29 Correct 5 ms 4956 KB n=500
30 Correct 5 ms 4956 KB n=500
31 Correct 5 ms 4952 KB n=500
32 Correct 10 ms 4956 KB n=500
33 Correct 5 ms 4952 KB n=500
34 Correct 10 ms 4956 KB n=500
35 Correct 5 ms 4956 KB n=500
36 Correct 21 ms 5112 KB n=500
37 Correct 21 ms 4956 KB n=500
38 Correct 22 ms 5140 KB n=500
39 Correct 13 ms 4956 KB n=500
40 Correct 11 ms 5208 KB n=500
41 Correct 12 ms 4952 KB n=500
42 Correct 12 ms 4956 KB n=500
43 Correct 12 ms 4952 KB n=500
44 Correct 12 ms 4952 KB n=500
45 Correct 8 ms 4956 KB n=500
46 Correct 5 ms 4952 KB n=500
47 Correct 5 ms 4956 KB n=500
48 Correct 8 ms 4956 KB n=500
49 Correct 4 ms 4952 KB n=500
50 Correct 7 ms 4952 KB n=500
51 Correct 6 ms 4956 KB n=500
52 Correct 7 ms 4956 KB n=500
53 Correct 7 ms 4956 KB n=500
54 Correct 19 ms 4952 KB n=500
55 Correct 2 ms 4956 KB n=278
56 Correct 20 ms 5164 KB n=500
57 Correct 21 ms 4956 KB n=500
58 Correct 16 ms 5076 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB n=5
2 Correct 2 ms 4952 KB n=100
3 Correct 1 ms 5064 KB n=100
4 Correct 2 ms 4956 KB n=100
5 Correct 1 ms 4956 KB n=100
6 Correct 2 ms 4956 KB n=100
7 Correct 2 ms 4956 KB n=100
8 Correct 2 ms 4956 KB n=100
9 Correct 2 ms 4956 KB n=100
10 Correct 2 ms 4956 KB n=100
11 Correct 2 ms 4956 KB n=100
12 Correct 1 ms 4956 KB n=100
13 Correct 1 ms 4956 KB n=100
14 Correct 2 ms 4956 KB n=100
15 Correct 2 ms 4952 KB n=100
16 Correct 2 ms 4956 KB n=100
17 Correct 2 ms 4956 KB n=100
18 Correct 2 ms 4952 KB n=100
19 Correct 2 ms 4952 KB n=100
20 Correct 2 ms 4956 KB n=100
21 Correct 1 ms 4956 KB n=100
22 Correct 1 ms 4952 KB n=100
23 Correct 2 ms 4956 KB n=100
24 Correct 2 ms 4956 KB n=100
25 Correct 2 ms 4956 KB n=100
26 Correct 1 ms 4956 KB n=12
27 Correct 2 ms 4956 KB n=100
28 Correct 9 ms 5140 KB n=500
29 Correct 5 ms 4956 KB n=500
30 Correct 5 ms 4956 KB n=500
31 Correct 5 ms 4952 KB n=500
32 Correct 10 ms 4956 KB n=500
33 Correct 5 ms 4952 KB n=500
34 Correct 10 ms 4956 KB n=500
35 Correct 5 ms 4956 KB n=500
36 Correct 21 ms 5112 KB n=500
37 Correct 21 ms 4956 KB n=500
38 Correct 22 ms 5140 KB n=500
39 Correct 13 ms 4956 KB n=500
40 Correct 11 ms 5208 KB n=500
41 Correct 12 ms 4952 KB n=500
42 Correct 12 ms 4956 KB n=500
43 Correct 12 ms 4952 KB n=500
44 Correct 12 ms 4952 KB n=500
45 Correct 8 ms 4956 KB n=500
46 Correct 5 ms 4952 KB n=500
47 Correct 5 ms 4956 KB n=500
48 Correct 8 ms 4956 KB n=500
49 Correct 4 ms 4952 KB n=500
50 Correct 7 ms 4952 KB n=500
51 Correct 6 ms 4956 KB n=500
52 Correct 7 ms 4956 KB n=500
53 Correct 7 ms 4956 KB n=500
54 Correct 19 ms 4952 KB n=500
55 Correct 2 ms 4956 KB n=278
56 Correct 20 ms 5164 KB n=500
57 Correct 21 ms 4956 KB n=500
58 Correct 16 ms 5076 KB n=500
59 Correct 122 ms 5332 KB n=2000
60 Correct 56 ms 5212 KB n=2000
61 Correct 54 ms 5212 KB n=2000
62 Correct 40 ms 5380 KB n=2000
63 Correct 128 ms 5332 KB n=2000
64 Correct 51 ms 5212 KB n=2000
65 Correct 133 ms 5332 KB n=2000
66 Correct 60 ms 5208 KB n=2000
67 Correct 84 ms 5320 KB n=2000
68 Correct 52 ms 5208 KB n=2000
69 Correct 311 ms 5340 KB n=2000
70 Correct 316 ms 5336 KB n=2000
71 Correct 312 ms 5340 KB n=2000
72 Correct 158 ms 5212 KB n=2000
73 Correct 161 ms 5468 KB n=2000
74 Correct 105 ms 5208 KB n=1844
75 Correct 159 ms 5332 KB n=2000
76 Correct 167 ms 5332 KB n=2000
77 Correct 165 ms 5332 KB n=2000
78 Correct 176 ms 5208 KB n=2000
79 Correct 118 ms 5456 KB n=2000
80 Correct 49 ms 5212 KB n=2000
81 Correct 45 ms 5464 KB n=2000
82 Correct 108 ms 5328 KB n=2000
83 Correct 50 ms 5428 KB n=2000
84 Correct 84 ms 5208 KB n=2000
85 Correct 82 ms 5376 KB n=2000
86 Correct 87 ms 5212 KB n=2000
87 Correct 87 ms 5464 KB n=2000
88 Correct 342 ms 5480 KB n=2000
89 Correct 340 ms 5212 KB n=2000
90 Correct 282 ms 5464 KB n=2000
91 Correct 221 ms 5208 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB n=5
2 Correct 2 ms 4952 KB n=100
3 Correct 1 ms 5064 KB n=100
4 Correct 2 ms 4956 KB n=100
5 Correct 1 ms 4956 KB n=100
6 Correct 2 ms 4956 KB n=100
7 Correct 2 ms 4956 KB n=100
8 Correct 2 ms 4956 KB n=100
9 Correct 2 ms 4956 KB n=100
10 Correct 2 ms 4956 KB n=100
11 Correct 2 ms 4956 KB n=100
12 Correct 1 ms 4956 KB n=100
13 Correct 1 ms 4956 KB n=100
14 Correct 2 ms 4956 KB n=100
15 Correct 2 ms 4952 KB n=100
16 Correct 2 ms 4956 KB n=100
17 Correct 2 ms 4956 KB n=100
18 Correct 2 ms 4952 KB n=100
19 Correct 2 ms 4952 KB n=100
20 Correct 2 ms 4956 KB n=100
21 Correct 1 ms 4956 KB n=100
22 Correct 1 ms 4952 KB n=100
23 Correct 2 ms 4956 KB n=100
24 Correct 2 ms 4956 KB n=100
25 Correct 2 ms 4956 KB n=100
26 Correct 1 ms 4956 KB n=12
27 Correct 2 ms 4956 KB n=100
28 Correct 9 ms 5140 KB n=500
29 Correct 5 ms 4956 KB n=500
30 Correct 5 ms 4956 KB n=500
31 Correct 5 ms 4952 KB n=500
32 Correct 10 ms 4956 KB n=500
33 Correct 5 ms 4952 KB n=500
34 Correct 10 ms 4956 KB n=500
35 Correct 5 ms 4956 KB n=500
36 Correct 21 ms 5112 KB n=500
37 Correct 21 ms 4956 KB n=500
38 Correct 22 ms 5140 KB n=500
39 Correct 13 ms 4956 KB n=500
40 Correct 11 ms 5208 KB n=500
41 Correct 12 ms 4952 KB n=500
42 Correct 12 ms 4956 KB n=500
43 Correct 12 ms 4952 KB n=500
44 Correct 12 ms 4952 KB n=500
45 Correct 8 ms 4956 KB n=500
46 Correct 5 ms 4952 KB n=500
47 Correct 5 ms 4956 KB n=500
48 Correct 8 ms 4956 KB n=500
49 Correct 4 ms 4952 KB n=500
50 Correct 7 ms 4952 KB n=500
51 Correct 6 ms 4956 KB n=500
52 Correct 7 ms 4956 KB n=500
53 Correct 7 ms 4956 KB n=500
54 Correct 19 ms 4952 KB n=500
55 Correct 2 ms 4956 KB n=278
56 Correct 20 ms 5164 KB n=500
57 Correct 21 ms 4956 KB n=500
58 Correct 16 ms 5076 KB n=500
59 Correct 122 ms 5332 KB n=2000
60 Correct 56 ms 5212 KB n=2000
61 Correct 54 ms 5212 KB n=2000
62 Correct 40 ms 5380 KB n=2000
63 Correct 128 ms 5332 KB n=2000
64 Correct 51 ms 5212 KB n=2000
65 Correct 133 ms 5332 KB n=2000
66 Correct 60 ms 5208 KB n=2000
67 Correct 84 ms 5320 KB n=2000
68 Correct 52 ms 5208 KB n=2000
69 Correct 311 ms 5340 KB n=2000
70 Correct 316 ms 5336 KB n=2000
71 Correct 312 ms 5340 KB n=2000
72 Correct 158 ms 5212 KB n=2000
73 Correct 161 ms 5468 KB n=2000
74 Correct 105 ms 5208 KB n=1844
75 Correct 159 ms 5332 KB n=2000
76 Correct 167 ms 5332 KB n=2000
77 Correct 165 ms 5332 KB n=2000
78 Correct 176 ms 5208 KB n=2000
79 Correct 118 ms 5456 KB n=2000
80 Correct 49 ms 5212 KB n=2000
81 Correct 45 ms 5464 KB n=2000
82 Correct 108 ms 5328 KB n=2000
83 Correct 50 ms 5428 KB n=2000
84 Correct 84 ms 5208 KB n=2000
85 Correct 82 ms 5376 KB n=2000
86 Correct 87 ms 5212 KB n=2000
87 Correct 87 ms 5464 KB n=2000
88 Correct 342 ms 5480 KB n=2000
89 Correct 340 ms 5212 KB n=2000
90 Correct 282 ms 5464 KB n=2000
91 Correct 221 ms 5208 KB n=2000
92 Runtime error 3 ms 5724 KB Execution killed with signal 11
93 Halted 0 ms 0 KB -