답안 #1034469

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1034469 2024-07-25T14:09:12 Z pera Birthday gift (IZhO18_treearray) C++17
100 / 100
1116 ms 92584 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1 , LOG = 20;
int n , m , q;
vector<int> a(N) , d(N) , LCA(N);
vector<vector<int>> g(N) , up(N , vector<int>(LOG));
set<int> E[N] , O[N];
void dfs(int u , int p = 1){
   up[u][0] = p;
   d[u] = d[p] + 1;
   for(int x = 0;x < (int)g[u].size();x ++){
      if(g[u][x] != p){
         dfs(g[u][x] , u);
      }
   }
}
int lca(int u , int v){
   if(d[u] < d[v]){
      swap(u , v);
   }
   int s = d[u] - d[v];
   for(int bit = 0;bit < LOG;bit ++){
      if(s >> bit & 1){
         u = up[u][bit];
      }
   }
   if(u == v){
      return u;
   }
   for(int bit = LOG - 1;bit >= 0;bit --){
      if(up[u][bit] != up[v][bit]){
         u = up[u][bit];
         v = up[v][bit];
      }
   }
   return up[u][0];
}
int main(){
   cin >> n >> m >> q;
   for(int x = 1;x < n;x ++){
      int u , v;
      cin >> u >> v;
      g[u].push_back(v);
      g[v].push_back(u);
   }
   dfs(1);
   for(int bit = 1;bit < LOG;bit ++){
      for(int x = 1;x <= n;x ++){
         up[x][bit] = up[up[x][bit - 1]][bit - 1];
      }
   }
   for(int x = 1;x <= m;x ++){
      cin >> a[x];
      E[a[x]].insert(x);
      if(x > 1){
         LCA[x - 1] = lca(a[x] , a[x - 1]);
         O[LCA[x - 1]].insert(x - 1);
      }
   }
   for(int i = 1;i <= q;i ++){
      int type;
      cin >> type;
      if(type == 1){
         int pos , v;
         cin >> pos >> v;
         E[a[pos]].erase(pos);
         if(pos < m){
            O[LCA[pos]].erase(pos);
         }
         if(pos > 1){
            O[LCA[pos - 1]].erase(pos - 1);
         }
         a[pos] = v;
         E[a[pos]].insert(pos);
         if(pos < m){
            LCA[pos] = lca(a[pos] , a[pos + 1]);
            O[LCA[pos]].insert(pos);
         }
         if(pos > 1){
            LCA[pos - 1] = lca(a[pos - 1] , a[pos]);
            O[LCA[pos - 1]].insert(pos - 1);
         }
      }else{
         int l , r , v;
         cin >> l >> r >> v;
         auto it = E[v].lower_bound(l);
         if(it != E[v].end() && *it <= r){
            cout << *it << " " << *it << endl;
            continue;
         }
         it = O[v].lower_bound(l);
         if(it != O[v].end() && *it < r){
            cout << *it << " " << *it + 1 << endl;
            continue;
         }
         cout << -1 << " " << -1 << endl;
      }
   }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 49756 KB n=5
2 Correct 30 ms 49756 KB n=100
3 Correct 25 ms 49752 KB n=100
4 Correct 24 ms 49776 KB n=100
5 Correct 24 ms 50004 KB n=100
6 Correct 24 ms 49756 KB n=100
7 Correct 25 ms 49756 KB n=100
8 Correct 29 ms 49756 KB n=100
9 Correct 25 ms 49756 KB n=100
10 Correct 26 ms 49756 KB n=100
11 Correct 24 ms 49752 KB n=100
12 Correct 24 ms 49740 KB n=100
13 Correct 24 ms 49764 KB n=100
14 Correct 27 ms 49756 KB n=100
15 Correct 24 ms 49752 KB n=100
16 Correct 26 ms 49756 KB n=100
17 Correct 23 ms 49752 KB n=100
18 Correct 25 ms 49752 KB n=100
19 Correct 24 ms 49756 KB n=100
20 Correct 23 ms 49756 KB n=100
21 Correct 25 ms 49752 KB n=100
22 Correct 31 ms 49748 KB n=100
23 Correct 23 ms 49756 KB n=100
24 Correct 29 ms 49756 KB n=100
25 Correct 24 ms 49744 KB n=100
26 Correct 30 ms 49732 KB n=12
27 Correct 35 ms 49612 KB n=100
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 49756 KB n=5
2 Correct 30 ms 49756 KB n=100
3 Correct 25 ms 49752 KB n=100
4 Correct 24 ms 49776 KB n=100
5 Correct 24 ms 50004 KB n=100
6 Correct 24 ms 49756 KB n=100
7 Correct 25 ms 49756 KB n=100
8 Correct 29 ms 49756 KB n=100
9 Correct 25 ms 49756 KB n=100
10 Correct 26 ms 49756 KB n=100
11 Correct 24 ms 49752 KB n=100
12 Correct 24 ms 49740 KB n=100
13 Correct 24 ms 49764 KB n=100
14 Correct 27 ms 49756 KB n=100
15 Correct 24 ms 49752 KB n=100
16 Correct 26 ms 49756 KB n=100
17 Correct 23 ms 49752 KB n=100
18 Correct 25 ms 49752 KB n=100
19 Correct 24 ms 49756 KB n=100
20 Correct 23 ms 49756 KB n=100
21 Correct 25 ms 49752 KB n=100
22 Correct 31 ms 49748 KB n=100
23 Correct 23 ms 49756 KB n=100
24 Correct 29 ms 49756 KB n=100
25 Correct 24 ms 49744 KB n=100
26 Correct 30 ms 49732 KB n=12
27 Correct 35 ms 49612 KB n=100
28 Correct 25 ms 49776 KB n=500
29 Correct 25 ms 49756 KB n=500
30 Correct 24 ms 49756 KB n=500
31 Correct 24 ms 49756 KB n=500
32 Correct 25 ms 49696 KB n=500
33 Correct 33 ms 49684 KB n=500
34 Correct 25 ms 49756 KB n=500
35 Correct 24 ms 49840 KB n=500
36 Correct 24 ms 49704 KB n=500
37 Correct 25 ms 49752 KB n=500
38 Correct 24 ms 49756 KB n=500
39 Correct 26 ms 49756 KB n=500
40 Correct 26 ms 49756 KB n=500
41 Correct 24 ms 49752 KB n=500
42 Correct 24 ms 49756 KB n=500
43 Correct 25 ms 49756 KB n=500
44 Correct 24 ms 49756 KB n=500
45 Correct 24 ms 49756 KB n=500
46 Correct 24 ms 49752 KB n=500
47 Correct 25 ms 49756 KB n=500
48 Correct 24 ms 49756 KB n=500
49 Correct 28 ms 49752 KB n=500
50 Correct 24 ms 49756 KB n=500
51 Correct 24 ms 49616 KB n=500
52 Correct 24 ms 49672 KB n=500
53 Correct 24 ms 49820 KB n=500
54 Correct 25 ms 49752 KB n=500
55 Correct 33 ms 49756 KB n=278
56 Correct 28 ms 50076 KB n=500
57 Correct 24 ms 50000 KB n=500
58 Correct 24 ms 49752 KB n=500
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 49756 KB n=5
2 Correct 30 ms 49756 KB n=100
3 Correct 25 ms 49752 KB n=100
4 Correct 24 ms 49776 KB n=100
5 Correct 24 ms 50004 KB n=100
6 Correct 24 ms 49756 KB n=100
7 Correct 25 ms 49756 KB n=100
8 Correct 29 ms 49756 KB n=100
9 Correct 25 ms 49756 KB n=100
10 Correct 26 ms 49756 KB n=100
11 Correct 24 ms 49752 KB n=100
12 Correct 24 ms 49740 KB n=100
13 Correct 24 ms 49764 KB n=100
14 Correct 27 ms 49756 KB n=100
15 Correct 24 ms 49752 KB n=100
16 Correct 26 ms 49756 KB n=100
17 Correct 23 ms 49752 KB n=100
18 Correct 25 ms 49752 KB n=100
19 Correct 24 ms 49756 KB n=100
20 Correct 23 ms 49756 KB n=100
21 Correct 25 ms 49752 KB n=100
22 Correct 31 ms 49748 KB n=100
23 Correct 23 ms 49756 KB n=100
24 Correct 29 ms 49756 KB n=100
25 Correct 24 ms 49744 KB n=100
26 Correct 30 ms 49732 KB n=12
27 Correct 35 ms 49612 KB n=100
28 Correct 25 ms 49776 KB n=500
29 Correct 25 ms 49756 KB n=500
30 Correct 24 ms 49756 KB n=500
31 Correct 24 ms 49756 KB n=500
32 Correct 25 ms 49696 KB n=500
33 Correct 33 ms 49684 KB n=500
34 Correct 25 ms 49756 KB n=500
35 Correct 24 ms 49840 KB n=500
36 Correct 24 ms 49704 KB n=500
37 Correct 25 ms 49752 KB n=500
38 Correct 24 ms 49756 KB n=500
39 Correct 26 ms 49756 KB n=500
40 Correct 26 ms 49756 KB n=500
41 Correct 24 ms 49752 KB n=500
42 Correct 24 ms 49756 KB n=500
43 Correct 25 ms 49756 KB n=500
44 Correct 24 ms 49756 KB n=500
45 Correct 24 ms 49756 KB n=500
46 Correct 24 ms 49752 KB n=500
47 Correct 25 ms 49756 KB n=500
48 Correct 24 ms 49756 KB n=500
49 Correct 28 ms 49752 KB n=500
50 Correct 24 ms 49756 KB n=500
51 Correct 24 ms 49616 KB n=500
52 Correct 24 ms 49672 KB n=500
53 Correct 24 ms 49820 KB n=500
54 Correct 25 ms 49752 KB n=500
55 Correct 33 ms 49756 KB n=278
56 Correct 28 ms 50076 KB n=500
57 Correct 24 ms 50000 KB n=500
58 Correct 24 ms 49752 KB n=500
59 Correct 28 ms 50012 KB n=2000
60 Correct 28 ms 50132 KB n=2000
61 Correct 28 ms 50000 KB n=2000
62 Correct 28 ms 50012 KB n=2000
63 Correct 27 ms 50012 KB n=2000
64 Correct 28 ms 50008 KB n=2000
65 Correct 27 ms 50012 KB n=2000
66 Correct 28 ms 50036 KB n=2000
67 Correct 27 ms 50012 KB n=2000
68 Correct 33 ms 49884 KB n=2000
69 Correct 28 ms 50012 KB n=2000
70 Correct 28 ms 50008 KB n=2000
71 Correct 28 ms 50008 KB n=2000
72 Correct 28 ms 50000 KB n=2000
73 Correct 35 ms 50520 KB n=2000
74 Correct 26 ms 50008 KB n=1844
75 Correct 32 ms 50008 KB n=2000
76 Correct 27 ms 50012 KB n=2000
77 Correct 27 ms 50012 KB n=2000
78 Correct 37 ms 49888 KB n=2000
79 Correct 32 ms 50268 KB n=2000
80 Correct 27 ms 49956 KB n=2000
81 Correct 28 ms 50008 KB n=2000
82 Correct 28 ms 50008 KB n=2000
83 Correct 28 ms 50012 KB n=2000
84 Correct 28 ms 50004 KB n=2000
85 Correct 28 ms 50008 KB n=2000
86 Correct 28 ms 50040 KB n=2000
87 Correct 28 ms 49940 KB n=2000
88 Correct 40 ms 50136 KB n=2000
89 Correct 28 ms 50012 KB n=2000
90 Correct 28 ms 50012 KB n=2000
91 Correct 34 ms 50004 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 49756 KB n=5
2 Correct 30 ms 49756 KB n=100
3 Correct 25 ms 49752 KB n=100
4 Correct 24 ms 49776 KB n=100
5 Correct 24 ms 50004 KB n=100
6 Correct 24 ms 49756 KB n=100
7 Correct 25 ms 49756 KB n=100
8 Correct 29 ms 49756 KB n=100
9 Correct 25 ms 49756 KB n=100
10 Correct 26 ms 49756 KB n=100
11 Correct 24 ms 49752 KB n=100
12 Correct 24 ms 49740 KB n=100
13 Correct 24 ms 49764 KB n=100
14 Correct 27 ms 49756 KB n=100
15 Correct 24 ms 49752 KB n=100
16 Correct 26 ms 49756 KB n=100
17 Correct 23 ms 49752 KB n=100
18 Correct 25 ms 49752 KB n=100
19 Correct 24 ms 49756 KB n=100
20 Correct 23 ms 49756 KB n=100
21 Correct 25 ms 49752 KB n=100
22 Correct 31 ms 49748 KB n=100
23 Correct 23 ms 49756 KB n=100
24 Correct 29 ms 49756 KB n=100
25 Correct 24 ms 49744 KB n=100
26 Correct 30 ms 49732 KB n=12
27 Correct 35 ms 49612 KB n=100
28 Correct 25 ms 49776 KB n=500
29 Correct 25 ms 49756 KB n=500
30 Correct 24 ms 49756 KB n=500
31 Correct 24 ms 49756 KB n=500
32 Correct 25 ms 49696 KB n=500
33 Correct 33 ms 49684 KB n=500
34 Correct 25 ms 49756 KB n=500
35 Correct 24 ms 49840 KB n=500
36 Correct 24 ms 49704 KB n=500
37 Correct 25 ms 49752 KB n=500
38 Correct 24 ms 49756 KB n=500
39 Correct 26 ms 49756 KB n=500
40 Correct 26 ms 49756 KB n=500
41 Correct 24 ms 49752 KB n=500
42 Correct 24 ms 49756 KB n=500
43 Correct 25 ms 49756 KB n=500
44 Correct 24 ms 49756 KB n=500
45 Correct 24 ms 49756 KB n=500
46 Correct 24 ms 49752 KB n=500
47 Correct 25 ms 49756 KB n=500
48 Correct 24 ms 49756 KB n=500
49 Correct 28 ms 49752 KB n=500
50 Correct 24 ms 49756 KB n=500
51 Correct 24 ms 49616 KB n=500
52 Correct 24 ms 49672 KB n=500
53 Correct 24 ms 49820 KB n=500
54 Correct 25 ms 49752 KB n=500
55 Correct 33 ms 49756 KB n=278
56 Correct 28 ms 50076 KB n=500
57 Correct 24 ms 50000 KB n=500
58 Correct 24 ms 49752 KB n=500
59 Correct 28 ms 50012 KB n=2000
60 Correct 28 ms 50132 KB n=2000
61 Correct 28 ms 50000 KB n=2000
62 Correct 28 ms 50012 KB n=2000
63 Correct 27 ms 50012 KB n=2000
64 Correct 28 ms 50008 KB n=2000
65 Correct 27 ms 50012 KB n=2000
66 Correct 28 ms 50036 KB n=2000
67 Correct 27 ms 50012 KB n=2000
68 Correct 33 ms 49884 KB n=2000
69 Correct 28 ms 50012 KB n=2000
70 Correct 28 ms 50008 KB n=2000
71 Correct 28 ms 50008 KB n=2000
72 Correct 28 ms 50000 KB n=2000
73 Correct 35 ms 50520 KB n=2000
74 Correct 26 ms 50008 KB n=1844
75 Correct 32 ms 50008 KB n=2000
76 Correct 27 ms 50012 KB n=2000
77 Correct 27 ms 50012 KB n=2000
78 Correct 37 ms 49888 KB n=2000
79 Correct 32 ms 50268 KB n=2000
80 Correct 27 ms 49956 KB n=2000
81 Correct 28 ms 50008 KB n=2000
82 Correct 28 ms 50008 KB n=2000
83 Correct 28 ms 50012 KB n=2000
84 Correct 28 ms 50004 KB n=2000
85 Correct 28 ms 50008 KB n=2000
86 Correct 28 ms 50040 KB n=2000
87 Correct 28 ms 49940 KB n=2000
88 Correct 40 ms 50136 KB n=2000
89 Correct 28 ms 50012 KB n=2000
90 Correct 28 ms 50012 KB n=2000
91 Correct 34 ms 50004 KB n=2000
92 Correct 713 ms 83120 KB n=200000
93 Correct 894 ms 88144 KB n=200000
94 Correct 952 ms 91396 KB n=200000
95 Correct 640 ms 82996 KB n=200000
96 Correct 668 ms 83140 KB n=200000
97 Correct 895 ms 87120 KB n=200000
98 Correct 780 ms 83116 KB n=200000
99 Correct 898 ms 83304 KB n=200000
100 Correct 879 ms 82996 KB n=200000
101 Correct 1116 ms 92584 KB n=200000
102 Correct 587 ms 84196 KB n=200000
103 Correct 629 ms 84156 KB n=200000
104 Correct 653 ms 84304 KB n=200000
105 Correct 637 ms 84708 KB n=200000
106 Correct 630 ms 84560 KB n=200000
107 Correct 703 ms 84648 KB n=200000
108 Correct 791 ms 83028 KB n=200000
109 Correct 769 ms 83148 KB n=200000
110 Correct 732 ms 83028 KB n=200000
111 Correct 679 ms 82376 KB n=200000
112 Correct 879 ms 91756 KB n=200000
113 Correct 862 ms 87140 KB n=200000
114 Correct 760 ms 82628 KB n=200000
115 Correct 891 ms 85176 KB n=200000
116 Correct 748 ms 83068 KB n=200000
117 Correct 956 ms 92244 KB n=200000
118 Correct 906 ms 86100 KB n=200000
119 Correct 723 ms 83192 KB n=200000
120 Correct 818 ms 91696 KB n=200000
121 Correct 848 ms 91652 KB n=200000
122 Correct 824 ms 92060 KB n=200000
123 Correct 641 ms 84304 KB n=200000
124 Correct 210 ms 62152 KB n=25264