Submission #334825

# Submission time Handle Problem Language Result Execution time Memory
334825 2020-12-10T04:21:24 Z juggernaut Birthday gift (IZhO18_treearray) C++14
56 / 100
153 ms 748 KB
#include<bits/stdc++.h>
using namespace std;
int n,m,q,a[2005],up[2005][11],tin[2005],tout[2005],timer;
vector<int>g[2005];
void dfs(int v,int p){
    tin[v]=++timer;
    up[v][0]=p;
    for(int i=1;i<11;i++)up[v][i]=up[up[v][i-1]][i-1];
    for(int to:g[v])if(to!=p)dfs(to,v);
    tout[v]=++timer;
}
bool upper(int a,int b){
    return tin[a]<=tin[b]&&tout[a]>=tout[b];
}
int lca(int a,int b){
    if(upper(a,b))return a;
    if(upper(b,a))return b;
    for(int i=10;i>=0;i--)
        if(!upper(up[a][i],b))a=up[a][i];
    return up[a][0];
}
int main(){
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<n;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(1,1);
    for(int i=1;i<=m;i++)scanf("%d",&a[i]);
    while(q--){
        int type;
        scanf("%d",&type);
        if(type&1){
            int pos,val;
            scanf("%d%d",&pos,&val);
            a[pos]=val;
        }else{
            int l,r,v,al=-1,ar=-1;
            scanf("%d%d%d",&l,&r,&v);
            for(int i=l;i<r;i++){
                if(a[i]==v){
                    al=i;
                    ar=i;
                    break;
                }
                if(lca(a[i],a[i+1])==v){
                    al=i;
                    ar=i+1;
                    break;
                }
            }
            if(a[r]==v){
                al=r;
                ar=r;
            }
            printf("%d %d\n",al,ar);
        }
    }
}

Compilation message

