Submission #492394

# Submission time Handle Problem Language Result Execution time Memory
492394 2021-12-07T04:26:20 Z generic_placeholder_name Birthday gift (IZhO18_treearray) C++17
100 / 100
1144 ms 72876 KB
#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops")
#pragma GCC target("avx,avx2,fma")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include <ext/rope>
 
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define gcd __gcd
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define rep(i, n) for (int i=0; i<(n); i++)
#define rep1(i, n) for (int i=1; i<=(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl "\n"
 
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned uint;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
template<typename T, typename cmp = less<T>>
using ordered_set=tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
typedef trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> pref_trie;
 
constexpr int N = 2e5 + 5;
constexpr int K = 18;
 
vi adj[N];
int dep[N];
int par[N][K + 1];
 
void dfs(int u = 0, int p = -1){
    rep1(i, K) par[u][i] = par[par[u][i - 1]][i - 1];
    for(int v: adj[u]) if(v != p) {
        par[v][0] = u;
        dep[v] = dep[u] + 1;
        dfs(v, u);
    }
}
 
int lca(int u, int v) {
    if(u == v) return u;
    if(dep[u] > dep[v]) swap(u, v);
    for(int i = K; ~i; i--) {
        if(dep[par[v][i]] >= dep[u]) {
            v = par[v][i];
        }
    }
    if(u == v) return u;
    for(int i = K; ~i; i--) {
        if(par[u][i] != par[v][i]) {
            u = par[u][i];
            v = par[v][i];
        }
    }
    return par[u][0];
}
 
int a[N];
set<int> id[N][2];
 
int32_t main() {
    fastio;
    int n, m, q; cin >> n >> m >> q;
    rep(_, n - 1) {
        int u, v; cin >> u >> v; --u, --v;
        adj[u].eb(v);
        adj[v].eb(u);
    }
    dfs();
    rep(i, m) cin >> a[i], --a[i];
    rep(i, m) id[a[i]][0].insert(i);
    rep(i, m - 1) id[lca(a[i], a[i + 1])][1].insert(i);
    while(q--) {
        int t; cin >> t;
        if(t == 1) {
            int i, x; cin >> i >> x; --i, --x;
            if(i + 1 < m) {
                id[lca(a[i], a[i + 1])][1].erase(i);
                id[lca(x, a[i + 1])][1].insert(i);
            }
            if(i > 0) {
                id[lca(a[i - 1], a[i])][1].erase(i - 1);
                id[lca(a[i - 1], x)][1].insert(i - 1);
            }
            id[a[i]][0].erase(i);
            id[x][0].insert(i);
            a[i] = x;
        }
        else {
            int l, r, v; cin >> l >> r >> v; --l, --r, --v;
            auto x = id[v][0].lower_bound(l);
            auto y = id[v][1].lower_bound(l);
            if(x != id[v][0].end() && *x <= r) cout << 1 + *x << ' ' << 1 + *x << endl;
            else if(y != id[v][1].end() && *y < r) cout << 1 + *y << ' ' << 2 + *y << endl;
            else cout << "-1 -1\n";
        }
    }
}

Compilation message

