Submission #557796

# Submission time Handle Problem Language Result Execution time Memory
557796 2022-05-06T04:00:26 Z Tien_Noob Birthday gift (IZhO18_treearray) C++17
56 / 100
1067 ms 88684 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 < n)
            {
                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 23764 KB n=5
2 Correct 13 ms 23820 KB n=100
3 Correct 13 ms 23764 KB n=100
4 Correct 12 ms 23764 KB n=100
5 Correct 12 ms 23764 KB n=100
6 Correct 12 ms 23816 KB n=100
7 Correct 13 ms 23916 KB n=100
8 Correct 13 ms 23912 KB n=100
9 Correct 13 ms 23764 KB n=100
10 Correct 14 ms 23820 KB n=100
11 Correct 13 ms 23764 KB n=100
12 Correct 12 ms 23764 KB n=100
13 Correct 14 ms 23800 KB n=100
14 Correct 14 ms 23816 KB n=100
15 Correct 13 ms 23824 KB n=100
16 Correct 13 ms 23764 KB n=100
17 Correct 13 ms 23728 KB n=100
18 Correct 14 ms 23736 KB n=100
19 Correct 13 ms 23776 KB n=100
20 Correct 12 ms 23764 KB n=100
21 Correct 12 ms 23764 KB n=100
22 Correct 13 ms 23764 KB n=100
23 Correct 12 ms 23808 KB n=100
24 Correct 12 ms 23820 KB n=100
25 Correct 13 ms 23764 KB n=100
26 Correct 13 ms 23820 KB n=12
27 Correct 13 ms 23820 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB n=5
2 Correct 13 ms 23820 KB n=100
3 Correct 13 ms 23764 KB n=100
4 Correct 12 ms 23764 KB n=100
5 Correct 12 ms 23764 KB n=100
6 Correct 12 ms 23816 KB n=100
7 Correct 13 ms 23916 KB n=100
8 Correct 13 ms 23912 KB n=100
9 Correct 13 ms 23764 KB n=100
10 Correct 14 ms 23820 KB n=100
11 Correct 13 ms 23764 KB n=100
12 Correct 12 ms 23764 KB n=100
13 Correct 14 ms 23800 KB n=100
14 Correct 14 ms 23816 KB n=100
15 Correct 13 ms 23824 KB n=100
16 Correct 13 ms 23764 KB n=100
17 Correct 13 ms 23728 KB n=100
18 Correct 14 ms 23736 KB n=100
19 Correct 13 ms 23776 KB n=100
20 Correct 12 ms 23764 KB n=100
21 Correct 12 ms 23764 KB n=100
22 Correct 13 ms 23764 KB n=100
23 Correct 12 ms 23808 KB n=100
24 Correct 12 ms 23820 KB n=100
25 Correct 13 ms 23764 KB n=100
26 Correct 13 ms 23820 KB n=12
27 Correct 13 ms 23820 KB n=100
28 Correct 12 ms 23832 KB n=500
29 Correct 13 ms 23956 KB n=500
30 Correct 13 ms 23892 KB n=500
31 Correct 14 ms 23964 KB n=500
32 Correct 12 ms 23892 KB n=500
33 Correct 13 ms 23892 KB n=500
34 Correct 13 ms 23884 KB n=500
35 Correct 14 ms 23964 KB n=500
36 Correct 17 ms 23932 KB n=500
37 Correct 15 ms 23872 KB n=500
38 Correct 13 ms 23908 KB n=500
39 Correct 13 ms 23832 KB n=500
40 Correct 14 ms 23900 KB n=500
41 Correct 13 ms 23892 KB n=500
42 Correct 13 ms 23892 KB n=500
43 Correct 14 ms 23892 KB n=500
44 Correct 16 ms 23820 KB n=500
45 Correct 13 ms 23828 KB n=500
46 Correct 12 ms 23892 KB n=500
47 Correct 13 ms 23944 KB n=500
48 Correct 14 ms 23892 KB n=500
49 Correct 14 ms 23956 KB n=500
50 Correct 13 ms 23892 KB n=500
51 Correct 13 ms 23960 KB n=500
52 Correct 13 ms 23956 KB n=500
53 Correct 13 ms 23956 KB n=500
54 Correct 14 ms 23892 KB n=500
55 Correct 12 ms 23844 KB n=278
56 Correct 13 ms 23892 KB n=500
57 Correct 13 ms 23892 KB n=500
58 Correct 13 ms 23940 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB n=5
2 Correct 13 ms 23820 KB n=100
3 Correct 13 ms 23764 KB n=100
4 Correct 12 ms 23764 KB n=100
5 Correct 12 ms 23764 KB n=100
6 Correct 12 ms 23816 KB n=100
7 Correct 13 ms 23916 KB n=100
8 Correct 13 ms 23912 KB n=100
9 Correct 13 ms 23764 KB n=100
10 Correct 14 ms 23820 KB n=100
11 Correct 13 ms 23764 KB n=100
12 Correct 12 ms 23764 KB n=100
13 Correct 14 ms 23800 KB n=100
14 Correct 14 ms 23816 KB n=100
15 Correct 13 ms 23824 KB n=100
16 Correct 13 ms 23764 KB n=100
17 Correct 13 ms 23728 KB n=100
18 Correct 14 ms 23736 KB n=100
19 Correct 13 ms 23776 KB n=100
20 Correct 12 ms 23764 KB n=100
21 Correct 12 ms 23764 KB n=100
22 Correct 13 ms 23764 KB n=100
23 Correct 12 ms 23808 KB n=100
24 Correct 12 ms 23820 KB n=100
25 Correct 13 ms 23764 KB n=100
26 Correct 13 ms 23820 KB n=12
27 Correct 13 ms 23820 KB n=100
28 Correct 12 ms 23832 KB n=500
29 Correct 13 ms 23956 KB n=500
30 Correct 13 ms 23892 KB n=500
31 Correct 14 ms 23964 KB n=500
32 Correct 12 ms 23892 KB n=500
33 Correct 13 ms 23892 KB n=500
34 Correct 13 ms 23884 KB n=500
35 Correct 14 ms 23964 KB n=500
36 Correct 17 ms 23932 KB n=500
37 Correct 15 ms 23872 KB n=500
38 Correct 13 ms 23908 KB n=500
39 Correct 13 ms 23832 KB n=500
40 Correct 14 ms 23900 KB n=500
41 Correct 13 ms 23892 KB n=500
42 Correct 13 ms 23892 KB n=500
43 Correct 14 ms 23892 KB n=500
44 Correct 16 ms 23820 KB n=500
45 Correct 13 ms 23828 KB n=500
46 Correct 12 ms 23892 KB n=500
47 Correct 13 ms 23944 KB n=500
48 Correct 14 ms 23892 KB n=500
49 Correct 14 ms 23956 KB n=500
50 Correct 13 ms 23892 KB n=500
51 Correct 13 ms 23960 KB n=500
52 Correct 13 ms 23956 KB n=500
53 Correct 13 ms 23956 KB n=500
54 Correct 14 ms 23892 KB n=500
55 Correct 12 ms 23844 KB n=278
56 Correct 13 ms 23892 KB n=500
57 Correct 13 ms 23892 KB n=500
58 Correct 13 ms 23940 KB n=500
59 Correct 15 ms 24276 KB n=2000
60 Correct 15 ms 24404 KB n=2000
61 Correct 15 ms 24268 KB n=2000
62 Correct 17 ms 24276 KB n=2000
63 Correct 16 ms 24276 KB n=2000
64 Correct 17 ms 24276 KB n=2000
65 Correct 20 ms 24296 KB n=2000
66 Correct 17 ms 24404 KB n=2000
67 Correct 16 ms 24216 KB n=2000
68 Correct 16 ms 24276 KB n=2000
69 Correct 15 ms 24276 KB n=2000
70 Correct 15 ms 24216 KB n=2000
71 Correct 15 ms 24276 KB n=2000
72 Correct 15 ms 24212 KB n=2000
73 Correct 16 ms 24216 KB n=2000
74 Correct 15 ms 24212 KB n=1844
75 Correct 15 ms 24224 KB n=2000
76 Correct 16 ms 24276 KB n=2000
77 Correct 16 ms 24220 KB n=2000
78 Correct 16 ms 24276 KB n=2000
79 Correct 15 ms 24304 KB n=2000
80 Correct 16 ms 24404 KB n=2000
81 Correct 16 ms 24344 KB n=2000
82 Correct 16 ms 24296 KB n=2000
83 Correct 15 ms 24340 KB n=2000
84 Correct 15 ms 24208 KB n=2000
85 Correct 17 ms 24276 KB n=2000
86 Correct 16 ms 24324 KB n=2000
87 Correct 17 ms 24276 KB n=2000
88 Correct 15 ms 24388 KB n=2000
89 Correct 15 ms 24404 KB n=2000
90 Correct 15 ms 24408 KB n=2000
91 Correct 19 ms 24220 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB n=5
2 Correct 13 ms 23820 KB n=100
3 Correct 13 ms 23764 KB n=100
4 Correct 12 ms 23764 KB n=100
5 Correct 12 ms 23764 KB n=100
6 Correct 12 ms 23816 KB n=100
7 Correct 13 ms 23916 KB n=100
8 Correct 13 ms 23912 KB n=100
9 Correct 13 ms 23764 KB n=100
10 Correct 14 ms 23820 KB n=100
11 Correct 13 ms 23764 KB n=100
12 Correct 12 ms 23764 KB n=100
13 Correct 14 ms 23800 KB n=100
14 Correct 14 ms 23816 KB n=100
15 Correct 13 ms 23824 KB n=100
16 Correct 13 ms 23764 KB n=100
17 Correct 13 ms 23728 KB n=100
18 Correct 14 ms 23736 KB n=100
19 Correct 13 ms 23776 KB n=100
20 Correct 12 ms 23764 KB n=100
21 Correct 12 ms 23764 KB n=100
22 Correct 13 ms 23764 KB n=100
23 Correct 12 ms 23808 KB n=100
24 Correct 12 ms 23820 KB n=100
25 Correct 13 ms 23764 KB n=100
26 Correct 13 ms 23820 KB n=12
27 Correct 13 ms 23820 KB n=100
28 Correct 12 ms 23832 KB n=500
29 Correct 13 ms 23956 KB n=500
30 Correct 13 ms 23892 KB n=500
31 Correct 14 ms 23964 KB n=500
32 Correct 12 ms 23892 KB n=500
33 Correct 13 ms 23892 KB n=500
34 Correct 13 ms 23884 KB n=500
35 Correct 14 ms 23964 KB n=500
36 Correct 17 ms 23932 KB n=500
37 Correct 15 ms 23872 KB n=500
38 Correct 13 ms 23908 KB n=500
39 Correct 13 ms 23832 KB n=500
40 Correct 14 ms 23900 KB n=500
41 Correct 13 ms 23892 KB n=500
42 Correct 13 ms 23892 KB n=500
43 Correct 14 ms 23892 KB n=500
44 Correct 16 ms 23820 KB n=500
45 Correct 13 ms 23828 KB n=500
46 Correct 12 ms 23892 KB n=500
47 Correct 13 ms 23944 KB n=500
48 Correct 14 ms 23892 KB n=500
49 Correct 14 ms 23956 KB n=500
50 Correct 13 ms 23892 KB n=500
51 Correct 13 ms 23960 KB n=500
52 Correct 13 ms 23956 KB n=500
53 Correct 13 ms 23956 KB n=500
54 Correct 14 ms 23892 KB n=500
55 Correct 12 ms 23844 KB n=278
56 Correct 13 ms 23892 KB n=500
57 Correct 13 ms 23892 KB n=500
58 Correct 13 ms 23940 KB n=500
59 Correct 15 ms 24276 KB n=2000
60 Correct 15 ms 24404 KB n=2000
61 Correct 15 ms 24268 KB n=2000
62 Correct 17 ms 24276 KB n=2000
63 Correct 16 ms 24276 KB n=2000
64 Correct 17 ms 24276 KB n=2000
65 Correct 20 ms 24296 KB n=2000
66 Correct 17 ms 24404 KB n=2000
67 Correct 16 ms 24216 KB n=2000
68 Correct 16 ms 24276 KB n=2000
69 Correct 15 ms 24276 KB n=2000
70 Correct 15 ms 24216 KB n=2000
71 Correct 15 ms 24276 KB n=2000
72 Correct 15 ms 24212 KB n=2000
73 Correct 16 ms 24216 KB n=2000
74 Correct 15 ms 24212 KB n=1844
75 Correct 15 ms 24224 KB n=2000
76 Correct 16 ms 24276 KB n=2000
77 Correct 16 ms 24220 KB n=2000
78 Correct 16 ms 24276 KB n=2000
79 Correct 15 ms 24304 KB n=2000
80 Correct 16 ms 24404 KB n=2000
81 Correct 16 ms 24344 KB n=2000
82 Correct 16 ms 24296 KB n=2000
83 Correct 15 ms 24340 KB n=2000
84 Correct 15 ms 24208 KB n=2000
85 Correct 17 ms 24276 KB n=2000
86 Correct 16 ms 24324 KB n=2000
87 Correct 17 ms 24276 KB n=2000
88 Correct 15 ms 24388 KB n=2000
89 Correct 15 ms 24404 KB n=2000
90 Correct 15 ms 24408 KB n=2000
91 Correct 19 ms 24220 KB n=2000
92 Correct 707 ms 73064 KB n=200000
93 Correct 914 ms 81088 KB n=200000
94 Correct 852 ms 86472 KB n=200000
95 Correct 650 ms 72916 KB n=200000
96 Correct 681 ms 72824 KB n=200000
97 Correct 958 ms 79460 KB n=200000
98 Correct 643 ms 72820 KB n=200000
99 Correct 817 ms 73180 KB n=200000
100 Correct 704 ms 73084 KB n=200000
101 Correct 853 ms 88684 KB n=200000
102 Correct 447 ms 73972 KB n=200000
103 Correct 461 ms 73968 KB n=200000
104 Correct 436 ms 74004 KB n=200000
105 Correct 399 ms 74348 KB n=200000
106 Correct 428 ms 74480 KB n=200000
107 Correct 412 ms 74448 KB n=200000
108 Correct 755 ms 72880 KB n=200000
109 Correct 764 ms 73004 KB n=200000
110 Correct 727 ms 72888 KB n=200000
111 Correct 677 ms 72184 KB n=200000
112 Correct 852 ms 86904 KB n=200000
113 Correct 955 ms 79528 KB n=200000
114 Correct 705 ms 72224 KB n=200000
115 Correct 1067 ms 75968 KB n=200000
116 Correct 630 ms 72892 KB n=200000
117 Correct 816 ms 87864 KB n=200000
118 Correct 973 ms 77712 KB n=200000
119 Correct 613 ms 72904 KB n=200000
120 Correct 745 ms 87704 KB n=200000
121 Correct 817 ms 87900 KB n=200000
122 Correct 824 ms 88124 KB n=200000
123 Correct 451 ms 74144 KB n=200000
124 Incorrect 178 ms 39396 KB Wrong range.
125 Halted 0 ms 0 KB -