답안 #344972

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
344972 2021-01-06T20:24:57 Z Valera_Grinenko Birthday gift (IZhO18_treearray) C++17
100 / 100
1343 ms 92712 KB
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <bitset>
#include <numeric>
#include <array>
#include <cstring>
#include <random>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template<class T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 2e5 + 42, L = 20;
vector<int> g[N];
int a[N];
set<int> haveone[N], havelca[N];
vector<int> tin, tout;
vector<vector<int> > up;
int n, m, q, l;
int timer = 0;
void dfs(int v, int p = 0) {
  tin[v] = ++timer;
  up[v][0] = p;
  for(int i = 1; i <= l; i++)
    up[v][i] = up[up[v][i - 1]][i - 1];
  for(auto& x : g[v])
    if(x != p)
      dfs(x, v);
  tout[v] = ++timer;
}
bool upper(int a, int b) {
  return tin[a] <= tin[b] && tout[a] >= tout[b];
}
int lca(int a, int b) {
  if(upper(a, b)) return a;
  if(upper(b, a)) return b;
  for(int i = l; i >= 0; i--)
    if(!upper(up[a][i], b))
      a = up[a][i];
  return up[a][0];
}
int main() {

  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  cin >> n >> m >> q;

  tin.resize(n); tout.resize(n); up.resize(n);

  l = 1;

  while((1 << l) <= n) l++;

  for(int i = 0; i < n; i++) up[i].resize(l + 1);

  for(int i = 1; i < n; i++) {
    int u, v; cin >> u >> v;
    g[--u].pb(--v);
    g[v].pb(u);
  }

  dfs(0);

  vector<int> a(m);

  for(int i = 0; i < m; i++) {
    cin >> a[i]; a[i]--;
    haveone[a[i]].insert(i);
    if(i) {
      havelca[lca(a[i], a[i - 1])].insert(i - 1);
    }
  }

  while(q--) {
    int type; cin >> type;
    if(type == 1) {
      int pos, v;
      cin >> pos >> v; pos--; v--;
      haveone[a[pos]].erase(pos);
      if(pos > 0) havelca[lca(a[pos], a[pos - 1])].erase(pos - 1);
      if(pos + 1 < m) havelca[lca(a[pos], a[pos + 1])].erase(pos);
      a[pos] = v;
      haveone[a[pos]].insert(pos);
      if(pos > 0) havelca[lca(a[pos], a[pos - 1])].insert(pos - 1);
      if(pos + 1 < m) havelca[lca(a[pos], a[pos + 1])].insert(pos);
    } else {
      int l, r, v;
      cin >> l >> r >> v;
      l--; r--; v--;
      auto it = haveone[v].lower_bound(l);
      if(it != haveone[v].end()) {
        int cur = *it;
        if(cur <= r) { cout << cur + 1 << ' ' << cur + 1 << '\n'; continue; }
      }
      it = havelca[v].lower_bound(l);
      if(it != havelca[v].end()) {
        int cur = *it;
        if(cur + 1 <= r) { cout << cur + 1 << ' ' << cur + 2 << '\n'; continue; }
      }
      cout << "-1 -1\n";
    }
  }

  return 0;
}
/*

*/

Compilation message

