Submission #443912

# Submission time Handle Problem Language Result Execution time Memory
443912 2021-07-12T11:44:50 Z NintsiChkhaidze Birthday gift (IZhO18_treearray) C++14
100 / 100
1929 ms 94640 KB
#include <iostream>
#include <set>
#include <vector>
#define pb push_back
using namespace std;
const int N = 200005; 
int a[N],dp[N],d[20][N],n;
vector <int> v[N];
multiset <int> A[N],B[N];
void dfs(int x,int par){
    dp[x] = dp[par] + 1;
    d[0][x] = par;
    for (int i = 0; i < v[x].size(); i++)
      if (v[x][i] != par) dfs(v[x][i],x);
}
int lca(int x,int y){
    if (dp[x] > dp[y]) swap(x,y);
    for (int i = 18; i >= 0; i--)
        if (dp[d[i][y]] >= dp[x]) y = d[i][y];
  
    if (x == y) return x;
    for (int i = 18; i >= 0; i--)
        if (d[i][x] != d[i][y]) x = d[i][x],y = d[i][y];
  
    return d[0][x];
}
void upd(int ind,bool val){
    if (!ind) return;
    int y = lca(a[ind],a[ind + 1]),x = a[ind]; 
    
    if (!val){
        A[x].erase(A[x].find(ind));
        B[y].erase(B[y].find(ind));
    }
    else{
        A[x].insert(ind);
        B[y].insert(ind);
    }
}
int main (){
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    int m,q;
    cin>>n>>m>>q;
    
    for (int i = 1; i < n; i++){
        int a,b;
        cin>>a>>b;
        v[a].pb(b),v[b].pb(a);
    }
    for (int i = 1; i <= m; i++)
        cin>>a[i];
 
    dfs(1,1);
    for (int j = 1; j <= 18; j++)
        for (int i = 1; i <= n; i++)
            d[j][i] = d[j - 1][d[j - 1][i]];
 
    a[m + 1] = 1;
    for (int i = 1; i <= m; i++)
      upd(i,1);
    
    for (int i = 1; i <= n; i++)
        A[i].insert(N),B[i].insert(N);
   
    while(q--){
        int tp;
        cin>>tp;
        if (tp == 1){
            int pos,val;
            cin>>pos>>val;
            upd(pos - 1, 0); upd(pos, 0);
            a[pos] = val;
            upd(pos - 1, 1),upd(pos, 1);
        }
        else{
            int l,r,val;
            cin>>l>>r>>val;
            int x = *A[val].lower_bound(l);
            int y = *B[val].lower_bound(l);
            
            if (y >= l && y < r) cout<<y<<" "<<y + 1<<"\n";
            else if (x >= l && x <= r) cout<<x<<" "<<x<<"\n";
            else cout<<-1<<" "<<-1<<"\n";
        }
    }
}

Compilation message

treearray.cpp: In function 'void dfs(int, int)':
treearray.cpp:13:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for (int i = 0; i < v[x].size(); i++)
      |                     ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23884 KB n=5
