Submission #74506

# Submission time Handle Problem Language Result Execution time Memory
74506 2018-09-02T16:11:08 Z win11905 Birthday gift (IZhO18_treearray) C++11
0 / 100
27 ms 24272 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5+5;

int n, m, q, A[N];
int par[N][18], dep[N];
vector<int> g[N];
set<int> pos[N], lca_pos[N];

void init_lca(int u, int p) {
    for(int i = 1; i < 18; ++i) par[u][i] = par[par[u][i-1]][i-1];
    for(int v : g[u]) if(v != p) par[v][0] = u, dep[v] = dep[u] + 1, init_lca(v, u);
}

int get_lca(int u, int v) {
    if(dep[u] < dep[v]) swap(u, v);
    for(int i = 17; ~i; --i) if(dep[par[u][i]] >= dep[v]) u = par[u][i];
    if(u == v) return u;
    for(int i = 17; ~i; --i) if(par[u][i] != par[v][i]) u = par[u][i], v = par[v][i];
    return par[u][0];
}

int main() {
    scanf("%d %d %d", &n, &m, &q);
    for(int i = 1, u, v; i < n; ++i) {
        scanf("%d %d", &u, &v);
        g[u].emplace_back(v), g[v].emplace_back(u);
    }
    for(int i = 1; i <= n; ++i) pos[i].emplace(n+1), lca_pos[i].emplace(n+1);
    init_lca(1, 0);
    for(int i = 1; i <= m; ++i) scanf("%d", A+i), pos[A[i]].emplace(i);
    for(int i = 1; i < m; ++i) lca_pos[get_lca(A[i], A[i+1])].emplace(i);
    for(int i = 0, tp, l, r, v; i < q; ++i) {
        scanf("%d", &tp);
        if(tp == 1) {
            scanf("%d %d", &tp, &v);
            pos[A[tp]].erase(tp);
            if(tp != 1) lca_pos[get_lca(A[tp], A[tp-1])].erase(tp-1);
            if(tp != m) lca_pos[get_lca(A[tp], A[tp+1])].erase(tp); 
            A[tp] = v;
            pos[A[tp]].emplace(tp);
            if(tp != 1) lca_pos[get_lca(A[tp], A[tp-1])].emplace(tp-1);
            if(tp != m) lca_pos[get_lca(A[tp], A[tp+1])].emplace(tp);
        } else {
            scanf("%d %d %d", &l, &r, &v);
            int a1 = *pos[v].lower_bound(l), a2 = *lca_pos[v].lower_bound(l);
            if(a1 <= r) printf("%d %d\n", a1, a1);
            else if(a2 < r) printf("%d %d\n", a2, a2+1);
            else puts("-1 -1");
        }
    } 
}

Compilation message

treearray.cpp: In function 'int main()':
treearray.cpp:25: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:27:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &u, &v);
         ~~~~~^~~~~~~~~~~~~~~~~
treearray.cpp:32:49: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i <= m; ++i) scanf("%d", A+i), pos[A[i]].emplace(i);
                                 ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
treearray.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &tp);
         ~~~~~^~~~~~~~~~~
treearray.cpp:37:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d %d", &tp, &v);
             ~~~~~^~~~~~~~~~~~~~~~~~
