답안 #750566

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
750566 2023-05-29T18:02:11 Z anaduguleanu Birthday gift (IZhO18_treearray) C++14
56 / 100
2108 ms 88680 KB
#include <iostream>
#include <vector>
#include <set>
#define LOG 20
#define MAX 200000
using namespace std;
///ifstream cin ("c.in");
///ofstream cout ("c.out");
int a[MAX + 10], level[MAX + 10], visited[MAX + 10], ancestor[LOG + 10][MAX + 10];
vector <int> graph[MAX + 10];
set <int> posSequence[MAX + 10], posLca[MAX + 10];
void dfs(int node, int parent, int depth)
{
    level[node] = depth;
    visited[node] = 1;
    for (auto next : graph[node])
        if (next != parent && visited[next] == 0)
        {
            ancestor[0][next] = node;
            dfs(next, node, depth + 1);
        }
}
int lca(int x, int y)
{
    if (level[y] > level[x])
        swap(x, y);
    for (int p = LOG; p >= 0; p--)
        if (level[ancestor[p][x]] >= level[y])
            x = ancestor[p][x];
    if (x == y)
        return x;
    for (int p = LOG; p >= 0; p--)
        if (ancestor[p][x] != ancestor[p][y])
        {
            x = ancestor[p][x];
            y = ancestor[p][y];
        }
    return ancestor[0][x];
}
int main()
{
    int n, m, q;
    cin >> n >> m >> q;
    for (int i = 1; i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    for (int p = 0; p <= LOG; p++)
        ancestor[p][1] = 1;
    dfs(1, 0, 0);
    for (int p = 1; p <= LOG; p++)
        for (int node = 2; node <= n; node++)
            ancestor[p][node] = ancestor[p - 1][ancestor[p - 1][node]];
    for (int i = 1; i <= m; i++)
    {
        cin >> a[i];
        posSequence[a[i]].insert(i);
    }
    for (int i = 1; i < m; i++)
        posLca[lca(a[i], a[i + 1])].insert(i);
    for (int qq = 1; qq <= q; qq++)
    {
        int type;
        cin >> type;
        if (type == 1)
        {
            int pos, val;
            cin >> pos >> val;
            posSequence[a[pos]].erase(pos);
            posSequence[val].insert(pos);
            if (pos < n)
            {
                posLca[lca(a[pos], a[pos + 1])].erase(pos);
                posLca[lca(val, a[pos + 1])].insert(pos);
            }
            if (pos > 1)
            {
                posLca[lca(a[pos - 1], a[pos])].erase(pos - 1);
                posLca[lca(a[pos - 1], val)].insert(pos - 1);
            }
            a[pos] = val;
        }
        else
        {
            int l, r, valLca;
            cin >> l >> r >> valLca;
            auto it = posSequence[valLca].lower_bound(l);
            if (it != posSequence[valLca].end() && *it <= r)
                cout << *it << ' ' << *it << '\n';
            else
            {
                it = posLca[valLca].lower_bound(l);
                if (it != posLca[valLca].end() && *it < r)
                    cout << *it << ' ' << (*it) + 1 << '\n';
                else
                    cout << "-1 1\n";
            }
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23892 KB n=5
2 Correct 13 ms 23892 KB n=100
3 Correct 15 ms 23892 KB n=100
4 Correct 14 ms 23892 KB n=100
5 Correct 16 ms 23932 KB n=100
6 Correct 13 ms 23860 KB n=100
7 Correct 13 ms 23908 KB n=100
8 Correct 13 ms 23892 KB n=100
9 Correct 13 ms 23948 KB n=100
10 Correct 14 ms 23892 KB n=100
11 Correct 12 ms 23872 KB n=100
12 Correct 13 ms 23904 KB n=100
13 Correct 15 ms 23924 KB n=100
14 Correct 13 ms 23892 KB n=100
15 Correct 14 ms 23892 KB n=100
16 Correct 12 ms 23892 KB n=100
17 Correct 13 ms 23924 KB n=100
18 Correct 14 ms 23892 KB n=100
19 Correct 13 ms 23892 KB n=100
20 Correct 13 ms 23844 KB n=100
21 Correct 14 ms 23940 KB n=100
22 Correct 13 ms 23892 KB n=100
23 Correct 14 ms 23932 KB n=100
24 Correct 13 ms 23928 KB n=100
25 Correct 14 ms 23924 KB n=100
26 Correct 16 ms 23892 KB n=12
27 Correct 13 ms 23924 KB n=100
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23892 KB n=5
2 Correct 13 ms 23892 KB n=100
3 Correct 15 ms 23892 KB n=100
4 Correct 14 ms 23892 KB n=100
5 Correct 16 ms 23932 KB n=100
6 Correct 13 ms 23860 KB n=100
7 Correct 13 ms 23908 KB n=100
8 Correct 13 ms 23892 KB n=100
9 Correct 13 ms 23948 KB n=100
10 Correct 14 ms 23892 KB n=100
11 Correct 12 ms 23872 KB n=100
12 Correct 13 ms 23904 KB n=100
13 Correct 15 ms 23924 KB n=100
14 Correct 13 ms 23892 KB n=100
15 Correct 14 ms 23892 KB n=100
16 Correct 12 ms 23892 KB n=100
17 Correct 13 ms 23924 KB n=100
18 Correct 14 ms 23892 KB n=100
19 Correct 13 ms 23892 KB n=100
20 Correct 13 ms 23844 KB n=100
21 Correct 14 ms 23940 KB n=100
22 Correct 13 ms 23892 KB n=100
23 Correct 14 ms 23932 KB n=100
24 Correct 13 ms 23928 KB n=100
25 Correct 14 ms 23924 KB n=100
26 Correct 16 ms 23892 KB n=12
27 Correct 13 ms 23924 KB n=100
28 Correct 16 ms 23936 KB n=500
29 Correct 16 ms 24020 KB n=500
30 Correct 15 ms 24012 KB n=500
31 Correct 20 ms 24020 KB n=500
32 Correct 16 ms 24020 KB n=500
33 Correct 15 ms 24004 KB n=500
34 Correct 15 ms 23964 KB n=500
35 Correct 17 ms 24060 KB n=500
36 Correct 18 ms 23932 KB n=500
37 Correct 15 ms 24020 KB n=500
38 Correct 15 ms 23936 KB n=500
39 Correct 14 ms 24008 KB n=500
40 Correct 14 ms 24020 KB n=500
41 Correct 15 ms 24020 KB n=500
42 Correct 14 ms 24020 KB n=500
43 Correct 14 ms 23932 KB n=500
44 Correct 14 ms 24020 KB n=500
45 Correct 15 ms 24020 KB n=500
46 Correct 19 ms 24020 KB n=500
47 Correct 15 ms 24020 KB n=500
48 Correct 14 ms 24020 KB n=500
49 Correct 14 ms 24000 KB n=500
50 Correct 15 ms 23932 KB n=500
51 Correct 14 ms 24020 KB n=500
52 Correct 16 ms 24064 KB n=500
53 Correct 16 ms 24020 KB n=500
54 Correct 15 ms 23980 KB n=500
55 Correct 15 ms 23996 KB n=278
56 Correct 16 ms 24020 KB n=500
57 Correct 22 ms 24008 KB n=500
58 Correct 18 ms 23940 KB n=500
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23892 KB n=5
2 Correct 13 ms 23892 KB n=100
3 Correct 15 ms 23892 KB n=100
4 Correct 14 ms 23892 KB n=100
5 Correct 16 ms 23932 KB n=100
6 Correct 13 ms 23860 KB n=100
7 Correct 13 ms 23908 KB n=100
8 Correct 13 ms 23892 KB n=100
9 Correct 13 ms 23948 KB n=100
10 Correct 14 ms 23892 KB n=100
11 Correct 12 ms 23872 KB n=100
12 Correct 13 ms 23904 KB n=100
13 Correct 15 ms 23924 KB n=100
14 Correct 13 ms 23892 KB n=100
15 Correct 14 ms 23892 KB n=100
16 Correct 12 ms 23892 KB n=100
17 Correct 13 ms 23924 KB n=100
18 Correct 14 ms 23892 KB n=100
19 Correct 13 ms 23892 KB n=100
20 Correct 13 ms 23844 KB n=100
21 Correct 14 ms 23940 KB n=100
22 Correct 13 ms 23892 KB n=100
23 Correct 14 ms 23932 KB n=100
24 Correct 13 ms 23928 KB n=100
25 Correct 14 ms 23924 KB n=100
26 Correct 16 ms 23892 KB n=12
27 Correct 13 ms 23924 KB n=100
28 Correct 16 ms 23936 KB n=500
29 Correct 16 ms 24020 KB n=500
30 Correct 15 ms 24012 KB n=500
31 Correct 20 ms 24020 KB n=500
32 Correct 16 ms 24020 KB n=500
33 Correct 15 ms 24004 KB n=500
34 Correct 15 ms 23964 KB n=500
35 Correct 17 ms 24060 KB n=500
36 Correct 18 ms 23932 KB n=500
37 Correct 15 ms 24020 KB n=500
38 Correct 15 ms 23936 KB n=500
39 Correct 14 ms 24008 KB n=500
40 Correct 14 ms 24020 KB n=500
41 Correct 15 ms 24020 KB n=500
42 Correct 14 ms 24020 KB n=500
43 Correct 14 ms 23932 KB n=500
44 Correct 14 ms 24020 KB n=500
45 Correct 15 ms 24020 KB n=500
46 Correct 19 ms 24020 KB n=500
47 Correct 15 ms 24020 KB n=500
48 Correct 14 ms 24020 KB n=500
49 Correct 14 ms 24000 KB n=500
50 Correct 15 ms 23932 KB n=500
51 Correct 14 ms 24020 KB n=500
52 Correct 16 ms 24064 KB n=500
53 Correct 16 ms 24020 KB n=500
54 Correct 15 ms 23980 KB n=500
55 Correct 15 ms 23996 KB n=278
56 Correct 16 ms 24020 KB n=500
57 Correct 22 ms 24008 KB n=500
58 Correct 18 ms 23940 KB n=500
59 Correct 21 ms 24404 KB n=2000
60 Correct 29 ms 24536 KB n=2000
61 Correct 20 ms 24492 KB n=2000
62 Correct 24 ms 24448 KB n=2000
63 Correct 21 ms 24312 KB n=2000
64 Correct 29 ms 24360 KB n=2000
65 Correct 21 ms 24384 KB n=2000
66 Correct 21 ms 24504 KB n=2000
67 Correct 27 ms 24420 KB n=2000
68 Correct 22 ms 24448 KB n=2000
69 Correct 34 ms 24352 KB n=2000
70 Correct 19 ms 24424 KB n=2000
71 Correct 19 ms 24396 KB n=2000
72 Correct 19 ms 24412 KB n=2000
73 Correct 19 ms 24316 KB n=2000
74 Correct 19 ms 24400 KB n=1844
75 Correct 19 ms 24392 KB n=2000
76 Correct 21 ms 24412 KB n=2000
77 Correct 21 ms 24404 KB n=2000
78 Correct 24 ms 24412 KB n=2000
79 Correct 19 ms 24320 KB n=2000
80 Correct 20 ms 24404 KB n=2000
81 Correct 20 ms 24404 KB n=2000
82 Correct 19 ms 24404 KB n=2000
83 Correct 25 ms 24448 KB n=2000
84 Correct 19 ms 24336 KB n=2000
85 Correct 19 ms 24448 KB n=2000
86 Correct 20 ms 24404 KB n=2000
87 Correct 20 ms 24404 KB n=2000
88 Correct 26 ms 24460 KB n=2000
89 Correct 19 ms 24452 KB n=2000
90 Correct 22 ms 24404 KB n=2000
91 Correct 19 ms 24408 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23892 KB n=5
2 Correct 13 ms 23892 KB n=100
3 Correct 15 ms 23892 KB n=100
4 Correct 14 ms 23892 KB n=100
5 Correct 16 ms 23932 KB n=100
6 Correct 13 ms 23860 KB n=100
7 Correct 13 ms 23908 KB n=100
8 Correct 13 ms 23892 KB n=100
9 Correct 13 ms 23948 KB n=100
10 Correct 14 ms 23892 KB n=100
11 Correct 12 ms 23872 KB n=100
12 Correct 13 ms 23904 KB n=100
13 Correct 15 ms 23924 KB n=100
14 Correct 13 ms 23892 KB n=100
15 Correct 14 ms 23892 KB n=100
16 Correct 12 ms 23892 KB n=100
17 Correct 13 ms 23924 KB n=100
18 Correct 14 ms 23892 KB n=100
19 Correct 13 ms 23892 KB n=100
20 Correct 13 ms 23844 KB n=100
21 Correct 14 ms 23940 KB n=100
22 Correct 13 ms 23892 KB n=100
23 Correct 14 ms 23932 KB n=100
24 Correct 13 ms 23928 KB n=100
25 Correct 14 ms 23924 KB n=100
26 Correct 16 ms 23892 KB n=12
27 Correct 13 ms 23924 KB n=100
28 Correct 16 ms 23936 KB n=500
29 Correct 16 ms 24020 KB n=500
30 Correct 15 ms 24012 KB n=500
31 Correct 20 ms 24020 KB n=500
32 Correct 16 ms 24020 KB n=500
33 Correct 15 ms 24004 KB n=500
34 Correct 15 ms 23964 KB n=500
35 Correct 17 ms 24060 KB n=500
36 Correct 18 ms 23932 KB n=500
37 Correct 15 ms 24020 KB n=500
38 Correct 15 ms 23936 KB n=500
39 Correct 14 ms 24008 KB n=500
40 Correct 14 ms 24020 KB n=500
41 Correct 15 ms 24020 KB n=500
42 Correct 14 ms 24020 KB n=500
43 Correct 14 ms 23932 KB n=500
44 Correct 14 ms 24020 KB n=500
45 Correct 15 ms 24020 KB n=500
46 Correct 19 ms 24020 KB n=500
47 Correct 15 ms 24020 KB n=500
48 Correct 14 ms 24020 KB n=500
49 Correct 14 ms 24000 KB n=500
50 Correct 15 ms 23932 KB n=500
51 Correct 14 ms 24020 KB n=500
52 Correct 16 ms 24064 KB n=500
53 Correct 16 ms 24020 KB n=500
54 Correct 15 ms 23980 KB n=500
55 Correct 15 ms 23996 KB n=278
56 Correct 16 ms 24020 KB n=500
57 Correct 22 ms 24008 KB n=500
58 Correct 18 ms 23940 KB n=500
59 Correct 21 ms 24404 KB n=2000
60 Correct 29 ms 24536 KB n=2000
61 Correct 20 ms 24492 KB n=2000
62 Correct 24 ms 24448 KB n=2000
63 Correct 21 ms 24312 KB n=2000
64 Correct 29 ms 24360 KB n=2000
65 Correct 21 ms 24384 KB n=2000
66 Correct 21 ms 24504 KB n=2000
67 Correct 27 ms 24420 KB n=2000
68 Correct 22 ms 24448 KB n=2000
69 Correct 34 ms 24352 KB n=2000
70 Correct 19 ms 24424 KB n=2000
71 Correct 19 ms 24396 KB n=2000
72 Correct 19 ms 24412 KB n=2000
73 Correct 19 ms 24316 KB n=2000
74 Correct 19 ms 24400 KB n=1844
75 Correct 19 ms 24392 KB n=2000
76 Correct 21 ms 24412 KB n=2000
77 Correct 21 ms 24404 KB n=2000
78 Correct 24 ms 24412 KB n=2000
79 Correct 19 ms 24320 KB n=2000
80 Correct 20 ms 24404 KB n=2000
81 Correct 20 ms 24404 KB n=2000
82 Correct 19 ms 24404 KB n=2000
83 Correct 25 ms 24448 KB n=2000
84 Correct 19 ms 24336 KB n=2000
85 Correct 19 ms 24448 KB n=2000
86 Correct 20 ms 24404 KB n=2000
87 Correct 20 ms 24404 KB n=2000
88 Correct 26 ms 24460 KB n=2000
89 Correct 19 ms 24452 KB n=2000
90 Correct 22 ms 24404 KB n=2000
91 Correct 19 ms 24408 KB n=2000
92 Correct 1738 ms 76056 KB n=200000
93 Correct 2021 ms 82532 KB n=200000
94 Correct 1912 ms 86964 KB n=200000
95 Correct 1716 ms 75900 KB n=200000
96 Correct 1700 ms 75960 KB n=200000
97 Correct 2027 ms 81320 KB n=200000
98 Correct 1720 ms 75948 KB n=200000
99 Correct 2087 ms 76068 KB n=200000
100 Correct 1735 ms 75932 KB n=200000
101 Correct 2098 ms 88680 KB n=200000
102 Correct 1096 ms 77268 KB n=200000
103 Correct 1083 ms 77120 KB n=200000
104 Correct 1107 ms 77012 KB n=200000
105 Correct 1155 ms 77580 KB n=200000
106 Correct 1151 ms 77500 KB n=200000
107 Correct 1145 ms 77504 KB n=200000
108 Correct 2008 ms 75884 KB n=200000
109 Correct 1919 ms 76104 KB n=200000
110 Correct 1894 ms 76044 KB n=200000
111 Correct 1553 ms 75484 KB n=200000
112 Correct 2108 ms 87464 KB n=200000
113 Correct 2103 ms 81284 KB n=200000
114 Correct 1441 ms 75420 KB n=200000
115 Correct 2073 ms 78440 KB n=200000
116 Correct 1622 ms 76136 KB n=200000
117 Correct 2003 ms 87740 KB n=200000
118 Correct 1986 ms 79868 KB n=200000
119 Correct 1498 ms 75976 KB n=200000
120 Correct 1837 ms 87720 KB n=200000
121 Correct 1775 ms 87596 KB n=200000
122 Correct 1769 ms 88108 KB n=200000
123 Correct 1032 ms 77192 KB n=200000
124 Incorrect 381 ms 39320 KB Wrong range.
125 Halted 0 ms 0 KB -