답안 #683274

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
683274 2023-01-18T05:41:02 Z Dima_Borchuk Birthday gift (IZhO18_treearray) C++17
30 / 100
4000 ms 7892 KB
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) int32_t(x.size())
#define pii pair<int,int>
#include<bits/stdc++.h>
#define ld long double
#define ll long long
#define _ << ' ' <<
//#define int ll

using namespace std;
using namespace __gnu_pbds;

const int p = 1009;
const int L = 20;
const int N = (int)3e5 + 5;
const int INF = (int)2e18 + 6;
const int mod = (int)998244353;

mt19937 gen(chrono::system_clock::now().time_since_epoch().count());

template <typename T>
using ordered_set = tree < T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update >;

int a[N], up[N][20], tin[N], tout[N];

vector < int > g[N];

int timer = 0;

void dfs(int v, int anc) {
    tin[v] = ++timer;
    up[v][0] = anc;
    for (int i = 1; i < 20; i++) {
        up[v][i] = up[up[v][i - 1]][i - 1];
    }

    for (auto to : g[v]) {
        if (to == anc) continue;
        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 = 19; i >= 0; i--) {
        if (up[a][i] && !upper(up[a][i], b)) {
            a = up[a][i];
        }
    }
    return up[a][0];
}

int32_t main() {
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif // LOCAL

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n, m, q;
    cin >> n >> m >> q;
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for (int i = 1; i <= m; i++) {
        cin >> a[i];
    }

    dfs(1, 0);

    while (q--) {
        int type;
        cin >> type;
        if (type == 2) {
            int l, r, v;
            cin >> l >> r >> v;
            pii ans = { -1, -1 };
            for (int i = l; i <= r; i++) {
                if (a[i] == v) {
                    ans = { i, i }; break;
                }
                if (!upper(v, a[i]) || ans.first != -1) continue;
                int mn = tin[a[i]], ver = a[i];
                int j = i + 1;
                while (j <= r &&  upper(v, a[j])) {
                    if (lca(a[j], ver) == v) {
                        ans = { i, j };
                        break;
                    }
                    if (tin[a[j]] < mn) {
                        mn = tin[a[j]];
                        ver = a[j];
                    }
                    j++;
                }
            }
            cout << ans.first << ' ' << ans.second << '\n';
        }
        else {
            int pos, v;
            cin >> pos >> v;
            a[pos] = v;
        }
    }
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB n=5
2 Correct 5 ms 7380 KB n=100
3 Correct 4 ms 7296 KB n=100
4 Correct 4 ms 7380 KB n=100
5 Correct 4 ms 7380 KB n=100
6 Correct 3 ms 7388 KB n=100
7 Correct 4 ms 7380 KB n=100
8 Correct 4 ms 7292 KB n=100
9 Correct 4 ms 7388 KB n=100
10 Correct 4 ms 7380 KB n=100
11 Correct 6 ms 7384 KB n=100
12 Correct 5 ms 7384 KB n=100
13 Correct 4 ms 7380 KB n=100
14 Correct 6 ms 7344 KB n=100
15 Correct 6 ms 7376 KB n=100
16 Correct 6 ms 7380 KB n=100
17 Correct 5 ms 7380 KB n=100
18 Correct 4 ms 7380 KB n=100
19 Correct 4 ms 7388 KB n=100
20 Correct 4 ms 7380 KB n=100
21 Correct 4 ms 7380 KB n=100
22 Correct 4 ms 7380 KB n=100
23 Correct 5 ms 7380 KB n=100
24 Correct 4 ms 7380 KB n=100
25 Correct 4 ms 7380 KB n=100
26 Correct 5 ms 7380 KB n=12
27 Correct 6 ms 7384 KB n=100
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB n=5
2 Correct 5 ms 7380 KB n=100
3 Correct 4 ms 7296 KB n=100
4 Correct 4 ms 7380 KB n=100
5 Correct 4 ms 7380 KB n=100
6 Correct 3 ms 7388 KB n=100
7 Correct 4 ms 7380 KB n=100
8 Correct 4 ms 7292 KB n=100
9 Correct 4 ms 7388 KB n=100
10 Correct 4 ms 7380 KB n=100
11 Correct 6 ms 7384 KB n=100
12 Correct 5 ms 7384 KB n=100
13 Correct 4 ms 7380 KB n=100
14 Correct 6 ms 7344 KB n=100
15 Correct 6 ms 7376 KB n=100
16 Correct 6 ms 7380 KB n=100
17 Correct 5 ms 7380 KB n=100
18 Correct 4 ms 7380 KB n=100
19 Correct 4 ms 7388 KB n=100
20 Correct 4 ms 7380 KB n=100
21 Correct 4 ms 7380 KB n=100
22 Correct 4 ms 7380 KB n=100
23 Correct 5 ms 7380 KB n=100
24 Correct 4 ms 7380 KB n=100
25 Correct 4 ms 7380 KB n=100
26 Correct 5 ms 7380 KB n=12
27 Correct 6 ms 7384 KB n=100
28 Correct 5 ms 7380 KB n=500
29 Correct 6 ms 7380 KB n=500
30 Correct 6 ms 7380 KB n=500
31 Correct 8 ms 7396 KB n=500
32 Correct 5 ms 7412 KB n=500
33 Correct 7 ms 7380 KB n=500
34 Correct 4 ms 7380 KB n=500
35 Correct 5 ms 7380 KB n=500
36 Correct 6 ms 7388 KB n=500
37 Correct 6 ms 7380 KB n=500
38 Correct 6 ms 7392 KB n=500
39 Correct 5 ms 7380 KB n=500
40 Correct 5 ms 7380 KB n=500
41 Correct 4 ms 7400 KB n=500
42 Correct 5 ms 7380 KB n=500
43 Correct 9 ms 7380 KB n=500
44 Correct 6 ms 7396 KB n=500
45 Correct 4 ms 7392 KB n=500
46 Correct 5 ms 7380 KB n=500
47 Correct 6 ms 7380 KB n=500
48 Correct 4 ms 7392 KB n=500
49 Correct 5 ms 7380 KB n=500
50 Correct 5 ms 7380 KB n=500
51 Correct 7 ms 7380 KB n=500
52 Correct 5 ms 7380 KB n=500
53 Correct 6 ms 7380 KB n=500
54 Correct 18 ms 7396 KB n=500
55 Correct 6 ms 7340 KB n=278
56 Correct 113 ms 7472 KB n=500
57 Correct 129 ms 7468 KB n=500
58 Correct 5 ms 7484 KB n=500
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB n=5
2 Correct 5 ms 7380 KB n=100
3 Correct 4 ms 7296 KB n=100
4 Correct 4 ms 7380 KB n=100
5 Correct 4 ms 7380 KB n=100
6 Correct 3 ms 7388 KB n=100
7 Correct 4 ms 7380 KB n=100
8 Correct 4 ms 7292 KB n=100
9 Correct 4 ms 7388 KB n=100
10 Correct 4 ms 7380 KB n=100
11 Correct 6 ms 7384 KB n=100
12 Correct 5 ms 7384 KB n=100
13 Correct 4 ms 7380 KB n=100
14 Correct 6 ms 7344 KB n=100
15 Correct 6 ms 7376 KB n=100
16 Correct 6 ms 7380 KB n=100
17 Correct 5 ms 7380 KB n=100
18 Correct 4 ms 7380 KB n=100
19 Correct 4 ms 7388 KB n=100
20 Correct 4 ms 7380 KB n=100
21 Correct 4 ms 7380 KB n=100
22 Correct 4 ms 7380 KB n=100
23 Correct 5 ms 7380 KB n=100
24 Correct 4 ms 7380 KB n=100
25 Correct 4 ms 7380 KB n=100
26 Correct 5 ms 7380 KB n=12
27 Correct 6 ms 7384 KB n=100
28 Correct 5 ms 7380 KB n=500
29 Correct 6 ms 7380 KB n=500
30 Correct 6 ms 7380 KB n=500
31 Correct 8 ms 7396 KB n=500
32 Correct 5 ms 7412 KB n=500
33 Correct 7 ms 7380 KB n=500
34 Correct 4 ms 7380 KB n=500
35 Correct 5 ms 7380 KB n=500
36 Correct 6 ms 7388 KB n=500
37 Correct 6 ms 7380 KB n=500
38 Correct 6 ms 7392 KB n=500
39 Correct 5 ms 7380 KB n=500
40 Correct 5 ms 7380 KB n=500
41 Correct 4 ms 7400 KB n=500
42 Correct 5 ms 7380 KB n=500
43 Correct 9 ms 7380 KB n=500
44 Correct 6 ms 7396 KB n=500
45 Correct 4 ms 7392 KB n=500
46 Correct 5 ms 7380 KB n=500
47 Correct 6 ms 7380 KB n=500
48 Correct 4 ms 7392 KB n=500
49 Correct 5 ms 7380 KB n=500
50 Correct 5 ms 7380 KB n=500
51 Correct 7 ms 7380 KB n=500
52 Correct 5 ms 7380 KB n=500
53 Correct 6 ms 7380 KB n=500
54 Correct 18 ms 7396 KB n=500
55 Correct 6 ms 7340 KB n=278
56 Correct 113 ms 7472 KB n=500
57 Correct 129 ms 7468 KB n=500
58 Correct 5 ms 7484 KB n=500
59 Correct 9 ms 7648 KB n=2000
60 Correct 27 ms 7764 KB n=2000
61 Correct 35 ms 7736 KB n=2000
62 Correct 48 ms 7716 KB n=2000
63 Correct 11 ms 7600 KB n=2000
64 Correct 56 ms 7728 KB n=2000
65 Correct 10 ms 7708 KB n=2000
66 Correct 44 ms 7752 KB n=2000
67 Correct 10 ms 7604 KB n=2000
68 Correct 42 ms 7756 KB n=2000
69 Correct 32 ms 7696 KB n=2000
70 Correct 34 ms 7772 KB n=2000
71 Correct 28 ms 7600 KB n=2000
72 Correct 13 ms 7600 KB n=2000
73 Correct 11 ms 7636 KB n=2000
74 Correct 9 ms 7656 KB n=1844
75 Correct 12 ms 7700 KB n=2000
76 Correct 24 ms 7636 KB n=2000
77 Correct 28 ms 7652 KB n=2000
78 Correct 24 ms 7636 KB n=2000
79 Correct 6 ms 7680 KB n=2000
80 Correct 23 ms 7764 KB n=2000
81 Correct 39 ms 7740 KB n=2000
82 Correct 6 ms 7656 KB n=2000
83 Correct 25 ms 7760 KB n=2000
84 Correct 9 ms 7636 KB n=2000
85 Correct 49 ms 7608 KB n=2000
86 Correct 33 ms 7724 KB n=2000
87 Correct 9 ms 7636 KB n=2000
88 Execution timed out 4045 ms 7892 KB Time limit exceeded
89 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB n=5
2 Correct 5 ms 7380 KB n=100
3 Correct 4 ms 7296 KB n=100
4 Correct 4 ms 7380 KB n=100
5 Correct 4 ms 7380 KB n=100
6 Correct 3 ms 7388 KB n=100
7 Correct 4 ms 7380 KB n=100
8 Correct 4 ms 7292 KB n=100
9 Correct 4 ms 7388 KB n=100
10 Correct 4 ms 7380 KB n=100
11 Correct 6 ms 7384 KB n=100
12 Correct 5 ms 7384 KB n=100
13 Correct 4 ms 7380 KB n=100
14 Correct 6 ms 7344 KB n=100
15 Correct 6 ms 7376 KB n=100
16 Correct 6 ms 7380 KB n=100
17 Correct 5 ms 7380 KB n=100
18 Correct 4 ms 7380 KB n=100
19 Correct 4 ms 7388 KB n=100
20 Correct 4 ms 7380 KB n=100
21 Correct 4 ms 7380 KB n=100
22 Correct 4 ms 7380 KB n=100
23 Correct 5 ms 7380 KB n=100
24 Correct 4 ms 7380 KB n=100
25 Correct 4 ms 7380 KB n=100
26 Correct 5 ms 7380 KB n=12
27 Correct 6 ms 7384 KB n=100
28 Correct 5 ms 7380 KB n=500
29 Correct 6 ms 7380 KB n=500
30 Correct 6 ms 7380 KB n=500
31 Correct 8 ms 7396 KB n=500
32 Correct 5 ms 7412 KB n=500
33 Correct 7 ms 7380 KB n=500
34 Correct 4 ms 7380 KB n=500
35 Correct 5 ms 7380 KB n=500
36 Correct 6 ms 7388 KB n=500
37 Correct 6 ms 7380 KB n=500
38 Correct 6 ms 7392 KB n=500
39 Correct 5 ms 7380 KB n=500
40 Correct 5 ms 7380 KB n=500
41 Correct 4 ms 7400 KB n=500
42 Correct 5 ms 7380 KB n=500
43 Correct 9 ms 7380 KB n=500
44 Correct 6 ms 7396 KB n=500
45 Correct 4 ms 7392 KB n=500
46 Correct 5 ms 7380 KB n=500
47 Correct 6 ms 7380 KB n=500
48 Correct 4 ms 7392 KB n=500
49 Correct 5 ms 7380 KB n=500
50 Correct 5 ms 7380 KB n=500
51 Correct 7 ms 7380 KB n=500
52 Correct 5 ms 7380 KB n=500
53 Correct 6 ms 7380 KB n=500
54 Correct 18 ms 7396 KB n=500
55 Correct 6 ms 7340 KB n=278
56 Correct 113 ms 7472 KB n=500
57 Correct 129 ms 7468 KB n=500
58 Correct 5 ms 7484 KB n=500
59 Correct 9 ms 7648 KB n=2000
60 Correct 27 ms 7764 KB n=2000
61 Correct 35 ms 7736 KB n=2000
62 Correct 48 ms 7716 KB n=2000
63 Correct 11 ms 7600 KB n=2000
64 Correct 56 ms 7728 KB n=2000
65 Correct 10 ms 7708 KB n=2000
66 Correct 44 ms 7752 KB n=2000
67 Correct 10 ms 7604 KB n=2000
68 Correct 42 ms 7756 KB n=2000
69 Correct 32 ms 7696 KB n=2000
70 Correct 34 ms 7772 KB n=2000
71 Correct 28 ms 7600 KB n=2000
72 Correct 13 ms 7600 KB n=2000
73 Correct 11 ms 7636 KB n=2000
74 Correct 9 ms 7656 KB n=1844
75 Correct 12 ms 7700 KB n=2000
76 Correct 24 ms 7636 KB n=2000
77 Correct 28 ms 7652 KB n=2000
78 Correct 24 ms 7636 KB n=2000
79 Correct 6 ms 7680 KB n=2000
80 Correct 23 ms 7764 KB n=2000
81 Correct 39 ms 7740 KB n=2000
82 Correct 6 ms 7656 KB n=2000
83 Correct 25 ms 7760 KB n=2000
84 Correct 9 ms 7636 KB n=2000
85 Correct 49 ms 7608 KB n=2000
86 Correct 33 ms 7724 KB n=2000
87 Correct 9 ms 7636 KB n=2000
88 Execution timed out 4045 ms 7892 KB Time limit exceeded
89 Halted 0 ms 0 KB -