답안 #927573

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
927573 2024-02-15T05:38:09 Z shenfe1 Birthday gift (IZhO18_treearray) C++17
56 / 100
793 ms 102936 KB
#include<bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define ll long long
#define maksim gay
#define int ll
#define pb push_back
#define sz(s) (int)s.size()
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define mem(a,i) memset(a,i,sizeof(a))
#define in insert
#define lb lower_bound
#define ub upper_bound

const int MAX=2e5+10;
const int inf=1e10;
const int N=2e5;

int n,m,q;
int up[MAX][20];
int tin[MAX],tout[MAX],timer;
vector<int> g[MAX];
int a[MAX];
set<int> p[MAX],p1[MAX];

void dfs(int v,int p=1){
  tin[v]=++timer;
  up[v][0]=p;
  for(int i=1;i<20;i++)up[v][i]=up[up[v][i-1]][i-1];
  for(auto to:g[v]){
    if(to==p)continue;
    dfs(to,v);
  }
  tout[v]=timer;
}

int par(int u,int v){
  return tin[u]<=tin[v]&&tout[v]<=tout[u];
}

int lca(int u,int v){
  if(par(u,v))return u;
  if(par(v,u))return v;
  for(int i=19;i>=0;i--){
    if(!par(up[u][i],v)){
      u=up[u][i];
    }
  }
  return up[u][0];
}

void upd(int pos,int v){
  p1[a[pos]].erase(pos);
  if(pos-1>=1){
    p[lca(a[pos],a[pos-1])].erase(pos-1);
  }
  if(pos+1<=n){
    p[lca(a[pos],a[pos+1])].erase(pos);
  }
  a[pos]=v;
  p1[a[pos]].in(pos);
  if(pos-1>=1){
    p[lca(a[pos],a[pos-1])].in(pos-1);
  }
  if(pos+1<=n){
    p[lca(a[pos],a[pos+1])].in(pos);
  }  
}

void solve(){
  cin>>n>>m>>q;
  for(int i=1;i<n;i++){
    int u,v;
    cin>>u>>v;
    g[u].pb(v);
    g[v].pb(u);
  }
  dfs(1);
  for(int i=1;i<=m;i++){
    cin>>a[i];
    p1[a[i]].in(i);
  }
  for(int i=2;i<=m;i++){
    p[lca(a[i],a[i-1])].in(i-1);
  }
  // cout<<0<<"\n";
  // return;
  while(q--){
    int t;
    cin>>t;
    if(t==1){
      int pos,v;
      cin>>pos>>v;
      upd(pos,v);
    }
    else{
      // cout<<0<<"\n";
      int l,r,v;
      cin>>l>>r>>v;
      auto f=p[v].lb(l);
      if(f!=p[v].end()&&*f+1<=r){
        cout<<*f<<" "<<*f+1<<"\n";
        continue;
      }
      f=p1[v].lb(l);
      if(f!=p1[v].end()&&*f<=r){
        cout<<*f<<" "<<*f<<"\n";
        continue;
      }
      cout<<-1<<" "<<-1<<"\n";
    }
  }
}


main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t=1;
  // cin>>t;
  while(t--){
    solve();
  }
}

Compilation message

