Submission #571229

# Submission time Handle Problem Language Result Execution time Memory
571229 2022-06-01T15:16:45 Z YouAreMyGalaxy Birthday gift (IZhO18_treearray) C++17
100 / 100
1333 ms 88028 KB
//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
#define Log2(x) 31 - __builtin_clz(x)
using namespace std;
const int N = 2e5, cbit = 17;
int f[N + 1][cbit + 1], depth[N + 1];
vector<int> adj[N + 1];
set<int> single[N + 1], dual[N + 1];
int n, m, q, a[N + 1];
void read()
{
    cin >> n >> m >> q;
    for (int i = 1; i < n; ++ i)
    {
        int u, v;
        cin >>  u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
}
void DFS(int u, int p)
{
    for (int v : adj[u])
    {
        if (v == p)
        {
            continue;
        }
        depth[v] = depth[u] + 1;
        f[v][0] = u;
        for (int i = 1; i <= cbit; ++ i)
        {
            f[v][i] = f[f[v][i - 1]][i - 1];
        }
        DFS(v, u);
    }
}
int LCA(int u, int v)
{
    if (depth[v] < depth[u])
    {
        swap(u, v);
    }
    int k = depth[v] - depth[u];
    for (int i = cbit; i >= 0; -- i)
    {
        if ((k >> i) & 1)
        {
            v = f[v][i];
        }
    }
    if (u == v)
    {
        return u;
    }
    for (int i = cbit; i >= 0; -- i)
    {
        if (f[u][i] != f[v][i])
        {
            u = f[u][i];
            v = f[v][i];
        }
    }
    return f[u][0];
}
void solve()
{
    DFS(1, 0);
    for (int i = 1; i <= m; ++ i)
    {
        cin >> a[i];
        single[a[i]].insert(i);
        if (i > 1)
        {
            dual[LCA(a[i], a[i - 1])].insert(i - 1);
        }
    }
    while(q--)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            int pos, v;
            cin >> pos >> v;
            single[a[pos]].erase(pos);
            single[v].insert(pos);
            if (pos > 1)
            {
                dual[LCA(a[pos], a[pos - 1])].erase(pos - 1);
                dual[LCA(v, a[pos - 1])].insert(pos - 1);
            }
            if (pos < m)
            {
                dual[LCA(a[pos], a[pos + 1])].erase(pos);
                dual[LCA(v, a[pos + 1])].insert(pos);
            }
            a[pos] = v;
        }
        else
        {
            int l, r, u;
            cin >> l >> r >> u;
            auto it = single[u].lower_bound(l);
            if (it != single[u].end() && *it <= r)
            {
                cout << *it << ' ' << *it << '\n';
                continue;
            }
            it = dual[u].lower_bound(l);
            if (it != dual[u].end() && *it < r)
            {
                cout << *it << ' ' << *it + 1 << '\n';
                continue;
            }
            cout << -1 << ' ' << -1 << '\n';
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen(TASK".INP", "r"))
    {
        freopen(TASK".INP", "r", stdin);
        //freopen(TASK".OUT", "w", stdout);
    }
    int t = 1;
    bool typetest = false;
    if (typetest)
    {
        cin >> t;
    }
    for (int __ = 1; __ <= t; ++ __)
    {
        //cout << "Case " << __ << ": ";
        read();
        solve();
    }
}

Compilation message