2 Correct 13 ms 23936 KB n=100
3 Correct 13 ms 23916 KB n=100
4 Correct 14 ms 23840 KB n=100
5 Correct 13 ms 23932 KB n=100
6 Correct 13 ms 23884 KB n=100
7 Correct 13 ms 23840 KB n=100
8 Correct 13 ms 23884 KB n=100
9 Correct 13 ms 23928 KB n=100
10 Correct 14 ms 23936 KB n=100
11 Correct 13 ms 23884 KB n=100
12 Correct 13 ms 23940 KB n=100
13 Correct 13 ms 23936 KB n=100
14 Correct 15 ms 23884 KB n=100
15 Correct 13 ms 23884 KB n=100
16 Correct 13 ms 23932 KB n=100
17 Correct 15 ms 23884 KB n=100
18 Correct 13 ms 23884 KB n=100
19 Correct 16 ms 23828 KB n=100
20 Correct 13 ms 23884 KB n=100
21 Correct 15 ms 23884 KB n=100
22 Correct 13 ms 23884 KB n=100
23 Correct 14 ms 23852 KB n=100
24 Correct 13 ms 23920 KB n=100
25 Correct 13 ms 23904 KB n=100
26 Correct 13 ms 23884 KB n=12
27 Correct 13 ms 23936 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23884 KB n=5
2 Correct 13 ms 23936 KB n=100
3 Correct 13 ms 23916 KB n=100
4 Correct 14 ms 23840 KB n=100
5 Correct 13 ms 23932 KB n=100
6 Correct 13 ms 23884 KB n=100
7 Correct 13 ms 23840 KB n=100
8 Correct 13 ms 23884 KB n=100
9 Correct 13 ms 23928 KB n=100
10 Correct 14 ms 23936 KB n=100
11 Correct 13 ms 23884 KB n=100
12 Correct 13 ms 23940 KB n=100
13 Correct 13 ms 23936 KB n=100
14 Correct 15 ms 23884 KB n=100
15 Correct 13 ms 23884 KB n=100
16 Correct 13 ms 23932 KB n=100
17 Correct 15 ms 23884 KB n=100
18 Correct 13 ms 23884 KB n=100
19 Correct 16 ms 23828 KB n=100
20 Correct 13 ms 23884 KB n=100
21 Correct 15 ms 23884 KB n=100
22 Correct 13 ms 23884 KB n=100
23 Correct 14 ms 23852 KB n=100
24 Correct 13 ms 23920 KB n=100
25 Correct 13 ms 23904 KB n=100
26 Correct 13 ms 23884 KB n=12
27 Correct 13 ms 23936 KB n=100
28 Correct 16 ms 24012 KB n=500
29 Correct 14 ms 24012 KB n=500
30 Correct 14 ms 24012 KB n=500
31 Correct 14 ms 24016 KB n=500
32 Correct 14 ms 24072 KB n=500
33 Correct 15 ms 24076 KB n=500
34 Correct 16 ms 24076 KB n=500
35 Correct 15 ms 24012 KB n=500
36 Correct 16 ms 24012 KB n=500
37 Correct 14 ms 24080 KB n=500
38 Correct 15 ms 24012 KB n=500
39 Correct 15 ms 24044 KB n=500
40 Correct 17 ms 24012 KB n=500
41 Correct 17 ms 23964 KB n=500
42 Correct 17 ms 24052 KB n=500
43 Correct 16 ms 24144 KB n=500
44 Correct 15 ms 24068 KB n=500
45 Correct 14 ms 24072 KB n=500
46 Correct 14 ms 24076 KB n=500
47 Correct 14 ms 24028 KB n=500
48 Correct 14 ms 24012 KB n=500
49 Correct 17 ms 23996 KB n=500
50 Correct 14 ms 24044 KB n=500
51 Correct 14 ms 24072 KB n=500
52 Correct 13 ms 24012 KB n=500
53 Correct 16 ms 23936 KB n=500
54 Correct 14 ms 24076 KB n=500
55 Correct 16 ms 23996 KB n=278
56 Correct 14 ms 24012 KB n=500
57 Correct 14 ms 24012 KB n=500
58 Correct 14 ms 24080 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23884 KB n=5
2 Correct 13 ms 23936 KB n=100
3 Correct 13 ms 23916 KB n=100
4 Correct 14 ms 23840 KB n=100
5 Correct 13 ms 23932 KB n=100
6 Correct 13 ms 23884 KB n=100
7 Correct 13 ms 23840 KB n=100
8 Correct 13 ms 23884 KB n=100
9 Correct 13 ms 23928 KB n=100
10 Correct 14 ms 23936 KB n=100
11 Correct 13 ms 23884 KB n=100
12 Correct 13 ms 23940 KB n=100
13 Correct 13 ms 23936 KB n=100
14 Correct 15 ms 23884 KB n=100
15 Correct 13 ms 23884 KB n=100
16 Correct 13 ms 23932 KB n=100
17 Correct 15 ms 23884 KB n=100
18 Correct 13 ms 23884 KB n=100
19 Correct 16 ms 23828 KB n=100
20 Correct 13 ms 23884 KB n=100
21 Correct 15 ms 23884 KB n=100
22 Correct 13 ms 23884 KB n=100
23 Correct 14 ms 23852 KB n=100
24 Correct 13 ms 23920 KB n=100
25 Correct 13 ms 23904 KB n=100
26 Correct 13 ms 23884 KB n=12
27 Correct 13 ms 23936 KB n=100
28 Correct 16 ms 24012 KB n=500
29 Correct 14 ms 24012 KB n=500
30 Correct 14 ms 24012 KB n=500
31 Correct 14 ms 24016 KB n=500
32 Correct 14 ms 24072 KB n=500
33 Correct 15 ms 24076 KB n=500
34 Correct 16 ms 24076 KB n=500
35 Correct 15 ms 24012 KB n=500
36 Correct 16 ms 24012 KB n=500
37 Correct 14 ms 24080 KB n=500
38 Correct 15 ms 24012 KB n=500
39 Correct 15 ms 24044 KB n=500
40 Correct 17 ms 24012 KB n=500
41 Correct 17 ms 23964 KB n=500
42 Correct 17 ms 24052 KB n=500
43 Correct 16 ms 24144 KB n=500
44 Correct 15 ms 24068 KB n=500
45 Correct 14 ms 24072 KB n=500
46 Correct 14 ms 24076 KB n=500
47 Correct 14 ms 24028 KB n=500
48 Correct 14 ms 24012 KB n=500
49 Correct 17 ms 23996 KB n=500
50 Correct 14 ms 24044 KB n=500
51 Correct 14 ms 24072 KB n=500
52 Correct 13 ms 24012 KB n=500
53 Correct 16 ms 23936 KB n=500
54 Correct 14 ms 24076 KB n=500
55 Correct 16 ms 23996 KB n=278
56 Correct 14 ms 24012 KB n=500
57 Correct 14 ms 24012 KB n=500
58 Correct 14 ms 24080 KB n=500
59 Correct 19 ms 24532 KB n=2000
60 Correct 18 ms 24656 KB n=2000
61 Correct 18 ms 24524 KB n=2000
62 Correct 18 ms 24604 KB n=2000
63 Correct 18 ms 24588 KB n=2000
64 Correct 18 ms 24588 KB n=2000
65 Correct 18 ms 24524 KB n=2000
66 Correct 17 ms 24640 KB n=2000
67 Correct 21 ms 24636 KB n=2000
68 Correct 18 ms 24544 KB n=2000
69 Correct 16 ms 24524 KB n=2000
70 Correct 16 ms 24524 KB n=2000
71 Correct 17 ms 24524 KB n=2000
72 Correct 17 ms 24584 KB n=2000
73 Correct 19 ms 24524 KB n=2000
74 Correct 17 ms 24544 KB n=1844
75 Correct 16 ms 24504 KB n=2000
76 Correct 22 ms 24576 KB n=2000
77 Correct 19 ms 24524 KB n=2000
78 Correct 18 ms 24588 KB n=2000
79 Correct 18 ms 24524 KB n=2000
80 Correct 18 ms 24592 KB n=2000
81 Correct 21 ms 24544 KB n=2000
82 Correct 18 ms 24576 KB n=2000
83 Correct 18 ms 24588 KB n=2000
84 Correct 20 ms 24592 KB n=2000
85 Correct 18 ms 24604 KB n=2000
86 Correct 18 ms 24556 KB n=2000
87 Correct 18 ms 24584 KB n=2000
88 Correct 17 ms 24652 KB n=2000
89 Correct 19 ms 24644 KB n=2000
90 Correct 18 ms 24652 KB n=2000
91 Correct 17 ms 24524 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23884 KB n=5
2 Correct 13 ms 23936 KB n=100
3 Correct 13 ms 23916 KB n=100
4 Correct 14 ms 23840 KB n=100
5 Correct 13 ms 23932 KB n=100
6 Correct 13 ms 23884 KB n=100
7 Correct 13 ms 23840 KB n=100
8 Correct 13 ms 23884 KB n=100
9 Correct 13 ms 23928 KB n=100
10 Correct 14 ms 23936 KB n=100
11 Correct 13 ms 23884 KB n=100
12 Correct 13 ms 23940 KB n=100
13 Correct 13 ms 23936 KB n=100
14 Correct 15 ms 23884 KB n=100
15 Correct 13 ms 23884 KB n=100
16 Correct 13 ms 23932 KB n=100
17 Correct 15 ms 23884 KB n=100
18 Correct 13 ms 23884 KB n=100
19 Correct 16 ms 23828 KB n=100
20 Correct 13 ms 23884 KB n=100
21 Correct 15 ms 23884 KB n=100
22 Correct 13 ms 23884 KB n=100
23 Correct 14 ms 23852 KB n=100
24 Correct 13 ms 23920 KB n=100
25 Correct 13 ms 23904 KB n=100
26 Correct 13 ms 23884 KB n=12
27 Correct 13 ms 23936 KB n=100
28 Correct 16 ms 24012 KB n=500
29 Correct 14 ms 24012 KB n=500
30 Correct 14 ms 24012 KB n=500
31 Correct 14 ms 24016 KB n=500
32 Correct 14 ms 24072 KB n=500
33 Correct 15 ms 24076 KB n=500
34 Correct 16 ms 24076 KB n=500
35 Correct 15 ms 24012 KB n=500
36 Correct 16 ms 24012 KB n=500
37 Correct 14 ms 24080 KB n=500
38 Correct 15 ms 24012 KB n=500
39 Correct 15 ms 24044 KB n=500
40 Correct 17 ms 24012 KB n=500
41 Correct 17 ms 23964 KB n=500
42 Correct 17 ms 24052 KB n=500
43 Correct 16 ms 24144 KB n=500
44 Correct 15 ms 24068 KB n=500
45 Correct 14 ms 24072 KB n=500
46 Correct 14 ms 24076 KB n=500
47 Correct 14 ms 24028 KB n=500
48 Correct 14 ms 24012 KB n=500
49 Correct 17 ms 23996 KB n=500
50 Correct 14 ms 24044 KB n=500
51 Correct 14 ms 24072 KB n=500
52 Correct 13 ms 24012 KB n=500
53 Correct 16 ms 23936 KB n=500
54 Correct 14 ms 24076 KB n=500
55 Correct 16 ms 23996 KB n=278
56 Correct 14 ms 24012 KB n=500
57 Correct 14 ms 24012 KB n=500
58 Correct 14 ms 24080 KB n=500
59 Correct 19 ms 24532 KB n=2000
60 Correct 18 ms 24656 KB n=2000
61 Correct 18 ms 24524 KB n=2000
62 Correct 18 ms 24604 KB n=2000
63 Correct 18 ms 24588 KB n=2000
64 Correct 18 ms 24588 KB n=2000
65 Correct 18 ms 24524 KB n=2000
66 Correct 17 ms 24640 KB n=2000
67 Correct 21 ms 24636 KB n=2000
68 Correct 18 ms 24544 KB n=2000
69 Correct 16 ms 24524 KB n=2000
70 Correct 16 ms 24524 KB n=2000
71 Correct 17 ms 24524 KB n=2000
72 Correct 17 ms 24584 KB n=2000
73 Correct 19 ms 24524 KB n=2000
74 Correct 17 ms 24544 KB n=1844
75 Correct 16 ms 24504 KB n=2000
76 Correct 22 ms 24576 KB n=2000
77 Correct 19 ms 24524 KB n=2000
78 Correct 18 ms 24588 KB n=2000
79 Correct 18 ms 24524 KB n=2000
80 Correct 18 ms 24592 KB n=2000
81 Correct 21 ms 24544 KB n=2000
82 Correct 18 ms 24576 KB n=2000
83 Correct 18 ms 24588 KB n=2000
84 Correct 20 ms 24592 KB n=2000
85 Correct 18 ms 24604 KB n=2000
86 Correct 18 ms 24556 KB n=2000
87 Correct 18 ms 24584 KB n=2000
88 Correct 17 ms 24652 KB n=2000
89 Correct 19 ms 24644 KB n=2000
90 Correct 18 ms 24652 KB n=2000
91 Correct 17 ms 24524 KB n=2000
92 Correct 1811 ms 86388 KB n=200000
93 Correct 1729 ms 89908 KB n=200000
94 Correct 1589 ms 93256 KB n=200000
95 Correct 1631 ms 86140 KB n=200000
96 Correct 1724 ms 86208 KB n=200000
97 Correct 1857 ms 89196 KB n=200000
98 Correct 1742 ms 86116 KB n=200000
99 Correct 1778 ms 85748 KB n=200000
100 Correct 1713 ms 86224 KB n=200000
101 Correct 1593 ms 94640 KB n=200000
102 Correct 769 ms 87216 KB n=200000
103 Correct 744 ms 87068 KB n=200000
104 Correct 760 ms 87148 KB n=200000
105 Correct 756 ms 86876 KB n=200000
106 Correct 722 ms 87032 KB n=200000
107 Correct 719 ms 86852 KB n=200000
108 Correct 1563 ms 85880 KB n=200000
109 Correct 1681 ms 85828 KB n=200000
110 Correct 1605 ms 85856 KB n=200000
111 Correct 1573 ms 86104 KB n=200000
112 Correct 1531 ms 93704 KB n=200000
113 Correct 1681 ms 88928 KB n=200000
114 Correct 1509 ms 85988 KB n=200000
115 Correct 1929 ms 86920 KB n=200000
116 Correct 1600 ms 85760 KB n=200000
117 Correct 1595 ms 93960 KB n=200000
118 Correct 1868 ms 87904 KB n=200000
119 Correct 1687 ms 85796 KB n=200000
120 Correct 1680 ms 94192 KB n=200000
121 Correct 1414 ms 94260 KB n=200000
122 Correct 1578 ms 94624 KB n=200000
123 Correct 758 ms 86316 KB n=200000
124 Correct 282 ms 39236 KB n=25264