Submission #173109

# Submission time Handle Problem Language Result Execution time Memory
173109 2020-01-03T11:30:04 Z juggernaut Birthday gift (IZhO18_treearray) C++14
100 / 100
1350 ms 74736 KB
//Just try and the idea will come!
#include<bits/stdc++.h>
using namespace std;
int n,m,q,i,x,y,z,timer,tin[200001],tout[200001],up[200001][19],l,r,a[200001];
vector<int>g[200001];
set<pair<int,int>>st[200001];
void dfs(int v,int p){
    up[v][0]=p;
    tin[v]=timer++;
    for(int i=1;i<19;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=18;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(i=1;i<n;i++){
        scanf("%d%d",&x,&y);
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(1,1);
    scanf("%d",&x);
    a[1]=x;
    st[x].insert({1,1});
    for(i=2;i<=m;i++){
        scanf("%d",&y);
        a[i]=y;
        st[y].insert({i,i});
        st[lca(y,x)].insert({i-1,i});
        x=y;
    }
    while(q--){
        scanf("%d",&x);
        if(x&1){
            scanf("%d%d",&x,&y);
            st[a[x]].erase({x,x});
            if(x>1)st[lca(a[x-1],a[x])].erase({x-1,x});
            if(x<m)st[lca(a[x],a[x+1])].erase({x,x+1});
            a[x]=y;
            st[a[x]].insert({x,x});
            if(x>1)st[lca(a[x-1],a[x])].insert({x-1,x});
            if(x<m)st[lca(a[x],a[x+1])].insert({x,x+1});
        }else{
            scanf("%d%d%d",&x,&y,&z);
            auto it=st[z].lower_bound({x,0});l=r=-1;
            if(it!=st[z].end()&&it->second<=y){
                l=it->first;
                r=it->second;
            }
            printf("%d %d\n",l,r);
        }
    }
}

Compilation message

treearray.cpp: In function 'int main()':
treearray.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     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]
         scanf("%d%d",&x,&y);
         ~~~~~^~~~~~~~~~~~~~
treearray.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&x);
     ~~~~~^~~~~~~~~
treearray.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&y);
         ~~~~~^~~~~~~~~
treearray.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&x);
         ~~~~~^~~~~~~~~
treearray.cpp:44:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d",&x,&y);
             ~~~~~^~~~~~~~~~~~~~
treearray.cpp:53:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d%d",&x,&y,&z);
             ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 14456 KB n=5
