Submission #750576

# Submission time Handle Problem Language Result Execution time Memory
750576 2023-05-29T18:21:22 Z anaduguleanu Birthday gift (IZhO18_treearray) C++14
56 / 100
2441 ms 92164 KB
#include <iostream>
#include <vector>
#include <set>
#define LOG 20
#define MAX 200000
using namespace std;
///ifstream cin ("c.in");
///ofstream cout ("c.out");
long long a[MAX + 10], level[MAX + 10], ancestor[LOG + 10][MAX + 10];
vector <long long> graph[MAX + 10];
set <long long> posSequence[MAX + 10], posLca[MAX + 10];
void dfs(long long node, long long parent, long long depth)
{
    level[node] = depth;
    for (auto next : graph[node])
        if (next != parent)
        {
            ancestor[0][next] = node;
            dfs(next, node, depth + 1);
        }
}
long long lca(long long x, long long y)
{
    if (level[y] > level[x])
        swap(x, y);
    for (long long p = LOG; p >= 0; p--)
        if (level[ancestor[p][x]] >= level[y])
            x = ancestor[p][x];
    if (x == y)
        return x;
    for (long long 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()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long n, m, q;
    cin >> n >> m >> q;
    for (long long i = 1; i < n; i++)
    {
        long long x, y;
        cin >> x >> y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    for (long long p = 0; p <= LOG; p++)
        ancestor[p][1] = 1;
    dfs(1, 0, 0);
    for (long long p = 1; p <= LOG; p++)
        for (long long node = 2; node <= n; node++)
            ancestor[p][node] = ancestor[p - 1][ancestor[p - 1][node]];
    for (long long i = 1; i <= m; i++)
    {
        cin >> a[i];
        posSequence[a[i]].insert(i);
    }
    for (long long i = 1; i < m; i++)
        posLca[lca(a[i], a[i + 1])].insert(i);
    for (long long qq = 1; qq <= q; qq++)
    {
        long long type;
        cin >> type;
        if (type == 1)
        {
            long long 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
        {
            long long 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;
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23892 KB n=5
2 Correct 12 ms 24056 KB n=100
3 Correct 12 ms 23892 KB n=100
4 Correct 11 ms 23892 KB n=100
5 Correct 12 ms 23952 KB n=100
6 Correct 12 ms 23892 KB n=100
7 Correct 12 ms 23892 KB n=100
8 Correct 14 ms 23892 KB n=100
9 Correct 12 ms 23892 KB n=100
10 Correct 12 ms 23932 KB n=100
11 Correct 12 ms 23956 KB n=100
12 Correct 12 ms 23892 KB n=100
13 Correct 12 ms 23892 KB n=100
14 Correct 12 ms 23892 KB n=100
15 Correct 12 ms 23880 KB n=100
16 Correct 14 ms 23892 KB n=100
17 Correct 14 ms 23992 KB n=100
18 Correct 13 ms 23880 KB n=100
19 Correct 13 ms 23892 KB n=100
20 Correct 12 ms 23996 KB n=100
21 Correct 12 ms 23892 KB n=100
22 Correct 12 ms 23892 KB n=100
23 Correct 12 ms 23920 KB n=100
24 Correct 12 ms 23976 KB n=100
25 Correct 12 ms 23892 KB n=100
26 Correct 13 ms 23968 KB n=12
27 Correct 14 ms 23892 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23892 KB n=5
2 Correct 12 ms 24056 KB n=100
3 Correct 12 ms 23892 KB n=100
4 Correct 11 ms 23892 KB n=100
5 Correct 12 ms 23952 KB n=100
6 Correct 12 ms 23892 KB n=100
7 Correct 12 ms 23892 KB n=100
8 Correct 14 ms 23892 KB n=100
9 Correct 12 ms 23892 KB n=100
10 Correct 12 ms 23932 KB n=100
11 Correct 12 ms 23956 KB n=100
12 Correct 12 ms 23892 KB n=100
13 Correct 12 ms 23892 KB n=100
14 Correct 12 ms 23892 KB n=100
15 Correct 12 ms 23880 KB n=100
16 Correct 14 ms 23892 KB n=100
17 Correct 14 ms 23992 KB n=100
18 Correct 13 ms 23880 KB n=100
19 Correct 13 ms 23892 KB n=100
20 Correct 12 ms 23996 KB n=100
21 Correct 12 ms 23892 KB n=100
22 Correct 12 ms 23892 KB n=100
23 Correct 12 ms 23920 KB n=100
24 Correct 12 ms 23976 KB n=100
25 Correct 12 ms 23892 KB n=100
26 Correct 13 ms 23968 KB n=12
27 Correct 14 ms 23892 KB n=100
28 Correct 16 ms 24020 KB n=500
29 Correct 13 ms 24052 KB n=500
30 Correct 13 ms 24020 KB n=500
31 Correct 13 ms 24020 KB n=500
32 Correct 13 ms 24020 KB n=500
33 Correct 16 ms 24020 KB n=500
34 Correct 13 ms 24148 KB n=500
35 Correct 12 ms 24132 KB n=500
36 Correct 12 ms 24020 KB n=500
37 Correct 12 ms 24120 KB n=500
38 Correct 12 ms 24020 KB n=500
39 Correct 13 ms 24092 KB n=500
40 Correct 12 ms 24044 KB n=500
41 Correct 12 ms 24020 KB n=500
42 Correct 14 ms 24104 KB n=500
43 Correct 13 ms 24032 KB n=500
44 Correct 13 ms 24052 KB n=500
45 Correct 14 ms 24124 KB n=500
46 Correct 14 ms 24020 KB n=500
47 Correct 12 ms 24100 KB n=500
48 Correct 13 ms 24072 KB n=500
49 Correct 13 ms 24020 KB n=500
50 Correct 12 ms 24020 KB n=500
51 Correct 12 ms 24020 KB n=500
52 Correct 14 ms 24064 KB n=500
53 Correct 12 ms 24020 KB n=500
54 Correct 12 ms 24020 KB n=500
55 Correct 13 ms 24020 KB n=278
56 Correct 12 ms 24020 KB n=500
57 Correct 13 ms 24020 KB n=500
58 Correct 13 ms 24020 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23892 KB n=5
2 Correct 12 ms 24056 KB n=100
3 Correct 12 ms 23892 KB n=100
4 Correct 11 ms 23892 KB n=100
5 Correct 12 ms 23952 KB n=100
6 Correct 12 ms 23892 KB n=100
7 Correct 12 ms 23892 KB n=100
8 Correct 14 ms 23892 KB n=100
9 Correct 12 ms 23892 KB n=100
10 Correct 12 ms 23932 KB n=100
11 Correct 12 ms 23956 KB n=100
12 Correct 12 ms 23892 KB n=100
13 Correct 12 ms 23892 KB n=100
14 Correct 12 ms 23892 KB n=100
15 Correct 12 ms 23880 KB n=100
16 Correct 14 ms 23892 KB n=100
17 Correct 14 ms 23992 KB n=100
18 Correct 13 ms 23880 KB n=100
19 Correct 13 ms 23892 KB n=100
20 Correct 12 ms 23996 KB n=100
21 Correct 12 ms 23892 KB n=100
22 Correct 12 ms 23892 KB n=100
23 Correct 12 ms 23920 KB n=100
24 Correct 12 ms 23976 KB n=100
25 Correct 12 ms 23892 KB n=100
26 Correct 13 ms 23968 KB n=12
27 Correct 14 ms 23892 KB n=100
28 Correct 16 ms 24020 KB n=500
29 Correct 13 ms 24052 KB n=500
30 Correct 13 ms 24020 KB n=500
31 Correct 13 ms 24020 KB n=500
32 Correct 13 ms 24020 KB n=500
33 Correct 16 ms 24020 KB n=500
34 Correct 13 ms 24148 KB n=500
35 Correct 12 ms 24132 KB n=500
36 Correct 12 ms 24020 KB n=500
37 Correct 12 ms 24120 KB n=500
38 Correct 12 ms 24020 KB n=500
39 Correct 13 ms 24092 KB n=500
40 Correct 12 ms 24044 KB n=500
41 Correct 12 ms 24020 KB n=500
42 Correct 14 ms 24104 KB n=500
43 Correct 13 ms 24032 KB n=500
44 Correct 13 ms 24052 KB n=500
45 Correct 14 ms 24124 KB n=500
46 Correct 14 ms 24020 KB n=500
47 Correct 12 ms 24100 KB n=500
48 Correct 13 ms 24072 KB n=500
49 Correct 13 ms 24020 KB n=500
50 Correct 12 ms 24020 KB n=500
51 Correct 12 ms 24020 KB n=500
52 Correct 14 ms 24064 KB n=500
53 Correct 12 ms 24020 KB n=500
54 Correct 12 ms 24020 KB n=500
55 Correct 13 ms 24020 KB n=278
56 Correct 12 ms 24020 KB n=500
57 Correct 13 ms 24020 KB n=500
58 Correct 13 ms 24020 KB n=500
59 Correct 16 ms 24532 KB n=2000
60 Correct 15 ms 24532 KB n=2000
61 Correct 16 ms 24596 KB n=2000
62 Correct 16 ms 24604 KB n=2000
63 Correct 16 ms 24532 KB n=2000
64 Correct 18 ms 24532 KB n=2000
65 Correct 16 ms 24532 KB n=2000
66 Correct 16 ms 24532 KB n=2000
67 Correct 17 ms 24492 KB n=2000
68 Correct 16 ms 24600 KB n=2000
69 Correct 15 ms 24532 KB n=2000
70 Correct 14 ms 24604 KB n=2000
71 Correct 15 ms 24544 KB n=2000
72 Correct 14 ms 24532 KB n=2000
73 Correct 16 ms 24532 KB n=2000
74 Correct 16 ms 24476 KB n=1844
75 Correct 14 ms 24532 KB n=2000
76 Correct 17 ms 24552 KB n=2000
77 Correct 17 ms 24584 KB n=2000
78 Correct 17 ms 24532 KB n=2000
79 Correct 17 ms 24588 KB n=2000
80 Correct 15 ms 24532 KB n=2000
81 Correct 16 ms 24524 KB n=2000
82 Correct 16 ms 24524 KB n=2000
83 Correct 16 ms 24620 KB n=2000
84 Correct 16 ms 24492 KB n=2000
85 Correct 16 ms 24532 KB n=2000
86 Correct 17 ms 24544 KB n=2000
87 Correct 17 ms 24556 KB n=2000
88 Correct 18 ms 24608 KB n=2000
89 Correct 18 ms 24624 KB n=2000
90 Correct 15 ms 24532 KB n=2000
91 Correct 14 ms 24600 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23892 KB n=5
2 Correct 12 ms 24056 KB n=100
3 Correct 12 ms 23892 KB n=100
4 Correct 11 ms 23892 KB n=100
5 Correct 12 ms 23952 KB n=100
6 Correct 12 ms 23892 KB n=100
7 Correct 12 ms 23892 KB n=100
8 Correct 14 ms 23892 KB n=100
9 Correct 12 ms 23892 KB n=100
10 Correct 12 ms 23932 KB n=100
11 Correct 12 ms 23956 KB n=100
12 Correct 12 ms 23892 KB n=100
13 Correct 12 ms 23892 KB n=100
14 Correct 12 ms 23892 KB n=100
15 Correct 12 ms 23880 KB n=100
16 Correct 14 ms 23892 KB n=100
17 Correct 14 ms 23992 KB n=100
18 Correct 13 ms 23880 KB n=100
19 Correct 13 ms 23892 KB n=100
20 Correct 12 ms 23996 KB n=100
21 Correct 12 ms 23892 KB n=100
22 Correct 12 ms 23892 KB n=100
23 Correct 12 ms 23920 KB n=100
24 Correct 12 ms 23976 KB n=100
25 Correct 12 ms 23892 KB n=100
26 Correct 13 ms 23968 KB n=12
27 Correct 14 ms 23892 KB n=100
28 Correct 16 ms 24020 KB n=500
29 Correct 13 ms 24052 KB n=500
30 Correct 13 ms 24020 KB n=500
31 Correct 13 ms 24020 KB n=500
32 Correct 13 ms 24020 KB n=500
33 Correct 16 ms 24020 KB n=500
34 Correct 13 ms 24148 KB n=500
35 Correct 12 ms 24132 KB n=500
36 Correct 12 ms 24020 KB n=500
37 Correct 12 ms 24120 KB n=500
38 Correct 12 ms 24020 KB n=500
39 Correct 13 ms 24092 KB n=500
40 Correct 12 ms 24044 KB n=500
41 Correct 12 ms 24020 KB n=500
42 Correct 14 ms 24104 KB n=500
43 Correct 13 ms 24032 KB n=500
44 Correct 13 ms 24052 KB n=500
45 Correct 14 ms 24124 KB n=500
46 Correct 14 ms 24020 KB n=500
47 Correct 12 ms 24100 KB n=500
48 Correct 13 ms 24072 KB n=500
49 Correct 13 ms 24020 KB n=500
50 Correct 12 ms 24020 KB n=500
51 Correct 12 ms 24020 KB n=500
52 Correct 14 ms 24064 KB n=500
53 Correct 12 ms 24020 KB n=500
54 Correct 12 ms 24020 KB n=500
55 Correct 13 ms 24020 KB n=278
56 Correct 12 ms 24020 KB n=500
57 Correct 13 ms 24020 KB n=500
58 Correct 13 ms 24020 KB n=500
59 Correct 16 ms 24532 KB n=2000
60 Correct 15 ms 24532 KB n=2000
61 Correct 16 ms 24596 KB n=2000
62 Correct 16 ms 24604 KB n=2000
63 Correct 16 ms 24532 KB n=2000
64 Correct 18 ms 24532 KB n=2000
65 Correct 16 ms 24532 KB n=2000
66 Correct 16 ms 24532 KB n=2000
67 Correct 17 ms 24492 KB n=2000
68 Correct 16 ms 24600 KB n=2000
69 Correct 15 ms 24532 KB n=2000
70 Correct 14 ms 24604 KB n=2000
71 Correct 15 ms 24544 KB n=2000
72 Correct 14 ms 24532 KB n=2000
73 Correct 16 ms 24532 KB n=2000
74 Correct 16 ms 24476 KB n=1844
75 Correct 14 ms 24532 KB n=2000
76 Correct 17 ms 24552 KB n=2000
77 Correct 17 ms 24584 KB n=2000
78 Correct 17 ms 24532 KB n=2000
79 Correct 17 ms 24588 KB n=2000
80 Correct 15 ms 24532 KB n=2000
81 Correct 16 ms 24524 KB n=2000
82 Correct 16 ms 24524 KB n=2000
83 Correct 16 ms 24620 KB n=2000
84 Correct 16 ms 24492 KB n=2000
85 Correct 16 ms 24532 KB n=2000
86 Correct 17 ms 24544 KB n=2000
87 Correct 17 ms 24556 KB n=2000
88 Correct 18 ms 24608 KB n=2000
89 Correct 18 ms 24624 KB n=2000
90 Correct 15 ms 24532 KB n=2000
91 Correct 14 ms 24600 KB n=2000
92 Correct 1907 ms 87640 KB n=200000
93 Correct 1983 ms 89848 KB n=200000
94 Correct 1764 ms 91640 KB n=200000
95 Correct 1877 ms 87684 KB n=200000
96 Correct 1901 ms 87468 KB n=200000
97 Correct 2198 ms 89208 KB n=200000
98 Correct 1873 ms 87604 KB n=200000
99 Correct 2304 ms 87136 KB n=200000
100 Correct 1967 ms 87576 KB n=200000
101 Correct 1806 ms 92008 KB n=200000
102 Correct 870 ms 88724 KB n=200000
103 Correct 875 ms 88612 KB n=200000
104 Correct 886 ms 88700 KB n=200000
105 Correct 848 ms 88340 KB n=200000
106 Correct 842 ms 88368 KB n=200000
107 Correct 863 ms 88436 KB n=200000
108 Correct 2258 ms 87420 KB n=200000
109 Correct 2171 ms 87380 KB n=200000
110 Correct 2286 ms 87612 KB n=200000
111 Correct 1574 ms 87516 KB n=200000
112 Correct 1714 ms 91620 KB n=200000
113 Correct 2074 ms 89352 KB n=200000
114 Correct 1595 ms 87384 KB n=200000
115 Correct 2441 ms 87900 KB n=200000
116 Correct 1812 ms 87224 KB n=200000
117 Correct 1674 ms 91768 KB n=200000
118 Correct 2159 ms 88468 KB n=200000
119 Correct 1842 ms 87404 KB n=200000
120 Correct 1678 ms 91612 KB n=200000
121 Correct 1631 ms 91652 KB n=200000
122 Correct 1600 ms 92164 KB n=200000
123 Correct 864 ms 87972 KB n=200000
124 Incorrect 267 ms 39372 KB Wrong range.
125 Halted 0 ms 0 KB -