Submission #424678

# Submission time Handle Problem Language Result Execution time Memory
424678 2021-06-12T09:04:25 Z cpp219 Birthday gift (IZhO18_treearray) C++14
100 / 100
1499 ms 110664 KB
#pragma GCC optimization "O2"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")

#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 2e5 + 9;
const ll inf = 1e9 + 7;
const ll Log2 = 21;
typedef pair<ll,ll> LL;
vector<ll> g[N];
ll n,m,Q,x,y,a[N],lca[N];
ll par[N][Log2],d[N];
set<ll> fath[N],place[N];
void DFS(ll u,ll p){
    for (ll i = 1;i < Log2;i++) if ((1 << i) <= d[u])
        par[u][i] = par[par[u][i - 1]][i - 1];
    for (auto i : g[u]){
        if (i == p) continue;
        par[i][0] = u; d[i] = d[u] + 1;
        DFS(i,u);
    }
}

ll LCA(ll u,ll v){
    if (d[u] > d[v]) swap(u,v);
    for (ll i = Log2 - 1;i >= 0;i--) if ((1 << i) <= d[v] && d[par[v][i]] >= d[u])
        v = par[v][i];
    if (u == v) return u;
    for (ll i = Log2 - 1;i >= 0;i--) if (par[u][i] != par[v][i])
        u = par[u][i],v = par[v][i];
    return par[v][0];
}

ll type,pos,v,l,r;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define task "tst"
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    cin>>n>>m>>Q;
    for (ll i = 1;i < n;i++){
        cin>>x>>y;
        g[x].push_back(y); g[y].push_back(x);
    }
    DFS(1,0);
    for (ll i = 1;i <= m;i++) place[i].insert(inf),fath[i].insert(inf);
    for (ll i = 1;i <= m;i++) cin>>a[i],place[a[i]].insert(i);
    for (ll i = 1;i < m;i++) lca[i] = LCA(a[i],a[i + 1]),fath[lca[i]].insert(i);
    while(Q--){
        cin>>type;
        if (type == 1){
            cin>>pos>>v;
            place[a[pos]].erase(pos); fath[lca[pos]].erase(pos); fath[lca[pos - 1]].erase(pos - 1);
            a[pos] = v;
            lca[pos] = LCA(a[pos],a[pos + 1]);
            lca[pos - 1] = LCA(a[pos - 1],a[pos]);
            place[a[pos]].insert(pos); fath[lca[pos]].insert(pos); fath[lca[pos - 1]].insert(pos - 1);
        }
        else{
            cin>>l>>r>>v;
            ll now1 = *fath[v].lower_bound(l),now2 = *place[v].lower_bound(l);
            if (now2 <= r) cout<<now2<<" "<<now2;
            else if (now1 < r) cout<<now1<<" "<<now1 + 1;
            else cout<<-1<<" "<<-1; cout<<"\n";
        }
    }
}

Compilation message

treearray.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization "O2"
      | 
treearray.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
treearray.cpp: In function 'int main()':
treearray.cpp:72:13: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
   72 |             else cout<<-1<<" "<<-1; cout<<"\n";
      |             ^~~~
treearray.cpp:72:37: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
   72 |             else cout<<-1<<" "<<-1; cout<<"\n";
      |                                     ^~~~
