Submission #696086

# Submission time Handle Problem Language Result Execution time Memory
696086 2023-02-05T11:33:35 Z Abrar_Al_Samit Birthday gift (IZhO18_treearray) C++17
100 / 100
1120 ms 83928 KB
#include<bits/stdc++.h>
using namespace std;

const int nax = 2e5 + 3;

vector<int>g[nax];

int n, m, q;
int a[nax];
int sp[nax][18];
int tt(0);
int st[nax], en[nax], dep[nax];
set<int>S[nax], T[nax];

bool anc(int x, int y) {
  return st[x]<=st[y] && en[x]>=en[y];
}
int getlca(int x, int y) {
  if(x==0) return y;
  if(y==0) return x;

  for(int j=17; j>=0; --j) {
    if(!anc(sp[x][j], y)) {
      x = sp[x][j];
    }
  }
  if(!anc(x, y)) x = sp[x][0];
  return x;
}
void DFS(int v, int par = 1) {
  dep[v] = 1+dep[par];
  st[v] = tt++;

  sp[v][0] = par;
  for(int j=1; j<18; ++j) {
    sp[v][j] = sp[sp[v][j-1]][j-1];
  }

  for(int u : g[v]) if(u!=par) {
    DFS(u, v);
  }
  en[v] = tt++;
}
void PlayGround() {
  cin>>n>>m>>q;

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

  dep[1] = -1;
  DFS(1);


  for(int i=1; i<=m; ++i) {
    S[a[i]].insert(i);

    if(i<m) {
      T[getlca(a[i], a[i+1])].insert(i+1);
    }
  }

  while(q--) {
    int t;
    cin>>t;
    if(t==1) {
      int pos, v;
      cin>>pos>>v;

      S[a[pos]].erase(pos);
      S[v].insert(pos);

      if(pos<m) {
        T[getlca(a[pos], a[pos+1])].erase(pos+1);
        T[getlca(a[pos+1], v)].insert(pos+1);
      }
      if(pos>1) {
        T[getlca(a[pos], a[pos-1])].erase(pos);
        T[getlca(a[pos-1], v)].insert(pos);
      }
      a[pos] = v;

    } else {
      int l, r, v;
      cin>>l>>r>>v;

      if(S[v].lower_bound(l)!=S[v].end() && *S[v].lower_bound(l)<=r) {
        cout<<*S[v].lower_bound(l)<<' '<<*S[v].lower_bound(l)<<'\n';
        continue;
      }
      if(T[v].lower_bound(l+1)!=T[v].end() && *T[v].lower_bound(l+1)<=r) {
        cout<<*T[v].lower_bound(l+1)-1<<' '<<*T[v].lower_bound(l+1)<<'\n';
        continue;
      }
      cout<<"-1 -1\n";
    } 
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  PlayGround();
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23764 KB n=5
2 Correct 11 ms 23764 KB n=100
3 Correct 11 ms 23764 KB n=100
4 Correct 11 ms 23848 KB n=100
5 Correct 11 ms 23764 KB n=100
6 Correct 12 ms 23772 KB n=100
7 Correct 11 ms 23764 KB n=100
8 Correct 11 ms 23804 KB n=100
9 Correct 13 ms 23820 KB n=100
10 Correct 11 ms 23820 KB n=100
11 Correct 14 ms 23764 KB n=100
12 Correct 11 ms 23764 KB n=100
13 Correct 11 ms 23764 KB n=100
14 Correct 13 ms 23820 KB n=100
15 Correct 11 ms 23792 KB n=100
16 Correct 14 ms 23756 KB n=100
17 Correct 10 ms 23764 KB n=100
18 Correct 13 ms 23764 KB n=100
19 Correct 13 ms 23816 KB n=100
20 Correct 11 ms 23816 KB n=100
21 Correct 11 ms 23844 KB n=100
22 Correct 11 ms 23856 KB n=100
23 Correct 11 ms 23856 KB n=100
24 Correct 13 ms 23764 KB n=100
25 Correct 11 ms 23812 KB n=100
26 Correct 12 ms 23892 KB n=12
27 Correct 12 ms 23812 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23764 KB n=5
2 Correct 11 ms 23764 KB n=100
3 Correct 11 ms 23764 KB n=100
4 Correct 11 ms 23848 KB n=100
5 Correct 11 ms 23764 KB n=100
6 Correct 12 ms 23772 KB n=100
7 Correct 11 ms 23764 KB n=100
8 Correct 11 ms 23804 KB n=100
9 Correct 13 ms 23820 KB n=100
10 Correct 11 ms 23820 KB n=100
11 Correct 14 ms 23764 KB n=100
12 Correct 11 ms 23764 KB n=100
13 Correct 11 ms 23764 KB n=100
14 Correct 13 ms 23820 KB n=100
15 Correct 11 ms 23792 KB n=100
16 Correct 14 ms 23756 KB n=100
17 Correct 10 ms 23764 KB n=100
18 Correct 13 ms 23764 KB n=100
19 Correct 13 ms 23816 KB n=100
20 Correct 11 ms 23816 KB n=100
21 Correct 11 ms 23844 KB n=100
22 Correct 11 ms 23856 KB n=100
23 Correct 11 ms 23856 KB n=100
24 Correct 13 ms 23764 KB n=100
25 Correct 11 ms 23812 KB n=100
26 Correct 12 ms 23892 KB n=12
27 Correct 12 ms 23812 KB n=100
28 Correct 12 ms 23892 KB n=500
29 Correct 12 ms 23904 KB n=500
30 Correct 12 ms 23956 KB n=500
31 Correct 12 ms 23856 KB n=500
32 Correct 13 ms 23948 KB n=500
33 Correct 12 ms 23892 KB n=500
34 Correct 13 ms 23892 KB n=500
35 Correct 14 ms 23956 KB n=500
36 Correct 13 ms 23892 KB n=500
37 Correct 11 ms 23892 KB n=500
38 Correct 12 ms 23956 KB n=500
39 Correct 12 ms 23892 KB n=500
40 Correct 12 ms 23884 KB n=500
41 Correct 12 ms 23956 KB n=500
42 Correct 12 ms 23892 KB n=500
43 Correct 12 ms 23892 KB n=500
44 Correct 15 ms 23816 KB n=500
45 Correct 12 ms 23948 KB n=500
46 Correct 12 ms 23956 KB n=500
47 Correct 13 ms 23892 KB n=500
48 Correct 12 ms 24012 KB n=500
49 Correct 12 ms 23892 KB n=500
50 Correct 13 ms 24020 KB n=500
51 Correct 12 ms 23892 KB n=500
52 Correct 13 ms 23872 KB n=500
53 Correct 12 ms 23892 KB n=500
54 Correct 12 ms 23948 KB n=500
55 Correct 11 ms 23816 KB n=278
56 Correct 12 ms 23892 KB n=500
57 Correct 12 ms 23892 KB n=500
58 Correct 13 ms 23892 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23764 KB n=5
2 Correct 11 ms 23764 KB n=100
3 Correct 11 ms 23764 KB n=100
4 Correct 11 ms 23848 KB n=100
5 Correct 11 ms 23764 KB n=100
6 Correct 12 ms 23772 KB n=100
7 Correct 11 ms 23764 KB n=100
8 Correct 11 ms 23804 KB n=100
9 Correct 13 ms 23820 KB n=100
10 Correct 11 ms 23820 KB n=100
11 Correct 14 ms 23764 KB n=100
12 Correct 11 ms 23764 KB n=100
13 Correct 11 ms 23764 KB n=100
14 Correct 13 ms 23820 KB n=100
15 Correct 11 ms 23792 KB n=100
16 Correct 14 ms 23756 KB n=100
17 Correct 10 ms 23764 KB n=100
18 Correct 13 ms 23764 KB n=100
19 Correct 13 ms 23816 KB n=100
20 Correct 11 ms 23816 KB n=100
21 Correct 11 ms 23844 KB n=100
22 Correct 11 ms 23856 KB n=100
23 Correct 11 ms 23856 KB n=100
24 Correct 13 ms 23764 KB n=100
25 Correct 11 ms 23812 KB n=100
26 Correct 12 ms 23892 KB n=12
27 Correct 12 ms 23812 KB n=100
28 Correct 12 ms 23892 KB n=500
29 Correct 12 ms 23904 KB n=500
30 Correct 12 ms 23956 KB n=500
31 Correct 12 ms 23856 KB n=500
32 Correct 13 ms 23948 KB n=500
33 Correct 12 ms 23892 KB n=500
34 Correct 13 ms 23892 KB n=500
35 Correct 14 ms 23956 KB n=500
36 Correct 13 ms 23892 KB n=500
37 Correct 11 ms 23892 KB n=500
38 Correct 12 ms 23956 KB n=500
39 Correct 12 ms 23892 KB n=500
40 Correct 12 ms 23884 KB n=500
41 Correct 12 ms 23956 KB n=500
42 Correct 12 ms 23892 KB n=500
43 Correct 12 ms 23892 KB n=500
44 Correct 15 ms 23816 KB n=500
45 Correct 12 ms 23948 KB n=500
46 Correct 12 ms 23956 KB n=500
47 Correct 13 ms 23892 KB n=500
48 Correct 12 ms 24012 KB n=500
49 Correct 12 ms 23892 KB n=500
50 Correct 13 ms 24020 KB n=500
51 Correct 12 ms 23892 KB n=500
52 Correct 13 ms 23872 KB n=500
53 Correct 12 ms 23892 KB n=500
54 Correct 12 ms 23948 KB n=500
55 Correct 11 ms 23816 KB n=278
56 Correct 12 ms 23892 KB n=500
57 Correct 12 ms 23892 KB n=500
58 Correct 13 ms 23892 KB n=500
59 Correct 14 ms 24276 KB n=2000
60 Correct 16 ms 24404 KB n=2000
61 Correct 15 ms 24324 KB n=2000
62 Correct 15 ms 24332 KB n=2000
63 Correct 15 ms 24272 KB n=2000
64 Correct 14 ms 24276 KB n=2000
65 Correct 14 ms 24276 KB n=2000
66 Correct 17 ms 24284 KB n=2000
67 Correct 14 ms 24268 KB n=2000
68 Correct 14 ms 24276 KB n=2000
69 Correct 18 ms 24240 KB n=2000
70 Correct 16 ms 24316 KB n=2000
71 Correct 14 ms 24216 KB n=2000
72 Correct 15 ms 24332 KB n=2000
73 Correct 14 ms 24320 KB n=2000
74 Correct 14 ms 24220 KB n=1844
75 Correct 14 ms 24280 KB n=2000
76 Correct 14 ms 24276 KB n=2000
77 Correct 14 ms 24212 KB n=2000
78 Correct 14 ms 24328 KB n=2000
79 Correct 15 ms 24296 KB n=2000
80 Correct 14 ms 24276 KB n=2000
81 Correct 14 ms 24336 KB n=2000
82 Correct 22 ms 24268 KB n=2000
83 Correct 16 ms 24328 KB n=2000
84 Correct 14 ms 24212 KB n=2000
85 Correct 14 ms 24292 KB n=2000
86 Correct 15 ms 24340 KB n=2000
87 Correct 20 ms 24308 KB n=2000
88 Correct 20 ms 24296 KB n=2000
89 Correct 15 ms 24404 KB n=2000
90 Correct 16 ms 24412 KB n=2000
91 Correct 14 ms 24208 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23764 KB n=5
2 Correct 11 ms 23764 KB n=100
3 Correct 11 ms 23764 KB n=100
4 Correct 11 ms 23848 KB n=100
5 Correct 11 ms 23764 KB n=100
6 Correct 12 ms 23772 KB n=100
7 Correct 11 ms 23764 KB n=100
8 Correct 11 ms 23804 KB n=100
9 Correct 13 ms 23820 KB n=100
10 Correct 11 ms 23820 KB n=100
11 Correct 14 ms 23764 KB n=100
12 Correct 11 ms 23764 KB n=100
13 Correct 11 ms 23764 KB n=100
14 Correct 13 ms 23820 KB n=100
15 Correct 11 ms 23792 KB n=100
16 Correct 14 ms 23756 KB n=100
17 Correct 10 ms 23764 KB n=100
18 Correct 13 ms 23764 KB n=100
19 Correct 13 ms 23816 KB n=100
20 Correct 11 ms 23816 KB n=100
21 Correct 11 ms 23844 KB n=100
22 Correct 11 ms 23856 KB n=100
23 Correct 11 ms 23856 KB n=100
24 Correct 13 ms 23764 KB n=100
25 Correct 11 ms 23812 KB n=100
26 Correct 12 ms 23892 KB n=12
27 Correct 12 ms 23812 KB n=100
28 Correct 12 ms 23892 KB n=500
29 Correct 12 ms 23904 KB n=500
30 Correct 12 ms 23956 KB n=500
31 Correct 12 ms 23856 KB n=500
32 Correct 13 ms 23948 KB n=500
33 Correct 12 ms 23892 KB n=500
34 Correct 13 ms 23892 KB n=500
35 Correct 14 ms 23956 KB n=500
36 Correct 13 ms 23892 KB n=500
37 Correct 11 ms 23892 KB n=500
38 Correct 12 ms 23956 KB n=500
39 Correct 12 ms 23892 KB n=500
40 Correct 12 ms 23884 KB n=500
41 Correct 12 ms 23956 KB n=500
42 Correct 12 ms 23892 KB n=500
43 Correct 12 ms 23892 KB n=500
44 Correct 15 ms 23816 KB n=500
45 Correct 12 ms 23948 KB n=500
46 Correct 12 ms 23956 KB n=500
47 Correct 13 ms 23892 KB n=500
48 Correct 12 ms 24012 KB n=500
49 Correct 12 ms 23892 KB n=500
50 Correct 13 ms 24020 KB n=500
51 Correct 12 ms 23892 KB n=500
52 Correct 13 ms 23872 KB n=500
53 Correct 12 ms 23892 KB n=500
54 Correct 12 ms 23948 KB n=500
55 Correct 11 ms 23816 KB n=278
56 Correct 12 ms 23892 KB n=500
57 Correct 12 ms 23892 KB n=500
58 Correct 13 ms 23892 KB n=500
59 Correct 14 ms 24276 KB n=2000
60 Correct 16 ms 24404 KB n=2000
61 Correct 15 ms 24324 KB n=2000
62 Correct 15 ms 24332 KB n=2000
63 Correct 15 ms 24272 KB n=2000
64 Correct 14 ms 24276 KB n=2000
65 Correct 14 ms 24276 KB n=2000
66 Correct 17 ms 24284 KB n=2000
67 Correct 14 ms 24268 KB n=2000
68 Correct 14 ms 24276 KB n=2000
69 Correct 18 ms 24240 KB n=2000
70 Correct 16 ms 24316 KB n=2000
71 Correct 14 ms 24216 KB n=2000
72 Correct 15 ms 24332 KB n=2000
73 Correct 14 ms 24320 KB n=2000
74 Correct 14 ms 24220 KB n=1844
75 Correct 14 ms 24280 KB n=2000
76 Correct 14 ms 24276 KB n=2000
77 Correct 14 ms 24212 KB n=2000
78 Correct 14 ms 24328 KB n=2000
79 Correct 15 ms 24296 KB n=2000
80 Correct 14 ms 24276 KB n=2000
81 Correct 14 ms 24336 KB n=2000
82 Correct 22 ms 24268 KB n=2000
83 Correct 16 ms 24328 KB n=2000
84 Correct 14 ms 24212 KB n=2000
85 Correct 14 ms 24292 KB n=2000
86 Correct 15 ms 24340 KB n=2000
87 Correct 20 ms 24308 KB n=2000
88 Correct 20 ms 24296 KB n=2000
89 Correct 15 ms 24404 KB n=2000
90 Correct 16 ms 24412 KB n=2000
91 Correct 14 ms 24208 KB n=2000
92 Correct 762 ms 74552 KB n=200000
93 Correct 1120 ms 79476 KB n=200000
94 Correct 955 ms 82832 KB n=200000
95 Correct 731 ms 74348 KB n=200000
96 Correct 674 ms 74376 KB n=200000
97 Correct 1061 ms 78596 KB n=200000
98 Correct 719 ms 74412 KB n=200000
99 Correct 790 ms 74496 KB n=200000
100 Correct 632 ms 74376 KB n=200000
101 Correct 901 ms 83928 KB n=200000
102 Correct 399 ms 75464 KB n=200000
103 Correct 389 ms 75596 KB n=200000
104 Correct 394 ms 75568 KB n=200000
105 Correct 418 ms 75900 KB n=200000
106 Correct 409 ms 75888 KB n=200000
107 Correct 391 ms 75944 KB n=200000
108 Correct 751 ms 74404 KB n=200000
109 Correct 726 ms 74380 KB n=200000
110 Correct 709 ms 74392 KB n=200000
111 Correct 698 ms 73828 KB n=200000
112 Correct 908 ms 82992 KB n=200000
113 Correct 957 ms 78556 KB n=200000
114 Correct 699 ms 73876 KB n=200000
115 Correct 1039 ms 76412 KB n=200000
116 Correct 615 ms 74556 KB n=200000
117 Correct 873 ms 83376 KB n=200000
118 Correct 954 ms 77336 KB n=200000
119 Correct 599 ms 74492 KB n=200000
120 Correct 850 ms 83136 KB n=200000
121 Correct 876 ms 83028 KB n=200000
122 Correct 826 ms 83232 KB n=200000
123 Correct 446 ms 75704 KB n=200000
124 Correct 211 ms 38664 KB n=25264