treearray.cpp: In function 'int main()':
treearray.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |     scanf("%d%d%d",&n,&m,&q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
treearray.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |         scanf("%d%d",&x,&y);
      |         ~~~~~^~~~~~~~~~~~~~
treearray.cpp:31:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   31 |     for(int i=1;i<=m;i++)scanf("%d",&a[i]);
      |                          ~~~~~^~~~~~~~~~~~
treearray.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   34 |         scanf("%d",&type);
      |         ~~~~~^~~~~~~~~~~~
treearray.cpp:37:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   37 |             scanf("%d%d",&pos,&val);
      |             ~~~~~^~~~~~~~~~~~~~~~~~
treearray.cpp:41:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   41 |             scanf("%d%d%d",&l,&r,&v);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=5
2 Correct 1 ms 364 KB n=100
3 Correct 1 ms 364 KB n=100
4 Correct 1 ms 364 KB n=100
5 Correct 1 ms 364 KB n=100
6 Correct 1 ms 364 KB n=100
7 Correct 1 ms 364 KB n=100
8 Correct 1 ms 364 KB n=100
9 Correct 1 ms 364 KB n=100
10 Correct 1 ms 364 KB n=100
11 Correct 1 ms 364 KB n=100
12 Correct 1 ms 364 KB n=100
13 Correct 1 ms 364 KB n=100
14 Correct 1 ms 364 KB n=100
15 Correct 1 ms 364 KB n=100
16 Correct 1 ms 364 KB n=100
17 Correct 1 ms 364 KB n=100
18 Correct 1 ms 364 KB n=100
19 Correct 1 ms 364 KB n=100
20 Correct 1 ms 364 KB n=100
21 Correct 1 ms 364 KB n=100
22 Correct 1 ms 364 KB n=100
23 Correct 1 ms 364 KB n=100
24 Correct 1 ms 364 KB n=100
25 Correct 1 ms 384 KB n=100
26 Correct 1 ms 364 KB n=12
27 Correct 1 ms 364 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=5
2 Correct 1 ms 364 KB n=100
3 Correct 1 ms 364 KB n=100
4 Correct 1 ms 364 KB n=100
5 Correct 1 ms 364 KB n=100
6 Correct 1 ms 364 KB n=100
7 Correct 1 ms 364 KB n=100
8 Correct 1 ms 364 KB n=100
9 Correct 1 ms 364 KB n=100
10 Correct 1 ms 364 KB n=100
11 Correct 1 ms 364 KB n=100
12 Correct 1 ms 364 KB n=100
13 Correct 1 ms 364 KB n=100
14 Correct 1 ms 364 KB n=100
15 Correct 1 ms 364 KB n=100
16 Correct 1 ms 364 KB n=100
17 Correct 1 ms 364 KB n=100
18 Correct 1 ms 364 KB n=100
19 Correct 1 ms 364 KB n=100
20 Correct 1 ms 364 KB n=100
21 Correct 1 ms 364 KB n=100
22 Correct 1 ms 364 KB n=100
23 Correct 1 ms 364 KB n=100
24 Correct 1 ms 364 KB n=100
25 Correct 1 ms 384 KB n=100
26 Correct 1 ms 364 KB n=12
27 Correct 1 ms 364 KB n=100
28 Correct 1 ms 364 KB n=500
29 Correct 1 ms 492 KB n=500
30 Correct 1 ms 364 KB n=500
31 Correct 1 ms 492 KB n=500
32 Correct 1 ms 364 KB n=500
33 Correct 2 ms 364 KB n=500
34 Correct 1 ms 364 KB n=500
35 Correct 1 ms 492 KB n=500
36 Correct 11 ms 492 KB n=500
37 Correct 10 ms 492 KB n=500
38 Correct 10 ms 492 KB n=500
39 Correct 6 ms 492 KB n=500
40 Correct 5 ms 492 KB n=500
41 Correct 5 ms 492 KB n=500
42 Correct 6 ms 512 KB n=500
43 Correct 5 ms 492 KB n=500
44 Correct 5 ms 492 KB n=500
45 Correct 1 ms 492 KB n=500
46 Correct 1 ms 492 KB n=500
47 Correct 1 ms 492 KB n=500
48 Correct 1 ms 492 KB n=500
49 Correct 1 ms 492 KB n=500
50 Correct 3 ms 492 KB n=500
51 Correct 2 ms 492 KB n=500
52 Correct 1 ms 492 KB n=500
53 Correct 3 ms 492 KB n=500
54 Correct 1 ms 492 KB n=500
55 Correct 2 ms 384 KB n=278
56 Correct 2 ms 492 KB n=500
57 Correct 2 ms 492 KB n=500
58 Correct 8 ms 492 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=5
2 Correct 1 ms 364 KB n=100
3 Correct 1 ms 364 KB n=100
4 Correct 1 ms 364 KB n=100
5 Correct 1 ms 364 KB n=100
6 Correct 1 ms 364 KB n=100
7 Correct 1 ms 364 KB n=100
8 Correct 1 ms 364 KB n=100
9 Correct 1 ms 364 KB n=100
10 Correct 1 ms 364 KB n=100
11 Correct 1 ms 364 KB n=100
12 Correct 1 ms 364 KB n=100
13 Correct 1 ms 364 KB n=100
14 Correct 1 ms 364 KB n=100
15 Correct 1 ms 364 KB n=100
16 Correct 1 ms 364 KB n=100
17 Correct 1 ms 364 KB n=100
18 Correct 1 ms 364 KB n=100
19 Correct 1 ms 364 KB n=100
20 Correct 1 ms 364 KB n=100
21 Correct 1 ms 364 KB n=100
22 Correct 1 ms 364 KB n=100
23 Correct 1 ms 364 KB n=100
24 Correct 1 ms 364 KB n=100
25 Correct 1 ms 384 KB n=100
26 Correct 1 ms 364 KB n=12
27 Correct 1 ms 364 KB n=100
28 Correct 1 ms 364 KB n=500
29 Correct 1 ms 492 KB n=500
30 Correct 1 ms 364 KB n=500
31 Correct 1 ms 492 KB n=500
32 Correct 1 ms 364 KB n=500
33 Correct 2 ms 364 KB n=500
34 Correct 1 ms 364 KB n=500
35 Correct 1 ms 492 KB n=500
36 Correct 11 ms 492 KB n=500
37 Correct 10 ms 492 KB n=500
38 Correct 10 ms 492 KB n=500
39 Correct 6 ms 492 KB n=500
40 Correct 5 ms 492 KB n=500
41 Correct 5 ms 492 KB n=500
42 Correct 6 ms 512 KB n=500
43 Correct 5 ms 492 KB n=500
44 Correct 5 ms 492 KB n=500
45 Correct 1 ms 492 KB n=500
46 Correct 1 ms 492 KB n=500
47 Correct 1 ms 492 KB n=500
48 Correct 1 ms 492 KB n=500
49 Correct 1 ms 492 KB n=500
50 Correct 3 ms 492 KB n=500
51 Correct 2 ms 492 KB n=500
52 Correct 1 ms 492 KB n=500
53 Correct 3 ms 492 KB n=500
54 Correct 1 ms 492 KB n=500
55 Correct 2 ms 384 KB n=278
56 Correct 2 ms 492 KB n=500
57 Correct 2 ms 492 KB n=500
58 Correct 8 ms 492 KB n=500
59 Correct 3 ms 620 KB n=2000
60 Correct 5 ms 748 KB n=2000
61 Correct 12 ms 620 KB n=2000
62 Correct 14 ms 620 KB n=2000
63 Correct 3 ms 620 KB n=2000
64 Correct 14 ms 620 KB n=2000
65 Correct 3 ms 620 KB n=2000
66 Correct 10 ms 620 KB n=2000
67 Correct 4 ms 620 KB n=2000
68 Correct 13 ms 620 KB n=2000
69 Correct 153 ms 620 KB n=2000
70 Correct 149 ms 620 KB n=2000
71 Correct 147 ms 748 KB n=2000
72 Correct 77 ms 620 KB n=2000
73 Correct 75 ms 620 KB n=2000
74 Correct 2 ms 620 KB n=1844
75 Correct 76 ms 748 KB n=2000
76 Correct 75 ms 620 KB n=2000
77 Correct 75 ms 620 KB n=2000
78 Correct 78 ms 536 KB n=2000
79 Correct 3 ms 620 KB n=2000
80 Correct 8 ms 620 KB n=2000
81 Correct 12 ms 620 KB n=2000
82 Correct 3 ms 620 KB n=2000
83 Correct 9 ms 620 KB n=2000
84 Correct 39 ms 620 KB n=2000
85 Correct 27 ms 640 KB n=2000
86 Correct 31 ms 620 KB n=2000
87 Correct 43 ms 620 KB n=2000
88 Correct 17 ms 748 KB n=2000
89 Correct 17 ms 748 KB n=2000
90 Correct 10 ms 620 KB n=2000
91 Correct 113 ms 620 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=5
2 Correct 1 ms 364 KB n=100
3 Correct 1 ms 364 KB n=100
4 Correct 1 ms 364 KB n=100
5 Correct 1 ms 364 KB n=100
6 Correct 1 ms 364 KB n=100
7 Correct 1 ms 364 KB n=100
8 Correct 1 ms 364 KB n=100
9 Correct 1 ms 364 KB n=100
10 Correct 1 ms 364 KB n=100
11 Correct 1 ms 364 KB n=100
12 Correct 1 ms 364 KB n=100
13 Correct 1 ms 364 KB n=100
14 Correct 1 ms 364 KB n=100
15 Correct 1 ms 364 KB n=100
16 Correct 1 ms 364 KB n=100
17 Correct 1 ms 364 KB n=100
18 Correct 1 ms 364 KB n=100
19 Correct 1 ms 364 KB n=100
20 Correct 1 ms 364 KB n=100
21 Correct 1 ms 364 KB n=100
22 Correct 1 ms 364 KB n=100
23 Correct 1 ms 364 KB n=100
24 Correct 1 ms 364 KB n=100
25 Correct 1 ms 384 KB n=100
26 Correct 1 ms 364 KB n=12
27 Correct 1 ms 364 KB n=100
28 Correct 1 ms 364 KB n=500
29 Correct 1 ms 492 KB n=500
30 Correct 1 ms 364 KB n=500
31 Correct 1 ms 492 KB n=500
32 Correct 1 ms 364 KB n=500
33 Correct 2 ms 364 KB n=500
34 Correct 1 ms 364 KB n=500
35 Correct 1 ms 492 KB n=500
36 Correct 11 ms 492 KB n=500
37 Correct 10 ms 492 KB n=500
38 Correct 10 ms 492 KB n=500
39 Correct 6 ms 492 KB n=500
40 Correct 5 ms 492 KB n=500
41 Correct 5 ms 492 KB n=500
42 Correct 6 ms 512 KB n=500
43 Correct 5 ms 492 KB n=500
44 Correct 5 ms 492 KB n=500
45 Correct 1 ms 492 KB n=500
46 Correct 1 ms 492 KB n=500
47 Correct 1 ms 492 KB n=500
48 Correct 1 ms 492 KB n=500
49 Correct 1 ms 492 KB n=500
50 Correct 3 ms 492 KB n=500
51 Correct 2 ms 492 KB n=500
52 Correct 1 ms 492 KB n=500
53 Correct 3 ms 492 KB n=500
54 Correct 1 ms 492 KB n=500
55 Correct 2 ms 384 KB n=278
56 Correct 2 ms 492 KB n=500
57 Correct 2 ms 492 KB n=500
58 Correct 8 ms 492 KB n=500
59 Correct 3 ms 620 KB n=2000
60 Correct 5 ms 748 KB n=2000
61 Correct 12 ms 620 KB n=2000
62 Correct 14 ms 620 KB n=2000
63 Correct 3 ms 620 KB n=2000
64 Correct 14 ms 620 KB n=2000
65 Correct 3 ms 620 KB n=2000
66 Correct 10 ms 620 KB n=2000
67 Correct 4 ms 620 KB n=2000
68 Correct 13 ms 620 KB n=2000
69 Correct 153 ms 620 KB n=2000
70 Correct 149 ms 620 KB n=2000
71 Correct 147 ms 748 KB n=2000
72 Correct 77 ms 620 KB n=2000
73 Correct 75 ms 620 KB n=2000
74 Correct 2 ms 620 KB n=1844
75 Correct 76 ms 748 KB n=2000
76 Correct 75 ms 620 KB n=2000
77 Correct 75 ms 620 KB n=2000
78 Correct 78 ms 536 KB n=2000
79 Correct 3 ms 620 KB n=2000
80 Correct 8 ms 620 KB n=2000
81 Correct 12 ms 620 KB n=2000
82 Correct 3 ms 620 KB n=2000
83 Correct 9 ms 620 KB n=2000
84 Correct 39 ms 620 KB n=2000
85 Correct 27 ms 640 KB n=2000
86 Correct 31 ms 620 KB n=2000
87 Correct 43 ms 620 KB n=2000
88 Correct 17 ms 748 KB n=2000
89 Correct 17 ms 748 KB n=2000
90 Correct 10 ms 620 KB n=2000
91 Correct 113 ms 620 KB n=2000
92 Runtime error 1 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
93 Halted 0 ms 0 KB -