treearray.cpp:46:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d %d %d", &l, &r, &v);
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 21 ms 23800 KB n=5
2 Correct 22 ms 24064 KB n=100
3 Correct 22 ms 24064 KB n=100
4 Correct 24 ms 24064 KB n=100
5 Correct 22 ms 24064 KB n=100
6 Correct 21 ms 24064 KB n=100
7 Correct 21 ms 24064 KB n=100
8 Correct 22 ms 24064 KB n=100
9 Correct 21 ms 24080 KB n=100
10 Correct 22 ms 24080 KB n=100
11 Correct 27 ms 24084 KB n=100
12 Correct 20 ms 24092 KB n=100
13 Correct 23 ms 24092 KB n=100
14 Correct 22 ms 24096 KB n=100
15 Correct 21 ms 24100 KB n=100
16 Correct 22 ms 24100 KB n=100
17 Correct 23 ms 24108 KB n=100
18 Correct 22 ms 24216 KB n=100
19 Correct 22 ms 24216 KB n=100
20 Correct 23 ms 24216 KB n=100
21 Correct 20 ms 24216 KB n=100
22 Correct 20 ms 24216 KB n=100
23 Correct 22 ms 24216 KB n=100
24 Correct 24 ms 24216 KB n=100
25 Correct 21 ms 24216 KB n=100
26 Incorrect 21 ms 24272 KB Wrong output format.
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 23800 KB n=5
2 Correct 22 ms 24064 KB n=100
3 Correct 22 ms 24064 KB n=100
4 Correct 24 ms 24064 KB n=100
5 Correct 22 ms 24064 KB n=100
6 Correct 21 ms 24064 KB n=100
7 Correct 21 ms 24064 KB n=100
8 Correct 22 ms 24064 KB n=100
9 Correct 21 ms 24080 KB n=100
10 Correct 22 ms 24080 KB n=100
11 Correct 27 ms 24084 KB n=100
12 Correct 20 ms 24092 KB n=100
13 Correct 23 ms 24092 KB n=100
14 Correct 22 ms 24096 KB n=100
15 Correct 21 ms 24100 KB n=100
16 Correct 22 ms 24100 KB n=100
17 Correct 23 ms 24108 KB n=100
18 Correct 22 ms 24216 KB n=100
19 Correct 22 ms 24216 KB n=100
20 Correct 23 ms 24216 KB n=100
21 Correct 20 ms 24216 KB n=100
22 Correct 20 ms 24216 KB n=100
23 Correct 22 ms 24216 KB n=100
24 Correct 24 ms 24216 KB n=100
25 Correct 21 ms 24216 KB n=100
26 Incorrect 21 ms 24272 KB Wrong output format.
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 23800 KB n=5
2 Correct 22 ms 24064 KB n=100
3 Correct 22 ms 24064 KB n=100
4 Correct 24 ms 24064 KB n=100
5 Correct 22 ms 24064 KB n=100
6 Correct 21 ms 24064 KB n=100
7 Correct 21 ms 24064 KB n=100
8 Correct 22 ms 24064 KB n=100
9 Correct 21 ms 24080 KB n=100
10 Correct 22 ms 24080 KB n=100
11 Correct 27 ms 24084 KB n=100
12 Correct 20 ms 24092 KB n=100
13 Correct 23 ms 24092 KB n=100
14 Correct 22 ms 24096 KB n=100
15 Correct 21 ms 24100 KB n=100
16 Correct 22 ms 24100 KB n=100
17 Correct 23 ms 24108 KB n=100
18 Correct 22 ms 24216 KB n=100
19 Correct 22 ms 24216 KB n=100
20 Correct 23 ms 24216 KB n=100
21 Correct 20 ms 24216 KB n=100
22 Correct 20 ms 24216 KB n=100
23 Correct 22 ms 24216 KB n=100
24 Correct 24 ms 24216 KB n=100
25 Correct 21 ms 24216 KB n=100
26 Incorrect 21 ms 24272 KB Wrong output format.
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 23800 KB n=5
2 Correct 22 ms 24064 KB n=100
3 Correct 22 ms 24064 KB n=100
4 Correct 24 ms 24064 KB n=100
5 Correct 22 ms 24064 KB n=100
6 Correct 21 ms 24064 KB n=100
7 Correct 21 ms 24064 KB n=100
8 Correct 22 ms 24064 KB n=100
9 Correct 21 ms 24080 KB n=100
10 Correct 22 ms 24080 KB n=100
11 Correct 27 ms 24084 KB n=100
12 Correct 20 ms 24092 KB n=100
13 Correct 23 ms 24092 KB n=100
14 Correct 22 ms 24096 KB n=100
15 Correct 21 ms 24100 KB n=100
16 Correct 22 ms 24100 KB n=100
17 Correct 23 ms 24108 KB n=100
18 Correct 22 ms 24216 KB n=100
19 Correct 22 ms 24216 KB n=100
20 Correct 23 ms 24216 KB n=100
21 Correct 20 ms 24216 KB n=100
22 Correct 20 ms 24216 KB n=100
23 Correct 22 ms 24216 KB n=100
24 Correct 24 ms 24216 KB n=100
25 Correct 21 ms 24216 KB n=100
26 Incorrect 21 ms 24272 KB Wrong output format.
27 Halted 0 ms 0 KB -