treearray.cpp: In function 'int main()':
treearray.cpp:128:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  128 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23820 KB n=5
2 Correct 14 ms 23808 KB n=100
3 Correct 15 ms 23732 KB n=100
4 Correct 15 ms 23840 KB n=100
5 Correct 19 ms 23772 KB n=100
6 Correct 15 ms 23808 KB n=100
7 Correct 15 ms 23868 KB n=100
8 Correct 15 ms 23832 KB n=100
9 Correct 14 ms 23788 KB n=100
10 Correct 14 ms 23820 KB n=100
11 Correct 14 ms 23776 KB n=100
12 Correct 19 ms 23828 KB n=100
13 Correct 14 ms 23764 KB n=100
14 Correct 16 ms 23780 KB n=100
15 Correct 16 ms 23764 KB n=100
16 Correct 18 ms 23816 KB n=100
17 Correct 17 ms 23760 KB n=100
18 Correct 19 ms 23820 KB n=100
19 Correct 16 ms 23812 KB n=100
20 Correct 15 ms 23764 KB n=100
21 Correct 16 ms 23752 KB n=100
22 Correct 15 ms 23820 KB n=100
23 Correct 14 ms 23764 KB n=100
24 Correct 16 ms 23764 KB n=100
25 Correct 15 ms 23744 KB n=100
26 Correct 18 ms 23788 KB n=12
27 Correct 17 ms 23772 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23820 KB n=5
2 Correct 14 ms 23808 KB n=100
3 Correct 15 ms 23732 KB n=100
4 Correct 15 ms 23840 KB n=100
5 Correct 19 ms 23772 KB n=100
6 Correct 15 ms 23808 KB n=100
7 Correct 15 ms 23868 KB n=100
8 Correct 15 ms 23832 KB n=100
9 Correct 14 ms 23788 KB n=100
10 Correct 14 ms 23820 KB n=100
11 Correct 14 ms 23776 KB n=100
12 Correct 19 ms 23828 KB n=100
13 Correct 14 ms 23764 KB n=100
14 Correct 16 ms 23780 KB n=100
15 Correct 16 ms 23764 KB n=100
16 Correct 18 ms 23816 KB n=100
17 Correct 17 ms 23760 KB n=100
18 Correct 19 ms 23820 KB n=100
19 Correct 16 ms 23812 KB n=100
20 Correct 15 ms 23764 KB n=100
21 Correct 16 ms 23752 KB n=100
22 Correct 15 ms 23820 KB n=100
23 Correct 14 ms 23764 KB n=100
24 Correct 16 ms 23764 KB n=100
25 Correct 15 ms 23744 KB n=100
26 Correct 18 ms 23788 KB n=12
27 Correct 17 ms 23772 KB n=100
28 Correct 16 ms 23892 KB n=500
29 Correct 18 ms 23964 KB n=500
30 Correct 15 ms 23820 KB n=500
31 Correct 22 ms 23912 KB n=500
32 Correct 18 ms 23848 KB n=500
33 Correct 19 ms 23924 KB n=500
34 Correct 18 ms 23892 KB n=500
35 Correct 17 ms 23864 KB n=500
36 Correct 18 ms 23884 KB n=500
37 Correct 19 ms 23832 KB n=500
38 Correct 15 ms 23832 KB n=500
39 Correct 15 ms 23852 KB n=500
40 Correct 18 ms 23920 KB n=500
41 Correct 17 ms 23824 KB n=500
42 Correct 16 ms 23892 KB n=500
43 Correct 17 ms 23852 KB n=500
44 Correct 19 ms 23808 KB n=500
45 Correct 17 ms 23824 KB n=500
46 Correct 18 ms 23892 KB n=500
47 Correct 18 ms 23948 KB n=500
48 Correct 18 ms 23808 KB n=500
49 Correct 17 ms 23928 KB n=500
50 Correct 18 ms 23828 KB n=500
51 Correct 20 ms 23880 KB n=500
52 Correct 16 ms 24004 KB n=500
53 Correct 21 ms 23836 KB n=500
54 Correct 17 ms 23952 KB n=500
55 Correct 17 ms 23872 KB n=278
56 Correct 15 ms 23952 KB n=500
57 Correct 20 ms 23924 KB n=500
58 Correct 19 ms 23908 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23820 KB n=5
2 Correct 14 ms 23808 KB n=100
3 Correct 15 ms 23732 KB n=100
4 Correct 15 ms 23840 KB n=100
5 Correct 19 ms 23772 KB n=100
6 Correct 15 ms 23808 KB n=100
7 Correct 15 ms 23868 KB n=100
8 Correct 15 ms 23832 KB n=100
9 Correct 14 ms 23788 KB n=100
10 Correct 14 ms 23820 KB n=100
11 Correct 14 ms 23776 KB n=100
12 Correct 19 ms 23828 KB n=100
13 Correct 14 ms 23764 KB n=100
14 Correct 16 ms 23780 KB n=100
15 Correct 16 ms 23764 KB n=100
16 Correct 18 ms 23816 KB n=100
17 Correct 17 ms 23760 KB n=100
18 Correct 19 ms 23820 KB n=100
19 Correct 16 ms 23812 KB n=100
20 Correct 15 ms 23764 KB n=100
21 Correct 16 ms 23752 KB n=100
22 Correct 15 ms 23820 KB n=100
23 Correct 14 ms 23764 KB n=100
24 Correct 16 ms 23764 KB n=100
25 Correct 15 ms 23744 KB n=100
26 Correct 18 ms 23788 KB n=12
27 Correct 17 ms 23772 KB n=100
28 Correct 16 ms 23892 KB n=500
29 Correct 18 ms 23964 KB n=500
30 Correct 15 ms 23820 KB n=500
31 Correct 22 ms 23912 KB n=500
32 Correct 18 ms 23848 KB n=500
33 Correct 19 ms 23924 KB n=500
34 Correct 18 ms 23892 KB n=500
35 Correct 17 ms 23864 KB n=500
36 Correct 18 ms 23884 KB n=500
37 Correct 19 ms 23832 KB n=500
38 Correct 15 ms 23832 KB n=500
39 Correct 15 ms 23852 KB n=500
40 Correct 18 ms 23920 KB n=500
41 Correct 17 ms 23824 KB n=500
42 Correct 16 ms 23892 KB n=500
43 Correct 17 ms 23852 KB n=500
44 Correct 19 ms 23808 KB n=500
45 Correct 17 ms 23824 KB n=500
46 Correct 18 ms 23892 KB n=500
47 Correct 18 ms 23948 KB n=500
48 Correct 18 ms 23808 KB n=500
49 Correct 17 ms 23928 KB n=500
50 Correct 18 ms 23828 KB n=500
51 Correct 20 ms 23880 KB n=500
52 Correct 16 ms 24004 KB n=500
53 Correct 21 ms 23836 KB n=500
54 Correct 17 ms 23952 KB n=500
55 Correct 17 ms 23872 KB n=278
56 Correct 15 ms 23952 KB n=500
57 Correct 20 ms 23924 KB n=500
58 Correct 19 ms 23908 KB n=500
59 Correct 23 ms 24204 KB n=2000
60 Correct 17 ms 24316 KB n=2000
61 Correct 18 ms 24292 KB n=2000
62 Correct 17 ms 24340 KB n=2000
63 Correct 22 ms 24276 KB n=2000
64 Correct 18 ms 24272 KB n=2000
65 Correct 18 ms 24216 KB n=2000
66 Correct 20 ms 24404 KB n=2000
67 Correct 24 ms 24216 KB n=2000
68 Correct 21 ms 24348 KB n=2000
69 Correct 17 ms 24276 KB n=2000
70 Correct 16 ms 24216 KB n=2000
71 Correct 20 ms 24292 KB n=2000
72 Correct 20 ms 24228 KB n=2000
73 Correct 21 ms 24280 KB n=2000
74 Correct 19 ms 24240 KB n=1844
75 Correct 19 ms 24212 KB n=2000
76 Correct 21 ms 24332 KB n=2000
77 Correct 21 ms 24296 KB n=2000
78 Correct 24 ms 24224 KB n=2000
79 Correct 22 ms 24168 KB n=2000
80 Correct 21 ms 24332 KB n=2000
81 Correct 17 ms 24352 KB n=2000
82 Correct 23 ms 24212 KB n=2000
83 Correct 18 ms 24404 KB n=2000
84 Correct 20 ms 24208 KB n=2000
85 Correct 16 ms 24304 KB n=2000
86 Correct 19 ms 24296 KB n=2000
87 Correct 20 ms 24204 KB n=2000
88 Correct 22 ms 24424 KB n=2000
89 Correct 21 ms 24404 KB n=2000
90 Correct 21 ms 24412 KB n=2000
91 Correct 17 ms 24296 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23820 KB n=5
2 Correct 14 ms 23808 KB n=100
3 Correct 15 ms 23732 KB n=100
4 Correct 15 ms 23840 KB n=100
5 Correct 19 ms 23772 KB n=100
6 Correct 15 ms 23808 KB n=100
7 Correct 15 ms 23868 KB n=100
8 Correct 15 ms 23832 KB n=100
9 Correct 14 ms 23788 KB n=100
10 Correct 14 ms 23820 KB n=100
11 Correct 14 ms 23776 KB n=100
12 Correct 19 ms 23828 KB n=100
13 Correct 14 ms 23764 KB n=100
14 Correct 16 ms 23780 KB n=100
15 Correct 16 ms 23764 KB n=100
16 Correct 18 ms 23816 KB n=100
17 Correct 17 ms 23760 KB n=100
18 Correct 19 ms 23820 KB n=100
19 Correct 16 ms 23812 KB n=100
20 Correct 15 ms 23764 KB n=100
21 Correct 16 ms 23752 KB n=100
22 Correct 15 ms 23820 KB n=100
23 Correct 14 ms 23764 KB n=100
24 Correct 16 ms 23764 KB n=100
25 Correct 15 ms 23744 KB n=100
26 Correct 18 ms 23788 KB n=12
27 Correct 17 ms 23772 KB n=100
28 Correct 16 ms 23892 KB n=500
29 Correct 18 ms 23964 KB n=500
30 Correct 15 ms 23820 KB n=500
31 Correct 22 ms 23912 KB n=500
32 Correct 18 ms 23848 KB n=500
33 Correct 19 ms 23924 KB n=500
34 Correct 18 ms 23892 KB n=500
35 Correct 17 ms 23864 KB n=500
36 Correct 18 ms 23884 KB n=500
37 Correct 19 ms 23832 KB n=500
38 Correct 15 ms 23832 KB n=500
39 Correct 15 ms 23852 KB n=500
40 Correct 18 ms 23920 KB n=500
41 Correct 17 ms 23824 KB n=500
42 Correct 16 ms 23892 KB n=500
43 Correct 17 ms 23852 KB n=500
44 Correct 19 ms 23808 KB n=500
45 Correct 17 ms 23824 KB n=500
46 Correct 18 ms 23892 KB n=500
47 Correct 18 ms 23948 KB n=500
48 Correct 18 ms 23808 KB n=500
49 Correct 17 ms 23928 KB n=500
50 Correct 18 ms 23828 KB n=500
51 Correct 20 ms 23880 KB n=500
52 Correct 16 ms 24004 KB n=500
53 Correct 21 ms 23836 KB n=500
54 Correct 17 ms 23952 KB n=500
55 Correct 17 ms 23872 KB n=278
56 Correct 15 ms 23952 KB n=500
57 Correct 20 ms 23924 KB n=500
58 Correct 19 ms 23908 KB n=500
59 Correct 23 ms 24204 KB n=2000
60 Correct 17 ms 24316 KB n=2000
61 Correct 18 ms 24292 KB n=2000
62 Correct 17 ms 24340 KB n=2000
63 Correct 22 ms 24276 KB n=2000
64 Correct 18 ms 24272 KB n=2000
65 Correct 18 ms 24216 KB n=2000
66 Correct 20 ms 24404 KB n=2000
67 Correct 24 ms 24216 KB n=2000
68 Correct 21 ms 24348 KB n=2000
69 Correct 17 ms 24276 KB n=2000
70 Correct 16 ms 24216 KB n=2000
71 Correct 20 ms 24292 KB n=2000
72 Correct 20 ms 24228 KB n=2000
73 Correct 21 ms 24280 KB n=2000
74 Correct 19 ms 24240 KB n=1844
75 Correct 19 ms 24212 KB n=2000
76 Correct 21 ms 24332 KB n=2000
77 Correct 21 ms 24296 KB n=2000
78 Correct 24 ms 24224 KB n=2000
79 Correct 22 ms 24168 KB n=2000
80 Correct 21 ms 24332 KB n=2000
81 Correct 17 ms 24352 KB n=2000
82 Correct 23 ms 24212 KB n=2000
83 Correct 18 ms 24404 KB n=2000
84 Correct 20 ms 24208 KB n=2000
85 Correct 16 ms 24304 KB n=2000
86 Correct 19 ms 24296 KB n=2000
87 Correct 20 ms 24204 KB n=2000
88 Correct 22 ms 24424 KB n=2000
89 Correct 21 ms 24404 KB n=2000
90 Correct 21 ms 24412 KB n=2000
91 Correct 17 ms 24296 KB n=2000
92 Correct 845 ms 72920 KB n=200000
93 Correct 1233 ms 79640 KB n=200000
94 Correct 983 ms 85208 KB n=200000
95 Correct 756 ms 72664 KB n=200000
96 Correct 877 ms 72752 KB n=200000
97 Correct 1333 ms 78628 KB n=200000
98 Correct 920 ms 72768 KB n=200000
99 Correct 987 ms 72620 KB n=200000
100 Correct 714 ms 72896 KB n=200000
101 Correct 948 ms 87796 KB n=200000
102 Correct 471 ms 73976 KB n=200000
103 Correct 540 ms 74032 KB n=200000
104 Correct 562 ms 73952 KB n=200000
105 Correct 540 ms 73924 KB n=200000
106 Correct 561 ms 73820 KB n=200000
107 Correct 517 ms 73936 KB n=200000
108 Correct 909 ms 72856 KB n=200000
109 Correct 1022 ms 72800 KB n=200000
110 Correct 977 ms 72828 KB n=200000
111 Correct 776 ms 72276 KB n=200000
112 Correct 887 ms 86068 KB n=200000
113 Correct 1049 ms 78508 KB n=200000
114 Correct 751 ms 72220 KB n=200000
115 Correct 1225 ms 74980 KB n=200000
116 Correct 784 ms 72844 KB n=200000
117 Correct 1022 ms 86716 KB n=200000
118 Correct 1285 ms 76772 KB n=200000
119 Correct 697 ms 72920 KB n=200000
120 Correct 887 ms 87596 KB n=200000
121 Correct 863 ms 87484 KB n=200000
122 Correct 951 ms 88028 KB n=200000
123 Correct 578 ms 73580 KB n=200000
124 Correct 280 ms 39172 KB n=25264