2 Correct 15 ms 14456 KB n=100
3 Correct 15 ms 14456 KB n=100
4 Correct 15 ms 14456 KB n=100
5 Correct 14 ms 14456 KB n=100
6 Correct 15 ms 14456 KB n=100
7 Correct 15 ms 14456 KB n=100
8 Correct 15 ms 14456 KB n=100
9 Correct 15 ms 14456 KB n=100
10 Correct 15 ms 14460 KB n=100
11 Correct 15 ms 14456 KB n=100
12 Correct 15 ms 14456 KB n=100
13 Correct 15 ms 14456 KB n=100
14 Correct 15 ms 14456 KB n=100
15 Correct 15 ms 14456 KB n=100
16 Correct 17 ms 14456 KB n=100
17 Correct 14 ms 14456 KB n=100
18 Correct 15 ms 14456 KB n=100
19 Correct 15 ms 14456 KB n=100
20 Correct 15 ms 14456 KB n=100
21 Correct 15 ms 14456 KB n=100
22 Correct 18 ms 14584 KB n=100
23 Correct 15 ms 14456 KB n=100
24 Correct 15 ms 14456 KB n=100
25 Correct 15 ms 14456 KB n=100
26 Correct 15 ms 14456 KB n=12
27 Correct 15 ms 14456 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 15 ms 14456 KB n=5
2 Correct 15 ms 14456 KB n=100
3 Correct 15 ms 14456 KB n=100
4 Correct 15 ms 14456 KB n=100
5 Correct 14 ms 14456 KB n=100
6 Correct 15 ms 14456 KB n=100
7 Correct 15 ms 14456 KB n=100
8 Correct 15 ms 14456 KB n=100
9 Correct 15 ms 14456 KB n=100
10 Correct 15 ms 14460 KB n=100
11 Correct 15 ms 14456 KB n=100
12 Correct 15 ms 14456 KB n=100
13 Correct 15 ms 14456 KB n=100
14 Correct 15 ms 14456 KB n=100
15 Correct 15 ms 14456 KB n=100
16 Correct 17 ms 14456 KB n=100
17 Correct 14 ms 14456 KB n=100
18 Correct 15 ms 14456 KB n=100
19 Correct 15 ms 14456 KB n=100
20 Correct 15 ms 14456 KB n=100
21 Correct 15 ms 14456 KB n=100
22 Correct 18 ms 14584 KB n=100
23 Correct 15 ms 14456 KB n=100
24 Correct 15 ms 14456 KB n=100
25 Correct 15 ms 14456 KB n=100
26 Correct 15 ms 14456 KB n=12
27 Correct 15 ms 14456 KB n=100
28 Correct 16 ms 14584 KB n=500
29 Correct 16 ms 14492 KB n=500
30 Correct 16 ms 14584 KB n=500
31 Correct 15 ms 14588 KB n=500
32 Correct 16 ms 14584 KB n=500
33 Correct 15 ms 14584 KB n=500
34 Correct 16 ms 14624 KB n=500
35 Correct 15 ms 14584 KB n=500
36 Correct 15 ms 14584 KB n=500
37 Correct 15 ms 14584 KB n=500
38 Correct 15 ms 14584 KB n=500
39 Correct 15 ms 14584 KB n=500
40 Correct 15 ms 14584 KB n=500
41 Correct 15 ms 14584 KB n=500
42 Correct 16 ms 14584 KB n=500
43 Correct 16 ms 14584 KB n=500
44 Correct 16 ms 14584 KB n=500
45 Correct 14 ms 14584 KB n=500
46 Correct 16 ms 14584 KB n=500
47 Correct 15 ms 14584 KB n=500
48 Correct 15 ms 14584 KB n=500
49 Correct 15 ms 14584 KB n=500
50 Correct 16 ms 14584 KB n=500
51 Correct 16 ms 14584 KB n=500
52 Correct 15 ms 14584 KB n=500
53 Correct 15 ms 14584 KB n=500
54 Correct 15 ms 14584 KB n=500
55 Correct 15 ms 14456 KB n=278
56 Correct 15 ms 14584 KB n=500
57 Correct 15 ms 14584 KB n=500
58 Correct 16 ms 14584 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 15 ms 14456 KB n=5
2 Correct 15 ms 14456 KB n=100
3 Correct 15 ms 14456 KB n=100
4 Correct 15 ms 14456 KB n=100
5 Correct 14 ms 14456 KB n=100
6 Correct 15 ms 14456 KB n=100
7 Correct 15 ms 14456 KB n=100
8 Correct 15 ms 14456 KB n=100
9 Correct 15 ms 14456 KB n=100
10 Correct 15 ms 14460 KB n=100
11 Correct 15 ms 14456 KB n=100
12 Correct 15 ms 14456 KB n=100
13 Correct 15 ms 14456 KB n=100
14 Correct 15 ms 14456 KB n=100
15 Correct 15 ms 14456 KB n=100
16 Correct 17 ms 14456 KB n=100
17 Correct 14 ms 14456 KB n=100
18 Correct 15 ms 14456 KB n=100
19 Correct 15 ms 14456 KB n=100
20 Correct 15 ms 14456 KB n=100
21 Correct 15 ms 14456 KB n=100
22 Correct 18 ms 14584 KB n=100
23 Correct 15 ms 14456 KB n=100
24 Correct 15 ms 14456 KB n=100
25 Correct 15 ms 14456 KB n=100
26 Correct 15 ms 14456 KB n=12
27 Correct 15 ms 14456 KB n=100
28 Correct 16 ms 14584 KB n=500
29 Correct 16 ms 14492 KB n=500
30 Correct 16 ms 14584 KB n=500
31 Correct 15 ms 14588 KB n=500
32 Correct 16 ms 14584 KB n=500
33 Correct 15 ms 14584 KB n=500
34 Correct 16 ms 14624 KB n=500
35 Correct 15 ms 14584 KB n=500
36 Correct 15 ms 14584 KB n=500
37 Correct 15 ms 14584 KB n=500
38 Correct 15 ms 14584 KB n=500
39 Correct 15 ms 14584 KB n=500
40 Correct 15 ms 14584 KB n=500
41 Correct 15 ms 14584 KB n=500
42 Correct 16 ms 14584 KB n=500
43 Correct 16 ms 14584 KB n=500
44 Correct 16 ms 14584 KB n=500
45 Correct 14 ms 14584 KB n=500
46 Correct 16 ms 14584 KB n=500
47 Correct 15 ms 14584 KB n=500
48 Correct 15 ms 14584 KB n=500
49 Correct 15 ms 14584 KB n=500
50 Correct 16 ms 14584 KB n=500
51 Correct 16 ms 14584 KB n=500
52 Correct 15 ms 14584 KB n=500
53 Correct 15 ms 14584 KB n=500
54 Correct 15 ms 14584 KB n=500
55 Correct 15 ms 14456 KB n=278
56 Correct 15 ms 14584 KB n=500
57 Correct 15 ms 14584 KB n=500
58 Correct 16 ms 14584 KB n=500
59 Correct 20 ms 14952 KB n=2000
60 Correct 18 ms 15052 KB n=2000
61 Correct 19 ms 14972 KB n=2000
62 Correct 19 ms 14968 KB n=2000
63 Correct 19 ms 14948 KB n=2000
64 Correct 20 ms 14908 KB n=2000
65 Correct 20 ms 14948 KB n=2000
66 Correct 19 ms 14968 KB n=2000
67 Correct 20 ms 14968 KB n=2000
68 Correct 19 ms 14968 KB n=2000
69 Correct 18 ms 14968 KB n=2000
70 Correct 18 ms 14968 KB n=2000
71 Correct 18 ms 14968 KB n=2000
72 Correct 18 ms 14968 KB n=2000
73 Correct 18 ms 14968 KB n=2000
74 Correct 19 ms 14968 KB n=1844
75 Correct 18 ms 14968 KB n=2000
76 Correct 19 ms 14968 KB n=2000
77 Correct 19 ms 14840 KB n=2000
78 Correct 19 ms 14844 KB n=2000
79 Correct 20 ms 14968 KB n=2000
80 Correct 19 ms 14968 KB n=2000
81 Correct 19 ms 14968 KB n=2000
82 Correct 19 ms 14968 KB n=2000
83 Correct 19 ms 14968 KB n=2000
84 Correct 19 ms 14968 KB n=2000
85 Correct 19 ms 14968 KB n=2000
86 Correct 19 ms 14968 KB n=2000
87 Correct 20 ms 14968 KB n=2000
88 Correct 18 ms 14968 KB n=2000
89 Correct 19 ms 14968 KB n=2000
90 Correct 18 ms 15096 KB n=2000
91 Correct 18 ms 14968 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 15 ms 14456 KB n=5
2 Correct 15 ms 14456 KB n=100
3 Correct 15 ms 14456 KB n=100
4 Correct 15 ms 14456 KB n=100
5 Correct 14 ms 14456 KB n=100
6 Correct 15 ms 14456 KB n=100
7 Correct 15 ms 14456 KB n=100
8 Correct 15 ms 14456 KB n=100
9 Correct 15 ms 14456 KB n=100
10 Correct 15 ms 14460 KB n=100
11 Correct 15 ms 14456 KB n=100
12 Correct 15 ms 14456 KB n=100
13 Correct 15 ms 14456 KB n=100
14 Correct 15 ms 14456 KB n=100
15 Correct 15 ms 14456 KB n=100
16 Correct 17 ms 14456 KB n=100
17 Correct 14 ms 14456 KB n=100
18 Correct 15 ms 14456 KB n=100
19 Correct 15 ms 14456 KB n=100
20 Correct 15 ms 14456 KB n=100
21 Correct 15 ms 14456 KB n=100
22 Correct 18 ms 14584 KB n=100
23 Correct 15 ms 14456 KB n=100
24 Correct 15 ms 14456 KB n=100
25 Correct 15 ms 14456 KB n=100
26 Correct 15 ms 14456 KB n=12
27 Correct 15 ms 14456 KB n=100
28 Correct 16 ms 14584 KB n=500
29 Correct 16 ms 14492 KB n=500
30 Correct 16 ms 14584 KB n=500
31 Correct 15 ms 14588 KB n=500
32 Correct 16 ms 14584 KB n=500
33 Correct 15 ms 14584 KB n=500
34 Correct 16 ms 14624 KB n=500
35 Correct 15 ms 14584 KB n=500
36 Correct 15 ms 14584 KB n=500
37 Correct 15 ms 14584 KB n=500
38 Correct 15 ms 14584 KB n=500
39 Correct 15 ms 14584 KB n=500
40 Correct 15 ms 14584 KB n=500
41 Correct 15 ms 14584 KB n=500
42 Correct 16 ms 14584 KB n=500
43 Correct 16 ms 14584 KB n=500
44 Correct 16 ms 14584 KB n=500
45 Correct 14 ms 14584 KB n=500
46 Correct 16 ms 14584 KB n=500
47 Correct 15 ms 14584 KB n=500
48 Correct 15 ms 14584 KB n=500
49 Correct 15 ms 14584 KB n=500
50 Correct 16 ms 14584 KB n=500
51 Correct 16 ms 14584 KB n=500
52 Correct 15 ms 14584 KB n=500
53 Correct 15 ms 14584 KB n=500
54 Correct 15 ms 14584 KB n=500
55 Correct 15 ms 14456 KB n=278
56 Correct 15 ms 14584 KB n=500
57 Correct 15 ms 14584 KB n=500
58 Correct 16 ms 14584 KB n=500
59 Correct 20 ms 14952 KB n=2000
60 Correct 18 ms 15052 KB n=2000
61 Correct 19 ms 14972 KB n=2000
62 Correct 19 ms 14968 KB n=2000
63 Correct 19 ms 14948 KB n=2000
64 Correct 20 ms 14908 KB n=2000
65 Correct 20 ms 14948 KB n=2000
66 Correct 19 ms 14968 KB n=2000
67 Correct 20 ms 14968 KB n=2000
68 Correct 19 ms 14968 KB n=2000
69 Correct 18 ms 14968 KB n=2000
70 Correct 18 ms 14968 KB n=2000
71 Correct 18 ms 14968 KB n=2000
72 Correct 18 ms 14968 KB n=2000
73 Correct 18 ms 14968 KB n=2000
74 Correct 19 ms 14968 KB n=1844
75 Correct 18 ms 14968 KB n=2000
76 Correct 19 ms 14968 KB n=2000
77 Correct 19 ms 14840 KB n=2000
78 Correct 19 ms 14844 KB n=2000
79 Correct 20 ms 14968 KB n=2000
80 Correct 19 ms 14968 KB n=2000
81 Correct 19 ms 14968 KB n=2000
82 Correct 19 ms 14968 KB n=2000
83 Correct 19 ms 14968 KB n=2000
84 Correct 19 ms 14968 KB n=2000
85 Correct 19 ms 14968 KB n=2000
86 Correct 19 ms 14968 KB n=2000
87 Correct 20 ms 14968 KB n=2000
88 Correct 18 ms 14968 KB n=2000
89 Correct 19 ms 14968 KB n=2000
90 Correct 18 ms 15096 KB n=2000
91 Correct 18 ms 14968 KB n=2000
92 Correct 994 ms 65212 KB n=200000
93 Correct 1080 ms 70236 KB n=200000
94 Correct 748 ms 73592 KB n=200000
95 Correct 994 ms 65088 KB n=200000
96 Correct 952 ms 65032 KB n=200000
97 Correct 1105 ms 69240 KB n=200000
98 Correct 970 ms 65256 KB n=200000
99 Correct 1116 ms 65400 KB n=200000
100 Correct 960 ms 65008 KB n=200000
101 Correct 728 ms 74736 KB n=200000
102 Correct 578 ms 66416 KB n=200000
103 Correct 585 ms 66296 KB n=200000
104 Correct 576 ms 66252 KB n=200000
105 Correct 586 ms 66808 KB n=200000
106 Correct 575 ms 66744 KB n=200000
107 Correct 579 ms 66640 KB n=200000
108 Correct 968 ms 65144 KB n=200000
109 Correct 975 ms 65288 KB n=200000
110 Correct 994 ms 65172 KB n=200000
111 Correct 943 ms 64540 KB n=200000
112 Correct 732 ms 73724 KB n=200000
113 Correct 1056 ms 69228 KB n=200000
114 Correct 942 ms 64516 KB n=200000
115 Correct 1350 ms 67192 KB n=200000
116 Correct 959 ms 65204 KB n=200000
117 Correct 716 ms 74148 KB n=200000
118 Correct 1208 ms 67996 KB n=200000
119 Correct 962 ms 65296 KB n=200000
120 Correct 702 ms 73804 KB n=200000
121 Correct 710 ms 73664 KB n=200000
122 Correct 715 ms 73940 KB n=200000
123 Correct 652 ms 66468 KB n=200000
124 Correct 237 ms 29432 KB n=25264