treearray.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization("unroll-loops")
      |
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB n=5
2 Correct 13 ms 23824 KB n=100
3 Correct 13 ms 23804 KB n=100
4 Correct 13 ms 23804 KB n=100
5 Correct 13 ms 23832 KB n=100
6 Correct 13 ms 23756 KB n=100
7 Correct 13 ms 23756 KB n=100
8 Correct 13 ms 23732 KB n=100
9 Correct 14 ms 23756 KB n=100
10 Correct 13 ms 23728 KB n=100
11 Correct 13 ms 23808 KB n=100
12 Correct 16 ms 23756 KB n=100
13 Correct 17 ms 23740 KB n=100
14 Correct 14 ms 23764 KB n=100
15 Correct 13 ms 23756 KB n=100
16 Correct 12 ms 23756 KB n=100
17 Correct 13 ms 23756 KB n=100
18 Correct 13 ms 23832 KB n=100
19 Correct 13 ms 23756 KB n=100
20 Correct 13 ms 23788 KB n=100
21 Correct 13 ms 23764 KB n=100
22 Correct 12 ms 23756 KB n=100
23 Correct 13 ms 23756 KB n=100
24 Correct 13 ms 23768 KB n=100
25 Correct 16 ms 23756 KB n=100
26 Correct 13 ms 23820 KB n=12
27 Correct 14 ms 23744 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB n=5
2 Correct 13 ms 23824 KB n=100
3 Correct 13 ms 23804 KB n=100
4 Correct 13 ms 23804 KB n=100
5 Correct 13 ms 23832 KB n=100
6 Correct 13 ms 23756 KB n=100
7 Correct 13 ms 23756 KB n=100
8 Correct 13 ms 23732 KB n=100
9 Correct 14 ms 23756 KB n=100
10 Correct 13 ms 23728 KB n=100
11 Correct 13 ms 23808 KB n=100
12 Correct 16 ms 23756 KB n=100
13 Correct 17 ms 23740 KB n=100
14 Correct 14 ms 23764 KB n=100
15 Correct 13 ms 23756 KB n=100
16 Correct 12 ms 23756 KB n=100
17 Correct 13 ms 23756 KB n=100
18 Correct 13 ms 23832 KB n=100
19 Correct 13 ms 23756 KB n=100
20 Correct 13 ms 23788 KB n=100
21 Correct 13 ms 23764 KB n=100
22 Correct 12 ms 23756 KB n=100
23 Correct 13 ms 23756 KB n=100
24 Correct 13 ms 23768 KB n=100
25 Correct 16 ms 23756 KB n=100
26 Correct 13 ms 23820 KB n=12
27 Correct 14 ms 23744 KB n=100
28 Correct 15 ms 23884 KB n=500
29 Correct 15 ms 23924 KB n=500
30 Correct 13 ms 23844 KB n=500
31 Correct 14 ms 23884 KB n=500
32 Correct 14 ms 23912 KB n=500
33 Correct 14 ms 23884 KB n=500
34 Correct 15 ms 23916 KB n=500
35 Correct 13 ms 23936 KB n=500
36 Correct 14 ms 23840 KB n=500
37 Correct 13 ms 23908 KB n=500
38 Correct 13 ms 23932 KB n=500
39 Correct 13 ms 23936 KB n=500
40 Correct 13 ms 23884 KB n=500
41 Correct 15 ms 23884 KB n=500
42 Correct 13 ms 23884 KB n=500
43 Correct 14 ms 23884 KB n=500
44 Correct 14 ms 23884 KB n=500
45 Correct 13 ms 23876 KB n=500
46 Correct 15 ms 23980 KB n=500
47 Correct 13 ms 23884 KB n=500
48 Correct 14 ms 23832 KB n=500
49 Correct 15 ms 23872 KB n=500
50 Correct 14 ms 23808 KB n=500
51 Correct 13 ms 23884 KB n=500
52 Correct 12 ms 23936 KB n=500
53 Correct 13 ms 23840 KB n=500
54 Correct 13 ms 23872 KB n=500
55 Correct 13 ms 23784 KB n=278
56 Correct 13 ms 23884 KB n=500
57 Correct 13 ms 23876 KB n=500
58 Correct 13 ms 23884 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB n=5
2 Correct 13 ms 23824 KB n=100
3 Correct 13 ms 23804 KB n=100
4 Correct 13 ms 23804 KB n=100
5 Correct 13 ms 23832 KB n=100
6 Correct 13 ms 23756 KB n=100
7 Correct 13 ms 23756 KB n=100
8 Correct 13 ms 23732 KB n=100
9 Correct 14 ms 23756 KB n=100
10 Correct 13 ms 23728 KB n=100
11 Correct 13 ms 23808 KB n=100
12 Correct 16 ms 23756 KB n=100
13 Correct 17 ms 23740 KB n=100
14 Correct 14 ms 23764 KB n=100
15 Correct 13 ms 23756 KB n=100
16 Correct 12 ms 23756 KB n=100
17 Correct 13 ms 23756 KB n=100
18 Correct 13 ms 23832 KB n=100
19 Correct 13 ms 23756 KB n=100
20 Correct 13 ms 23788 KB n=100
21 Correct 13 ms 23764 KB n=100
22 Correct 12 ms 23756 KB n=100
23 Correct 13 ms 23756 KB n=100
24 Correct 13 ms 23768 KB n=100
25 Correct 16 ms 23756 KB n=100
26 Correct 13 ms 23820 KB n=12
27 Correct 14 ms 23744 KB n=100
28 Correct 15 ms 23884 KB n=500
29 Correct 15 ms 23924 KB n=500
30 Correct 13 ms 23844 KB n=500
31 Correct 14 ms 23884 KB n=500
32 Correct 14 ms 23912 KB n=500
33 Correct 14 ms 23884 KB n=500
34 Correct 15 ms 23916 KB n=500
35 Correct 13 ms 23936 KB n=500
36 Correct 14 ms 23840 KB n=500
37 Correct 13 ms 23908 KB n=500
38 Correct 13 ms 23932 KB n=500
39 Correct 13 ms 23936 KB n=500
40 Correct 13 ms 23884 KB n=500
41 Correct 15 ms 23884 KB n=500
42 Correct 13 ms 23884 KB n=500
43 Correct 14 ms 23884 KB n=500
44 Correct 14 ms 23884 KB n=500
45 Correct 13 ms 23876 KB n=500
46 Correct 15 ms 23980 KB n=500
47 Correct 13 ms 23884 KB n=500
48 Correct 14 ms 23832 KB n=500
49 Correct 15 ms 23872 KB n=500
50 Correct 14 ms 23808 KB n=500
51 Correct 13 ms 23884 KB n=500
52 Correct 12 ms 23936 KB n=500
53 Correct 13 ms 23840 KB n=500
54 Correct 13 ms 23872 KB n=500
55 Correct 13 ms 23784 KB n=278
56 Correct 13 ms 23884 KB n=500
57 Correct 13 ms 23876 KB n=500
58 Correct 13 ms 23884 KB n=500
59 Correct 16 ms 24244 KB n=2000
60 Correct 17 ms 24276 KB n=2000
61 Correct 16 ms 24180 KB n=2000
62 Correct 16 ms 24260 KB n=2000
63 Correct 16 ms 24196 KB n=2000
64 Correct 16 ms 24268 KB n=2000
65 Correct 17 ms 24140 KB n=2000
66 Correct 16 ms 24280 KB n=2000
67 Correct 16 ms 24192 KB n=2000
68 Correct 16 ms 24268 KB n=2000
69 Correct 17 ms 24168 KB n=2000
70 Correct 16 ms 24268 KB n=2000
71 Correct 16 ms 24140 KB n=2000
72 Correct 15 ms 24140 KB n=2000
73 Correct 15 ms 24140 KB n=2000
74 Correct 16 ms 24140 KB n=1844
75 Correct 15 ms 24140 KB n=2000
76 Correct 16 ms 24140 KB n=2000
77 Correct 16 ms 24172 KB n=2000
78 Correct 20 ms 24140 KB n=2000
79 Correct 16 ms 24140 KB n=2000
80 Correct 16 ms 24288 KB n=2000
81 Correct 17 ms 24264 KB n=2000
82 Correct 16 ms 24248 KB n=2000
83 Correct 17 ms 24268 KB n=2000
84 Correct 15 ms 24140 KB n=2000
85 Correct 16 ms 24268 KB n=2000
86 Correct 17 ms 24204 KB n=2000
87 Correct 16 ms 24140 KB n=2000
88 Correct 16 ms 24396 KB n=2000
89 Correct 16 ms 24264 KB n=2000
90 Correct 16 ms 24208 KB n=2000
91 Correct 15 ms 24188 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB n=5
2 Correct 13 ms 23824 KB n=100
3 Correct 13 ms 23804 KB n=100
4 Correct 13 ms 23804 KB n=100
5 Correct 13 ms 23832 KB n=100
6 Correct 13 ms 23756 KB n=100
7 Correct 13 ms 23756 KB n=100
8 Correct 13 ms 23732 KB n=100
9 Correct 14 ms 23756 KB n=100
10 Correct 13 ms 23728 KB n=100
11 Correct 13 ms 23808 KB n=100
12 Correct 16 ms 23756 KB n=100
13 Correct 17 ms 23740 KB n=100
14 Correct 14 ms 23764 KB n=100
15 Correct 13 ms 23756 KB n=100
16 Correct 12 ms 23756 KB n=100
17 Correct 13 ms 23756 KB n=100
18 Correct 13 ms 23832 KB n=100
19 Correct 13 ms 23756 KB n=100
20 Correct 13 ms 23788 KB n=100
21 Correct 13 ms 23764 KB n=100
22 Correct 12 ms 23756 KB n=100
23 Correct 13 ms 23756 KB n=100
24 Correct 13 ms 23768 KB n=100
25 Correct 16 ms 23756 KB n=100
26 Correct 13 ms 23820 KB n=12
27 Correct 14 ms 23744 KB n=100
28 Correct 15 ms 23884 KB n=500
29 Correct 15 ms 23924 KB n=500
30 Correct 13 ms 23844 KB n=500
31 Correct 14 ms 23884 KB n=500
32 Correct 14 ms 23912 KB n=500
33 Correct 14 ms 23884 KB n=500
34 Correct 15 ms 23916 KB n=500
35 Correct 13 ms 23936 KB n=500
36 Correct 14 ms 23840 KB n=500
37 Correct 13 ms 23908 KB n=500
38 Correct 13 ms 23932 KB n=500
39 Correct 13 ms 23936 KB n=500
40 Correct 13 ms 23884 KB n=500
41 Correct 15 ms 23884 KB n=500
42 Correct 13 ms 23884 KB n=500
43 Correct 14 ms 23884 KB n=500
44 Correct 14 ms 23884 KB n=500
45 Correct 13 ms 23876 KB n=500
46 Correct 15 ms 23980 KB n=500
47 Correct 13 ms 23884 KB n=500
48 Correct 14 ms 23832 KB n=500
49 Correct 15 ms 23872 KB n=500
50 Correct 14 ms 23808 KB n=500
51 Correct 13 ms 23884 KB n=500
52 Correct 12 ms 23936 KB n=500
53 Correct 13 ms 23840 KB n=500
54 Correct 13 ms 23872 KB n=500
55 Correct 13 ms 23784 KB n=278
56 Correct 13 ms 23884 KB n=500
57 Correct 13 ms 23876 KB n=500
58 Correct 13 ms 23884 KB n=500
59 Correct 16 ms 24244 KB n=2000
60 Correct 17 ms 24276 KB n=2000
61 Correct 16 ms 24180 KB n=2000
62 Correct 16 ms 24260 KB n=2000
63 Correct 16 ms 24196 KB n=2000
64 Correct 16 ms 24268 KB n=2000
65 Correct 17 ms 24140 KB n=2000
66 Correct 16 ms 24280 KB n=2000
67 Correct 16 ms 24192 KB n=2000
68 Correct 16 ms 24268 KB n=2000
69 Correct 17 ms 24168 KB n=2000
70 Correct 16 ms 24268 KB n=2000
71 Correct 16 ms 24140 KB n=2000
72 Correct 15 ms 24140 KB n=2000
73 Correct 15 ms 24140 KB n=2000
74 Correct 16 ms 24140 KB n=1844
75 Correct 15 ms 24140 KB n=2000
76 Correct 16 ms 24140 KB n=2000
77 Correct 16 ms 24172 KB n=2000
78 Correct 20 ms 24140 KB n=2000
79 Correct 16 ms 24140 KB n=2000
80 Correct 16 ms 24288 KB n=2000
81 Correct 17 ms 24264 KB n=2000
82 Correct 16 ms 24248 KB n=2000
83 Correct 17 ms 24268 KB n=2000
84 Correct 15 ms 24140 KB n=2000
85 Correct 16 ms 24268 KB n=2000
86 Correct 17 ms 24204 KB n=2000
87 Correct 16 ms 24140 KB n=2000
88 Correct 16 ms 24396 KB n=2000
89 Correct 16 ms 24264 KB n=2000
90 Correct 16 ms 24208 KB n=2000
91 Correct 15 ms 24188 KB n=2000
92 Correct 672 ms 67296 KB n=200000
93 Correct 1103 ms 69768 KB n=200000
94 Correct 1047 ms 72016 KB n=200000
95 Correct 663 ms 67248 KB n=200000
96 Correct 653 ms 67156 KB n=200000
97 Correct 1092 ms 68976 KB n=200000
98 Correct 700 ms 67252 KB n=200000
99 Correct 843 ms 66608 KB n=200000
100 Correct 684 ms 67316 KB n=200000
101 Correct 1072 ms 72876 KB n=200000
102 Correct 399 ms 68016 KB n=200000
103 Correct 446 ms 68060 KB n=200000
104 Correct 407 ms 68096 KB n=200000
105 Correct 408 ms 67780 KB n=200000
106 Correct 399 ms 67780 KB n=200000
107 Correct 428 ms 67848 KB n=200000
108 Correct 769 ms 66756 KB n=200000
109 Correct 786 ms 66796 KB n=200000
110 Correct 841 ms 66772 KB n=200000
111 Correct 710 ms 67176 KB n=200000
112 Correct 1090 ms 72084 KB n=200000
113 Correct 1101 ms 68932 KB n=200000
114 Correct 745 ms 67160 KB n=200000
115 Correct 1134 ms 67480 KB n=200000
116 Correct 631 ms 66908 KB n=200000
117 Correct 1020 ms 72252 KB n=200000
118 Correct 1144 ms 68068 KB n=200000
119 Correct 638 ms 66816 KB n=200000
120 Correct 990 ms 72428 KB n=200000
121 Correct 987 ms 72400 KB n=200000
122 Correct 1020 ms 72848 KB n=200000
123 Correct 466 ms 67452 KB n=200000
124 Correct 285 ms 36316 KB n=25264