treearray.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 23788 KB n=5
2 Correct 17 ms 23788 KB n=100
3 Correct 16 ms 23788 KB n=100
4 Correct 17 ms 23788 KB n=100
5 Correct 16 ms 23788 KB n=100
6 Correct 16 ms 23788 KB n=100
7 Correct 16 ms 23808 KB n=100
8 Correct 17 ms 23788 KB n=100
9 Correct 16 ms 23788 KB n=100
10 Correct 17 ms 23788 KB n=100
11 Correct 17 ms 23788 KB n=100
12 Correct 17 ms 23788 KB n=100
13 Correct 17 ms 23788 KB n=100
14 Correct 16 ms 23788 KB n=100
15 Correct 18 ms 23788 KB n=100
16 Correct 16 ms 23808 KB n=100
17 Correct 16 ms 23788 KB n=100
18 Correct 16 ms 23788 KB n=100
19 Correct 16 ms 23788 KB n=100
20 Correct 16 ms 23788 KB n=100
21 Correct 16 ms 23788 KB n=100
22 Correct 17 ms 23788 KB n=100
23 Correct 17 ms 23788 KB n=100
24 Correct 17 ms 23788 KB n=100
25 Correct 16 ms 23788 KB n=100
26 Correct 16 ms 23936 KB n=12
27 Correct 16 ms 23788 KB n=100
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 23788 KB n=5
2 Correct 17 ms 23788 KB n=100
3 Correct 16 ms 23788 KB n=100
4 Correct 17 ms 23788 KB n=100
5 Correct 16 ms 23788 KB n=100
6 Correct 16 ms 23788 KB n=100
7 Correct 16 ms 23808 KB n=100
8 Correct 17 ms 23788 KB n=100
9 Correct 16 ms 23788 KB n=100
10 Correct 17 ms 23788 KB n=100
11 Correct 17 ms 23788 KB n=100
12 Correct 17 ms 23788 KB n=100
13 Correct 17 ms 23788 KB n=100
14 Correct 16 ms 23788 KB n=100
15 Correct 18 ms 23788 KB n=100
16 Correct 16 ms 23808 KB n=100
17 Correct 16 ms 23788 KB n=100
18 Correct 16 ms 23788 KB n=100
19 Correct 16 ms 23788 KB n=100
20 Correct 16 ms 23788 KB n=100
21 Correct 16 ms 23788 KB n=100
22 Correct 17 ms 23788 KB n=100
23 Correct 17 ms 23788 KB n=100
24 Correct 17 ms 23788 KB n=100
25 Correct 16 ms 23788 KB n=100
26 Correct 16 ms 23936 KB n=12
27 Correct 16 ms 23788 KB n=100
28 Correct 17 ms 23896 KB n=500
29 Correct 16 ms 23936 KB n=500
30 Correct 17 ms 23916 KB n=500
31 Correct 17 ms 23916 KB n=500
32 Correct 17 ms 23916 KB n=500
33 Correct 17 ms 23916 KB n=500
34 Correct 17 ms 23916 KB n=500
35 Correct 17 ms 23916 KB n=500
36 Correct 18 ms 23916 KB n=500
37 Correct 17 ms 23916 KB n=500
38 Correct 17 ms 23916 KB n=500
39 Correct 17 ms 23916 KB n=500
40 Correct 17 ms 23916 KB n=500
41 Correct 17 ms 23916 KB n=500
42 Correct 17 ms 23916 KB n=500
43 Correct 17 ms 23916 KB n=500
44 Correct 17 ms 23916 KB n=500
45 Correct 17 ms 24044 KB n=500
46 Correct 17 ms 23916 KB n=500
47 Correct 17 ms 23916 KB n=500
48 Correct 17 ms 23916 KB n=500
49 Correct 17 ms 23916 KB n=500
50 Correct 17 ms 23916 KB n=500
51 Correct 17 ms 23916 KB n=500
52 Correct 17 ms 23916 KB n=500
53 Correct 18 ms 23916 KB n=500
54 Correct 18 ms 23916 KB n=500
55 Correct 17 ms 23916 KB n=278
56 Correct 17 ms 23936 KB n=500
57 Correct 17 ms 23916 KB n=500
58 Correct 17 ms 23916 KB n=500
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 23788 KB n=5
2 Correct 17 ms 23788 KB n=100
3 Correct 16 ms 23788 KB n=100
4 Correct 17 ms 23788 KB n=100
5 Correct 16 ms 23788 KB n=100
6 Correct 16 ms 23788 KB n=100
7 Correct 16 ms 23808 KB n=100
8 Correct 17 ms 23788 KB n=100
9 Correct 16 ms 23788 KB n=100
10 Correct 17 ms 23788 KB n=100
11 Correct 17 ms 23788 KB n=100
12 Correct 17 ms 23788 KB n=100
13 Correct 17 ms 23788 KB n=100
14 Correct 16 ms 23788 KB n=100
15 Correct 18 ms 23788 KB n=100
16 Correct 16 ms 23808 KB n=100
17 Correct 16 ms 23788 KB n=100
18 Correct 16 ms 23788 KB n=100
19 Correct 16 ms 23788 KB n=100
20 Correct 16 ms 23788 KB n=100
21 Correct 16 ms 23788 KB n=100
22 Correct 17 ms 23788 KB n=100
23 Correct 17 ms 23788 KB n=100
24 Correct 17 ms 23788 KB n=100
25 Correct 16 ms 23788 KB n=100
26 Correct 16 ms 23936 KB n=12
27 Correct 16 ms 23788 KB n=100
28 Correct 17 ms 23896 KB n=500
29 Correct 16 ms 23936 KB n=500
30 Correct 17 ms 23916 KB n=500
31 Correct 17 ms 23916 KB n=500
32 Correct 17 ms 23916 KB n=500
33 Correct 17 ms 23916 KB n=500
34 Correct 17 ms 23916 KB n=500
35 Correct 17 ms 23916 KB n=500
36 Correct 18 ms 23916 KB n=500
37 Correct 17 ms 23916 KB n=500
38 Correct 17 ms 23916 KB n=500
39 Correct 17 ms 23916 KB n=500
40 Correct 17 ms 23916 KB n=500
41 Correct 17 ms 23916 KB n=500
42 Correct 17 ms 23916 KB n=500
43 Correct 17 ms 23916 KB n=500
44 Correct 17 ms 23916 KB n=500
45 Correct 17 ms 24044 KB n=500
46 Correct 17 ms 23916 KB n=500
47 Correct 17 ms 23916 KB n=500
48 Correct 17 ms 23916 KB n=500
49 Correct 17 ms 23916 KB n=500
50 Correct 17 ms 23916 KB n=500
51 Correct 17 ms 23916 KB n=500
52 Correct 17 ms 23916 KB n=500
53 Correct 18 ms 23916 KB n=500
54 Correct 18 ms 23916 KB n=500
55 Correct 17 ms 23916 KB n=278
56 Correct 17 ms 23936 KB n=500
57 Correct 17 ms 23916 KB n=500
58 Correct 17 ms 23916 KB n=500
59 Correct 22 ms 24428 KB n=2000
60 Correct 19 ms 24428 KB n=2000
61 Correct 20 ms 24428 KB n=2000
62 Correct 20 ms 24428 KB n=2000
63 Correct 20 ms 24428 KB n=2000
64 Correct 20 ms 24428 KB n=2000
65 Correct 20 ms 24428 KB n=2000
66 Correct 20 ms 24428 KB n=2000
67 Correct 21 ms 24300 KB n=2000
68 Correct 20 ms 24428 KB n=2000
69 Correct 20 ms 24428 KB n=2000
70 Correct 20 ms 24428 KB n=2000
71 Correct 20 ms 24428 KB n=2000
72 Correct 20 ms 24428 KB n=2000
73 Correct 19 ms 24428 KB n=2000
74 Correct 21 ms 24300 KB n=1844
75 Correct 19 ms 24428 KB n=2000
76 Correct 20 ms 24300 KB n=2000
77 Correct 20 ms 24300 KB n=2000
78 Correct 20 ms 24300 KB n=2000
79 Correct 20 ms 24300 KB n=2000
80 Correct 20 ms 24428 KB n=2000
81 Correct 21 ms 24428 KB n=2000
82 Correct 20 ms 24300 KB n=2000
83 Correct 21 ms 24456 KB n=2000
84 Correct 20 ms 24428 KB n=2000
85 Correct 22 ms 24428 KB n=2000
86 Correct 20 ms 24428 KB n=2000
87 Correct 20 ms 24428 KB n=2000
88 Correct 19 ms 24428 KB n=2000
89 Correct 19 ms 24428 KB n=2000
90 Correct 20 ms 24428 KB n=2000
91 Correct 19 ms 24428 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 23788 KB n=5
2 Correct 17 ms 23788 KB n=100
3 Correct 16 ms 23788 KB n=100
4 Correct 17 ms 23788 KB n=100
5 Correct 16 ms 23788 KB n=100
6 Correct 16 ms 23788 KB n=100
7 Correct 16 ms 23808 KB n=100
8 Correct 17 ms 23788 KB n=100
9 Correct 16 ms 23788 KB n=100
10 Correct 17 ms 23788 KB n=100
11 Correct 17 ms 23788 KB n=100
12 Correct 17 ms 23788 KB n=100
13 Correct 17 ms 23788 KB n=100
14 Correct 16 ms 23788 KB n=100
15 Correct 18 ms 23788 KB n=100
16 Correct 16 ms 23808 KB n=100
17 Correct 16 ms 23788 KB n=100
18 Correct 16 ms 23788 KB n=100
19 Correct 16 ms 23788 KB n=100
20 Correct 16 ms 23788 KB n=100
21 Correct 16 ms 23788 KB n=100
22 Correct 17 ms 23788 KB n=100
23 Correct 17 ms 23788 KB n=100
24 Correct 17 ms 23788 KB n=100
25 Correct 16 ms 23788 KB n=100
26 Correct 16 ms 23936 KB n=12
27 Correct 16 ms 23788 KB n=100
28 Correct 17 ms 23896 KB n=500
29 Correct 16 ms 23936 KB n=500
30 Correct 17 ms 23916 KB n=500
31 Correct 17 ms 23916 KB n=500
32 Correct 17 ms 23916 KB n=500
33 Correct 17 ms 23916 KB n=500
34 Correct 17 ms 23916 KB n=500
35 Correct 17 ms 23916 KB n=500
36 Correct 18 ms 23916 KB n=500
37 Correct 17 ms 23916 KB n=500
38 Correct 17 ms 23916 KB n=500
39 Correct 17 ms 23916 KB n=500
40 Correct 17 ms 23916 KB n=500
41 Correct 17 ms 23916 KB n=500
42 Correct 17 ms 23916 KB n=500
43 Correct 17 ms 23916 KB n=500
44 Correct 17 ms 23916 KB n=500
45 Correct 17 ms 24044 KB n=500
46 Correct 17 ms 23916 KB n=500
47 Correct 17 ms 23916 KB n=500
48 Correct 17 ms 23916 KB n=500
49 Correct 17 ms 23916 KB n=500
50 Correct 17 ms 23916 KB n=500
51 Correct 17 ms 23916 KB n=500
52 Correct 17 ms 23916 KB n=500
53 Correct 18 ms 23916 KB n=500
54 Correct 18 ms 23916 KB n=500
55 Correct 17 ms 23916 KB n=278
56 Correct 17 ms 23936 KB n=500
57 Correct 17 ms 23916 KB n=500
58 Correct 17 ms 23916 KB n=500
59 Correct 22 ms 24428 KB n=2000
60 Correct 19 ms 24428 KB n=2000
61 Correct 20 ms 24428 KB n=2000
62 Correct 20 ms 24428 KB n=2000
63 Correct 20 ms 24428 KB n=2000
64 Correct 20 ms 24428 KB n=2000
65 Correct 20 ms 24428 KB n=2000
66 Correct 20 ms 24428 KB n=2000
67 Correct 21 ms 24300 KB n=2000
68 Correct 20 ms 24428 KB n=2000
69 Correct 20 ms 24428 KB n=2000
70 Correct 20 ms 24428 KB n=2000
71 Correct 20 ms 24428 KB n=2000
72 Correct 20 ms 24428 KB n=2000
73 Correct 19 ms 24428 KB n=2000
74 Correct 21 ms 24300 KB n=1844
75 Correct 19 ms 24428 KB n=2000
76 Correct 20 ms 24300 KB n=2000
77 Correct 20 ms 24300 KB n=2000
78 Correct 20 ms 24300 KB n=2000
79 Correct 20 ms 24300 KB n=2000
80 Correct 20 ms 24428 KB n=2000
81 Correct 21 ms 24428 KB n=2000
82 Correct 20 ms 24300 KB n=2000
83 Correct 21 ms 24456 KB n=2000
84 Correct 20 ms 24428 KB n=2000
85 Correct 22 ms 24428 KB n=2000
86 Correct 20 ms 24428 KB n=2000
87 Correct 20 ms 24428 KB n=2000
88 Correct 19 ms 24428 KB n=2000
89 Correct 19 ms 24428 KB n=2000
90 Correct 20 ms 24428 KB n=2000
91 Correct 19 ms 24428 KB n=2000
92 Correct 906 ms 83388 KB n=200000
93 Correct 1035 ms 88180 KB n=200000
94 Correct 742 ms 91552 KB n=200000
95 Correct 861 ms 83116 KB n=200000
96 Correct 828 ms 83404 KB n=200000
97 Correct 1121 ms 87300 KB n=200000
98 Correct 856 ms 83152 KB n=200000
99 Correct 1029 ms 83300 KB n=200000
100 Correct 856 ms 83300 KB n=200000
101 Correct 671 ms 92712 KB n=200000
102 Correct 569 ms 84380 KB n=200000
103 Correct 549 ms 84228 KB n=200000
104 Correct 553 ms 84332 KB n=200000
105 Correct 569 ms 84716 KB n=200000
106 Correct 547 ms 84596 KB n=200000
107 Correct 556 ms 84652 KB n=200000
108 Correct 976 ms 83164 KB n=200000
109 Correct 976 ms 83160 KB n=200000
110 Correct 942 ms 83308 KB n=200000
111 Correct 870 ms 82656 KB n=200000
112 Correct 711 ms 91988 KB n=200000
113 Correct 1114 ms 87352 KB n=200000
114 Correct 869 ms 82528 KB n=200000
115 Correct 1343 ms 85140 KB n=200000
116 Correct 842 ms 82784 KB n=200000
117 Correct 675 ms 92012 KB n=200000
118 Correct 1190 ms 86236 KB n=200000
119 Correct 811 ms 83388 KB n=200000
120 Correct 598 ms 91756 KB n=200000
121 Correct 592 ms 91764 KB n=200000
122 Correct 611 ms 92140 KB n=200000
123 Correct 557 ms 84588 KB n=200000
124 Correct 213 ms 39404 KB n=25264