treearray.cpp:45:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23764 KB n=5
2 Correct 14 ms 23740 KB n=100
3 Correct 14 ms 23764 KB n=100
4 Correct 14 ms 23788 KB n=100
5 Correct 14 ms 23808 KB n=100
6 Correct 14 ms 23756 KB n=100
7 Correct 14 ms 23756 KB n=100
8 Correct 13 ms 23756 KB n=100
9 Correct 14 ms 23812 KB n=100
10 Correct 14 ms 23756 KB n=100
11 Correct 15 ms 23812 KB n=100
12 Correct 14 ms 23756 KB n=100
13 Correct 15 ms 23752 KB n=100
14 Correct 14 ms 23756 KB n=100
15 Correct 14 ms 23852 KB n=100
16 Correct 14 ms 23812 KB n=100
17 Correct 14 ms 23840 KB n=100
18 Correct 15 ms 23756 KB n=100
19 Correct 16 ms 23804 KB n=100
20 Correct 14 ms 23784 KB n=100
21 Correct 17 ms 23756 KB n=100
22 Correct 14 ms 23756 KB n=100
23 Correct 14 ms 23800 KB n=100
24 Correct 14 ms 23756 KB n=100
25 Correct 14 ms 23756 KB n=100
26 Correct 16 ms 23756 KB n=12
27 Correct 14 ms 23816 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23764 KB n=5
2 Correct 14 ms 23740 KB n=100
3 Correct 14 ms 23764 KB n=100
4 Correct 14 ms 23788 KB n=100
5 Correct 14 ms 23808 KB n=100
6 Correct 14 ms 23756 KB n=100
7 Correct 14 ms 23756 KB n=100
8 Correct 13 ms 23756 KB n=100
9 Correct 14 ms 23812 KB n=100
10 Correct 14 ms 23756 KB n=100
11 Correct 15 ms 23812 KB n=100
12 Correct 14 ms 23756 KB n=100
13 Correct 15 ms 23752 KB n=100
14 Correct 14 ms 23756 KB n=100
15 Correct 14 ms 23852 KB n=100
16 Correct 14 ms 23812 KB n=100
17 Correct 14 ms 23840 KB n=100
18 Correct 15 ms 23756 KB n=100
19 Correct 16 ms 23804 KB n=100
20 Correct 14 ms 23784 KB n=100
21 Correct 17 ms 23756 KB n=100
22 Correct 14 ms 23756 KB n=100
23 Correct 14 ms 23800 KB n=100
24 Correct 14 ms 23756 KB n=100
25 Correct 14 ms 23756 KB n=100
26 Correct 16 ms 23756 KB n=12
27 Correct 14 ms 23816 KB n=100
28 Correct 14 ms 23924 KB n=500
29 Correct 15 ms 24012 KB n=500
30 Correct 15 ms 23944 KB n=500
31 Correct 15 ms 23976 KB n=500
32 Correct 15 ms 23924 KB n=500
33 Correct 15 ms 23884 KB n=500
34 Correct 14 ms 23884 KB n=500
35 Correct 14 ms 24012 KB n=500
36 Correct 14 ms 23864 KB n=500
37 Correct 15 ms 23884 KB n=500
38 Correct 15 ms 23948 KB n=500
39 Correct 14 ms 23956 KB n=500
40 Correct 14 ms 23952 KB n=500
41 Correct 14 ms 23908 KB n=500
42 Correct 15 ms 23884 KB n=500
43 Correct 15 ms 23944 KB n=500
44 Correct 15 ms 23884 KB n=500
45 Correct 18 ms 23944 KB n=500
46 Correct 14 ms 24016 KB n=500
47 Correct 15 ms 23924 KB n=500
48 Correct 15 ms 23948 KB n=500
49 Correct 14 ms 24012 KB n=500
50 Correct 15 ms 23952 KB n=500
51 Correct 15 ms 24012 KB n=500
52 Correct 15 ms 24012 KB n=500
53 Correct 15 ms 23912 KB n=500
54 Correct 15 ms 23944 KB n=500
55 Correct 14 ms 23884 KB n=278
56 Correct 15 ms 23932 KB n=500
57 Correct 15 ms 23932 KB n=500
58 Correct 15 ms 23952 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23764 KB n=5
2 Correct 14 ms 23740 KB n=100
3 Correct 14 ms 23764 KB n=100
4 Correct 14 ms 23788 KB n=100
5 Correct 14 ms 23808 KB n=100
6 Correct 14 ms 23756 KB n=100
7 Correct 14 ms 23756 KB n=100
8 Correct 13 ms 23756 KB n=100
9 Correct 14 ms 23812 KB n=100
10 Correct 14 ms 23756 KB n=100
11 Correct 15 ms 23812 KB n=100
12 Correct 14 ms 23756 KB n=100
13 Correct 15 ms 23752 KB n=100
14 Correct 14 ms 23756 KB n=100
15 Correct 14 ms 23852 KB n=100
16 Correct 14 ms 23812 KB n=100
17 Correct 14 ms 23840 KB n=100
18 Correct 15 ms 23756 KB n=100
19 Correct 16 ms 23804 KB n=100
20 Correct 14 ms 23784 KB n=100
21 Correct 17 ms 23756 KB n=100
22 Correct 14 ms 23756 KB n=100
23 Correct 14 ms 23800 KB n=100
24 Correct 14 ms 23756 KB n=100
25 Correct 14 ms 23756 KB n=100
26 Correct 16 ms 23756 KB n=12
27 Correct 14 ms 23816 KB n=100
28 Correct 14 ms 23924 KB n=500
29 Correct 15 ms 24012 KB n=500
30 Correct 15 ms 23944 KB n=500
31 Correct 15 ms 23976 KB n=500
32 Correct 15 ms 23924 KB n=500
33 Correct 15 ms 23884 KB n=500
34 Correct 14 ms 23884 KB n=500
35 Correct 14 ms 24012 KB n=500
36 Correct 14 ms 23864 KB n=500
37 Correct 15 ms 23884 KB n=500
38 Correct 15 ms 23948 KB n=500
39 Correct 14 ms 23956 KB n=500
40 Correct 14 ms 23952 KB n=500
41 Correct 14 ms 23908 KB n=500
42 Correct 15 ms 23884 KB n=500
43 Correct 15 ms 23944 KB n=500
44 Correct 15 ms 23884 KB n=500
45 Correct 18 ms 23944 KB n=500
46 Correct 14 ms 24016 KB n=500
47 Correct 15 ms 23924 KB n=500
48 Correct 15 ms 23948 KB n=500
49 Correct 14 ms 24012 KB n=500
50 Correct 15 ms 23952 KB n=500
51 Correct 15 ms 24012 KB n=500
52 Correct 15 ms 24012 KB n=500
53 Correct 15 ms 23912 KB n=500
54 Correct 15 ms 23944 KB n=500
55 Correct 14 ms 23884 KB n=278
56 Correct 15 ms 23932 KB n=500
57 Correct 15 ms 23932 KB n=500
58 Correct 15 ms 23952 KB n=500
59 Correct 17 ms 24524 KB n=2000
60 Correct 18 ms 24636 KB n=2000
61 Correct 19 ms 24512 KB n=2000
62 Correct 19 ms 24496 KB n=2000
63 Correct 20 ms 24396 KB n=2000
64 Correct 18 ms 24524 KB n=2000
65 Correct 17 ms 24456 KB n=2000
66 Correct 18 ms 24628 KB n=2000
67 Correct 18 ms 24460 KB n=2000
68 Correct 19 ms 24652 KB n=2000
69 Correct 17 ms 24504 KB n=2000
70 Correct 20 ms 24536 KB n=2000
71 Correct 17 ms 24496 KB n=2000
72 Correct 17 ms 24464 KB n=2000
73 Correct 20 ms 24524 KB n=2000
74 Correct 17 ms 24436 KB n=1844
75 Correct 17 ms 24512 KB n=2000
76 Correct 18 ms 24396 KB n=2000
77 Correct 19 ms 24464 KB n=2000
78 Correct 18 ms 24396 KB n=2000
79 Correct 19 ms 24508 KB n=2000
80 Correct 20 ms 24552 KB n=2000
81 Correct 18 ms 24520 KB n=2000
82 Correct 17 ms 24464 KB n=2000
83 Correct 18 ms 24524 KB n=2000
84 Correct 18 ms 24396 KB n=2000
85 Correct 18 ms 24524 KB n=2000
86 Correct 18 ms 24560 KB n=2000
87 Correct 17 ms 24520 KB n=2000
88 Correct 17 ms 24652 KB n=2000
89 Correct 17 ms 24652 KB n=2000
90 Correct 17 ms 24572 KB n=2000
91 Correct 17 ms 24416 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23764 KB n=5
2 Correct 14 ms 23740 KB n=100
3 Correct 14 ms 23764 KB n=100
4 Correct 14 ms 23788 KB n=100
5 Correct 14 ms 23808 KB n=100
6 Correct 14 ms 23756 KB n=100
7 Correct 14 ms 23756 KB n=100
8 Correct 13 ms 23756 KB n=100
9 Correct 14 ms 23812 KB n=100
10 Correct 14 ms 23756 KB n=100
11 Correct 15 ms 23812 KB n=100
12 Correct 14 ms 23756 KB n=100
13 Correct 15 ms 23752 KB n=100
14 Correct 14 ms 23756 KB n=100
15 Correct 14 ms 23852 KB n=100
16 Correct 14 ms 23812 KB n=100
17 Correct 14 ms 23840 KB n=100
18 Correct 15 ms 23756 KB n=100
19 Correct 16 ms 23804 KB n=100
20 Correct 14 ms 23784 KB n=100
21 Correct 17 ms 23756 KB n=100
22 Correct 14 ms 23756 KB n=100
23 Correct 14 ms 23800 KB n=100
24 Correct 14 ms 23756 KB n=100
25 Correct 14 ms 23756 KB n=100
26 Correct 16 ms 23756 KB n=12
27 Correct 14 ms 23816 KB n=100
28 Correct 14 ms 23924 KB n=500
29 Correct 15 ms 24012 KB n=500
30 Correct 15 ms 23944 KB n=500
31 Correct 15 ms 23976 KB n=500
32 Correct 15 ms 23924 KB n=500
33 Correct 15 ms 23884 KB n=500
34 Correct 14 ms 23884 KB n=500
35 Correct 14 ms 24012 KB n=500
36 Correct 14 ms 23864 KB n=500
37 Correct 15 ms 23884 KB n=500
38 Correct 15 ms 23948 KB n=500
39 Correct 14 ms 23956 KB n=500
40 Correct 14 ms 23952 KB n=500
41 Correct 14 ms 23908 KB n=500
42 Correct 15 ms 23884 KB n=500
43 Correct 15 ms 23944 KB n=500
44 Correct 15 ms 23884 KB n=500
45 Correct 18 ms 23944 KB n=500
46 Correct 14 ms 24016 KB n=500
47 Correct 15 ms 23924 KB n=500
48 Correct 15 ms 23948 KB n=500
49 Correct 14 ms 24012 KB n=500
50 Correct 15 ms 23952 KB n=500
51 Correct 15 ms 24012 KB n=500
52 Correct 15 ms 24012 KB n=500
53 Correct 15 ms 23912 KB n=500
54 Correct 15 ms 23944 KB n=500
55 Correct 14 ms 23884 KB n=278
56 Correct 15 ms 23932 KB n=500
57 Correct 15 ms 23932 KB n=500
58 Correct 15 ms 23952 KB n=500
59 Correct 17 ms 24524 KB n=2000
60 Correct 18 ms 24636 KB n=2000
61 Correct 19 ms 24512 KB n=2000
62 Correct 19 ms 24496 KB n=2000
63 Correct 20 ms 24396 KB n=2000
64 Correct 18 ms 24524 KB n=2000
65 Correct 17 ms 24456 KB n=2000
66 Correct 18 ms 24628 KB n=2000
67 Correct 18 ms 24460 KB n=2000
68 Correct 19 ms 24652 KB n=2000
69 Correct 17 ms 24504 KB n=2000
70 Correct 20 ms 24536 KB n=2000
71 Correct 17 ms 24496 KB n=2000
72 Correct 17 ms 24464 KB n=2000
73 Correct 20 ms 24524 KB n=2000
74 Correct 17 ms 24436 KB n=1844
75 Correct 17 ms 24512 KB n=2000
76 Correct 18 ms 24396 KB n=2000
77 Correct 19 ms 24464 KB n=2000
78 Correct 18 ms 24396 KB n=2000
79 Correct 19 ms 24508 KB n=2000
80 Correct 20 ms 24552 KB n=2000
81 Correct 18 ms 24520 KB n=2000
82 Correct 17 ms 24464 KB n=2000
83 Correct 18 ms 24524 KB n=2000
84 Correct 18 ms 24396 KB n=2000
85 Correct 18 ms 24524 KB n=2000
86 Correct 18 ms 24560 KB n=2000
87 Correct 17 ms 24520 KB n=2000
88 Correct 17 ms 24652 KB n=2000
89 Correct 17 ms 24652 KB n=2000
90 Correct 17 ms 24572 KB n=2000
91 Correct 17 ms 24416 KB n=2000
92 Correct 832 ms 94788 KB n=200000
93 Correct 1264 ms 102852 KB n=200000
94 Correct 1159 ms 108372 KB n=200000
95 Correct 854 ms 94736 KB n=200000
96 Correct 868 ms 94908 KB n=200000
97 Correct 1245 ms 101444 KB n=200000
98 Correct 851 ms 94864 KB n=200000
99 Correct 999 ms 94884 KB n=200000
100 Correct 881 ms 94872 KB n=200000
101 Correct 1127 ms 110664 KB n=200000
102 Correct 533 ms 95944 KB n=200000
103 Correct 604 ms 96064 KB n=200000
104 Correct 562 ms 95944 KB n=200000
105 Correct 566 ms 96356 KB n=200000
106 Correct 557 ms 96324 KB n=200000
107 Correct 577 ms 96284 KB n=200000
108 Correct 935 ms 94832 KB n=200000
109 Correct 971 ms 94824 KB n=200000
110 Correct 979 ms 94720 KB n=200000
111 Correct 937 ms 94252 KB n=200000
112 Correct 1257 ms 108828 KB n=200000
113 Correct 1456 ms 101328 KB n=200000
114 Correct 871 ms 94368 KB n=200000
115 Correct 1499 ms 97916 KB n=200000
116 Correct 858 ms 94904 KB n=200000
117 Correct 1169 ms 109556 KB n=200000
118 Correct 1213 ms 99544 KB n=200000
119 Correct 824 ms 94984 KB n=200000
120 Correct 1119 ms 109564 KB n=200000
121 Correct 1099 ms 109652 KB n=200000
122 Correct 1141 ms 110044 KB n=200000
123 Correct 605 ms 96100 KB n=200000
124 Correct 279 ms 48252 KB n=25264