treearray.cpp:120:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  120 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 29272 KB n=5
2 Correct 6 ms 29364 KB n=100
3 Correct 6 ms 29276 KB n=100
4 Correct 7 ms 29276 KB n=100
5 Correct 8 ms 29276 KB n=100
6 Correct 6 ms 29276 KB n=100
7 Correct 6 ms 29276 KB n=100
8 Correct 6 ms 29276 KB n=100
9 Correct 7 ms 29528 KB n=100
10 Correct 6 ms 29276 KB n=100
11 Correct 6 ms 29276 KB n=100
12 Correct 6 ms 29276 KB n=100
13 Correct 6 ms 29276 KB n=100
14 Correct 6 ms 29276 KB n=100
15 Correct 6 ms 29528 KB n=100
16 Correct 7 ms 29276 KB n=100
17 Correct 5 ms 29276 KB n=100
18 Correct 6 ms 29276 KB n=100
19 Correct 7 ms 29276 KB n=100
20 Correct 6 ms 29276 KB n=100
21 Correct 6 ms 29380 KB n=100
22 Correct 6 ms 29276 KB n=100
23 Correct 6 ms 29276 KB n=100
24 Correct 6 ms 29272 KB n=100
25 Correct 6 ms 29272 KB n=100
26 Correct 6 ms 29272 KB n=12
27 Correct 6 ms 29276 KB n=100
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 29272 KB n=5
2 Correct 6 ms 29364 KB n=100
3 Correct 6 ms 29276 KB n=100
4 Correct 7 ms 29276 KB n=100
5 Correct 8 ms 29276 KB n=100
6 Correct 6 ms 29276 KB n=100
7 Correct 6 ms 29276 KB n=100
8 Correct 6 ms 29276 KB n=100
9 Correct 7 ms 29528 KB n=100
10 Correct 6 ms 29276 KB n=100
11 Correct 6 ms 29276 KB n=100
12 Correct 6 ms 29276 KB n=100
13 Correct 6 ms 29276 KB n=100
14 Correct 6 ms 29276 KB n=100
15 Correct 6 ms 29528 KB n=100
16 Correct 7 ms 29276 KB n=100
17 Correct 5 ms 29276 KB n=100
18 Correct 6 ms 29276 KB n=100
19 Correct 7 ms 29276 KB n=100
20 Correct 6 ms 29276 KB n=100
21 Correct 6 ms 29380 KB n=100
22 Correct 6 ms 29276 KB n=100
23 Correct 6 ms 29276 KB n=100
24 Correct 6 ms 29272 KB n=100
25 Correct 6 ms 29272 KB n=100
26 Correct 6 ms 29272 KB n=12
27 Correct 6 ms 29276 KB n=100
28 Correct 6 ms 29276 KB n=500
29 Correct 8 ms 29272 KB n=500
30 Correct 6 ms 29276 KB n=500
31 Correct 6 ms 29276 KB n=500
32 Correct 7 ms 29276 KB n=500
33 Correct 6 ms 29276 KB n=500
34 Correct 6 ms 29272 KB n=500
35 Correct 6 ms 29272 KB n=500
36 Correct 7 ms 29272 KB n=500
37 Correct 6 ms 29272 KB n=500
38 Correct 6 ms 29272 KB n=500
39 Correct 7 ms 29376 KB n=500
40 Correct 6 ms 29276 KB n=500
41 Correct 6 ms 29276 KB n=500
42 Correct 6 ms 29372 KB n=500
43 Correct 6 ms 29276 KB n=500
44 Correct 7 ms 29276 KB n=500
45 Correct 7 ms 29528 KB n=500
46 Correct 6 ms 29276 KB n=500
47 Correct 6 ms 29276 KB n=500
48 Correct 6 ms 29368 KB n=500
49 Correct 6 ms 29276 KB n=500
50 Correct 7 ms 29272 KB n=500
51 Correct 8 ms 29276 KB n=500
52 Correct 6 ms 29276 KB n=500
53 Correct 6 ms 29276 KB n=500
54 Correct 6 ms 29272 KB n=500
55 Correct 6 ms 29276 KB n=278
56 Correct 6 ms 29276 KB n=500
57 Correct 6 ms 29372 KB n=500
58 Correct 6 ms 29276 KB n=500
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 29272 KB n=5
2 Correct 6 ms 29364 KB n=100
3 Correct 6 ms 29276 KB n=100
4 Correct 7 ms 29276 KB n=100
5 Correct 8 ms 29276 KB n=100
6 Correct 6 ms 29276 KB n=100
7 Correct 6 ms 29276 KB n=100
8 Correct 6 ms 29276 KB n=100
9 Correct 7 ms 29528 KB n=100
10 Correct 6 ms 29276 KB n=100
11 Correct 6 ms 29276 KB n=100
12 Correct 6 ms 29276 KB n=100
13 Correct 6 ms 29276 KB n=100
14 Correct 6 ms 29276 KB n=100
15 Correct 6 ms 29528 KB n=100
16 Correct 7 ms 29276 KB n=100
17 Correct 5 ms 29276 KB n=100
18 Correct 6 ms 29276 KB n=100
19 Correct 7 ms 29276 KB n=100
20 Correct 6 ms 29276 KB n=100
21 Correct 6 ms 29380 KB n=100
22 Correct 6 ms 29276 KB n=100
23 Correct 6 ms 29276 KB n=100
24 Correct 6 ms 29272 KB n=100
25 Correct 6 ms 29272 KB n=100
26 Correct 6 ms 29272 KB n=12
27 Correct 6 ms 29276 KB n=100
28 Correct 6 ms 29276 KB n=500
29 Correct 8 ms 29272 KB n=500
30 Correct 6 ms 29276 KB n=500
31 Correct 6 ms 29276 KB n=500
32 Correct 7 ms 29276 KB n=500
33 Correct 6 ms 29276 KB n=500
34 Correct 6 ms 29272 KB n=500
35 Correct 6 ms 29272 KB n=500
36 Correct 7 ms 29272 KB n=500
37 Correct 6 ms 29272 KB n=500
38 Correct 6 ms 29272 KB n=500
39 Correct 7 ms 29376 KB n=500
40 Correct 6 ms 29276 KB n=500
41 Correct 6 ms 29276 KB n=500
42 Correct 6 ms 29372 KB n=500
43 Correct 6 ms 29276 KB n=500
44 Correct 7 ms 29276 KB n=500
45 Correct 7 ms 29528 KB n=500
46 Correct 6 ms 29276 KB n=500
47 Correct 6 ms 29276 KB n=500
48 Correct 6 ms 29368 KB n=500
49 Correct 6 ms 29276 KB n=500
50 Correct 7 ms 29272 KB n=500
51 Correct 8 ms 29276 KB n=500
52 Correct 6 ms 29276 KB n=500
53 Correct 6 ms 29276 KB n=500
54 Correct 6 ms 29272 KB n=500
55 Correct 6 ms 29276 KB n=278
56 Correct 6 ms 29276 KB n=500
57 Correct 6 ms 29372 KB n=500
58 Correct 6 ms 29276 KB n=500
59 Correct 8 ms 29532 KB n=2000
60 Correct 8 ms 29532 KB n=2000
61 Correct 8 ms 29532 KB n=2000
62 Correct 9 ms 29532 KB n=2000
63 Correct 8 ms 29532 KB n=2000
64 Correct 9 ms 29532 KB n=2000
65 Correct 12 ms 29528 KB n=2000
66 Correct 8 ms 29532 KB n=2000
67 Correct 9 ms 29528 KB n=2000
68 Correct 8 ms 29532 KB n=2000
69 Correct 8 ms 29528 KB n=2000
70 Correct 8 ms 29532 KB n=2000
71 Correct 8 ms 29532 KB n=2000
72 Correct 8 ms 29528 KB n=2000
73 Correct 9 ms 29580 KB n=2000
74 Correct 8 ms 29784 KB n=1844
75 Correct 8 ms 29784 KB n=2000
76 Correct 9 ms 29532 KB n=2000
77 Correct 9 ms 29532 KB n=2000
78 Correct 9 ms 29532 KB n=2000
79 Correct 8 ms 29532 KB n=2000
80 Correct 8 ms 29532 KB n=2000
81 Correct 8 ms 29720 KB n=2000
82 Correct 10 ms 29880 KB n=2000
83 Correct 9 ms 29532 KB n=2000
84 Correct 8 ms 29532 KB n=2000
85 Correct 9 ms 29528 KB n=2000
86 Correct 9 ms 29528 KB n=2000
87 Correct 8 ms 29532 KB n=2000
88 Correct 8 ms 29532 KB n=2000
89 Correct 7 ms 29532 KB n=2000
90 Correct 8 ms 29760 KB n=2000
91 Correct 9 ms 29632 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 29272 KB n=5
2 Correct 6 ms 29364 KB n=100
3 Correct 6 ms 29276 KB n=100
4 Correct 7 ms 29276 KB n=100
5 Correct 8 ms 29276 KB n=100
6 Correct 6 ms 29276 KB n=100
7 Correct 6 ms 29276 KB n=100
8 Correct 6 ms 29276 KB n=100
9 Correct 7 ms 29528 KB n=100
10 Correct 6 ms 29276 KB n=100
11 Correct 6 ms 29276 KB n=100
12 Correct 6 ms 29276 KB n=100
13 Correct 6 ms 29276 KB n=100
14 Correct 6 ms 29276 KB n=100
15 Correct 6 ms 29528 KB n=100
16 Correct 7 ms 29276 KB n=100
17 Correct 5 ms 29276 KB n=100
18 Correct 6 ms 29276 KB n=100
19 Correct 7 ms 29276 KB n=100
20 Correct 6 ms 29276 KB n=100
21 Correct 6 ms 29380 KB n=100
22 Correct 6 ms 29276 KB n=100
23 Correct 6 ms 29276 KB n=100
24 Correct 6 ms 29272 KB n=100
25 Correct 6 ms 29272 KB n=100
26 Correct 6 ms 29272 KB n=12
27 Correct 6 ms 29276 KB n=100
28 Correct 6 ms 29276 KB n=500
29 Correct 8 ms 29272 KB n=500
30 Correct 6 ms 29276 KB n=500
31 Correct 6 ms 29276 KB n=500
32 Correct 7 ms 29276 KB n=500
33 Correct 6 ms 29276 KB n=500
34 Correct 6 ms 29272 KB n=500
35 Correct 6 ms 29272 KB n=500
36 Correct 7 ms 29272 KB n=500
37 Correct 6 ms 29272 KB n=500
38 Correct 6 ms 29272 KB n=500
39 Correct 7 ms 29376 KB n=500
40 Correct 6 ms 29276 KB n=500
41 Correct 6 ms 29276 KB n=500
42 Correct 6 ms 29372 KB n=500
43 Correct 6 ms 29276 KB n=500
44 Correct 7 ms 29276 KB n=500
45 Correct 7 ms 29528 KB n=500
46 Correct 6 ms 29276 KB n=500
47 Correct 6 ms 29276 KB n=500
48 Correct 6 ms 29368 KB n=500
49 Correct 6 ms 29276 KB n=500
50 Correct 7 ms 29272 KB n=500
51 Correct 8 ms 29276 KB n=500
52 Correct 6 ms 29276 KB n=500
53 Correct 6 ms 29276 KB n=500
54 Correct 6 ms 29272 KB n=500
55 Correct 6 ms 29276 KB n=278
56 Correct 6 ms 29276 KB n=500
57 Correct 6 ms 29372 KB n=500
58 Correct 6 ms 29276 KB n=500
59 Correct 8 ms 29532 KB n=2000
60 Correct 8 ms 29532 KB n=2000
61 Correct 8 ms 29532 KB n=2000
62 Correct 9 ms 29532 KB n=2000
63 Correct 8 ms 29532 KB n=2000
64 Correct 9 ms 29532 KB n=2000
65 Correct 12 ms 29528 KB n=2000
66 Correct 8 ms 29532 KB n=2000
67 Correct 9 ms 29528 KB n=2000
68 Correct 8 ms 29532 KB n=2000
69 Correct 8 ms 29528 KB n=2000
70 Correct 8 ms 29532 KB n=2000
71 Correct 8 ms 29532 KB n=2000
72 Correct 8 ms 29528 KB n=2000
73 Correct 9 ms 29580 KB n=2000
74 Correct 8 ms 29784 KB n=1844
75 Correct 8 ms 29784 KB n=2000
76 Correct 9 ms 29532 KB n=2000
77 Correct 9 ms 29532 KB n=2000
78 Correct 9 ms 29532 KB n=2000
79 Correct 8 ms 29532 KB n=2000
80 Correct 8 ms 29532 KB n=2000
81 Correct 8 ms 29720 KB n=2000
82 Correct 10 ms 29880 KB n=2000
83 Correct 9 ms 29532 KB n=2000
84 Correct 8 ms 29532 KB n=2000
85 Correct 9 ms 29528 KB n=2000
86 Correct 9 ms 29528 KB n=2000
87 Correct 8 ms 29532 KB n=2000
88 Correct 8 ms 29532 KB n=2000
89 Correct 7 ms 29532 KB n=2000
90 Correct 8 ms 29760 KB n=2000
91 Correct 9 ms 29632 KB n=2000
92 Correct 519 ms 94160 KB n=200000
93 Correct 692 ms 99220 KB n=200000
94 Correct 481 ms 101896 KB n=200000
95 Correct 514 ms 93884 KB n=200000
96 Correct 538 ms 94052 KB n=200000
97 Correct 722 ms 98388 KB n=200000
98 Correct 542 ms 94144 KB n=200000
99 Correct 650 ms 94504 KB n=200000
100 Correct 588 ms 94112 KB n=200000
101 Correct 377 ms 102936 KB n=200000
102 Correct 296 ms 95312 KB n=200000
103 Correct 318 ms 95312 KB n=200000
104 Correct 334 ms 95404 KB n=200000
105 Correct 304 ms 95824 KB n=200000
106 Correct 332 ms 95696 KB n=200000
107 Correct 329 ms 96140 KB n=200000
108 Correct 547 ms 94232 KB n=200000
109 Correct 540 ms 94288 KB n=200000
110 Correct 554 ms 94308 KB n=200000
111 Correct 515 ms 93376 KB n=200000
112 Correct 437 ms 102068 KB n=200000
113 Correct 669 ms 98508 KB n=200000
114 Correct 505 ms 93440 KB n=200000
115 Correct 793 ms 96232 KB n=200000
116 Correct 514 ms 94252 KB n=200000
117 Correct 396 ms 102360 KB n=200000
118 Correct 731 ms 97448 KB n=200000
119 Correct 528 ms 94408 KB n=200000
120 Correct 398 ms 101716 KB n=200000
121 Correct 344 ms 101824 KB n=200000
122 Correct 355 ms 102044 KB n=200000
123 Correct 364 ms 95644 KB n=200000
124 Incorrect 89 ms 45908 KB Wrong range.
125 Halted 0 ms 0 KB -