답안 #927577

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
927577 2024-02-15T05:41:50 Z shenfe1 Birthday gift (IZhO18_treearray) C++17
56 / 100
781 ms 124244 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=4e5+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);
  }
  while(q--){
    int t;
    cin>>t;
    if(t==1){
      int pos,v;
      cin>>pos>>v;
      upd(pos,v);
    }
    else{
      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:117:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  117 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 55896 KB n=5
2 Correct 11 ms 55900 KB n=100
3 Correct 11 ms 56036 KB n=100
4 Correct 11 ms 56048 KB n=100
5 Correct 10 ms 55900 KB n=100
6 Correct 10 ms 55900 KB n=100
7 Correct 11 ms 55896 KB n=100
8 Correct 12 ms 55896 KB n=100
9 Correct 11 ms 55900 KB n=100
10 Correct 11 ms 55896 KB n=100
11 Correct 12 ms 55896 KB n=100
12 Correct 11 ms 55900 KB n=100
13 Correct 11 ms 55900 KB n=100
14 Correct 11 ms 55900 KB n=100
15 Correct 10 ms 55900 KB n=100
16 Correct 11 ms 55896 KB n=100
17 Correct 12 ms 55900 KB n=100
18 Correct 11 ms 55900 KB n=100
19 Correct 12 ms 55996 KB n=100
20 Correct 11 ms 56056 KB n=100
21 Correct 13 ms 55900 KB n=100
22 Correct 12 ms 55900 KB n=100
23 Correct 11 ms 55900 KB n=100
24 Correct 10 ms 55896 KB n=100
25 Correct 10 ms 55900 KB n=100
26 Correct 10 ms 55900 KB n=12
27 Correct 11 ms 55900 KB n=100
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 55896 KB n=5
2 Correct 11 ms 55900 KB n=100
3 Correct 11 ms 56036 KB n=100
4 Correct 11 ms 56048 KB n=100
5 Correct 10 ms 55900 KB n=100
6 Correct 10 ms 55900 KB n=100
7 Correct 11 ms 55896 KB n=100
8 Correct 12 ms 55896 KB n=100
9 Correct 11 ms 55900 KB n=100
10 Correct 11 ms 55896 KB n=100
11 Correct 12 ms 55896 KB n=100
12 Correct 11 ms 55900 KB n=100
13 Correct 11 ms 55900 KB n=100
14 Correct 11 ms 55900 KB n=100
15 Correct 10 ms 55900 KB n=100
16 Correct 11 ms 55896 KB n=100
17 Correct 12 ms 55900 KB n=100
18 Correct 11 ms 55900 KB n=100
19 Correct 12 ms 55996 KB n=100
20 Correct 11 ms 56056 KB n=100
21 Correct 13 ms 55900 KB n=100
22 Correct 12 ms 55900 KB n=100
23 Correct 11 ms 55900 KB n=100
24 Correct 10 ms 55896 KB n=100
25 Correct 10 ms 55900 KB n=100
26 Correct 10 ms 55900 KB n=12
27 Correct 11 ms 55900 KB n=100
28 Correct 12 ms 55900 KB n=500
29 Correct 11 ms 55896 KB n=500
30 Correct 14 ms 56156 KB n=500
31 Correct 11 ms 55900 KB n=500
32 Correct 13 ms 55900 KB n=500
33 Correct 11 ms 55900 KB n=500
34 Correct 12 ms 55900 KB n=500
35 Correct 11 ms 56232 KB n=500
36 Correct 11 ms 55908 KB n=500
37 Correct 11 ms 56108 KB n=500
38 Correct 11 ms 56104 KB n=500
39 Correct 11 ms 55900 KB n=500
40 Correct 11 ms 55896 KB n=500
41 Correct 11 ms 55896 KB n=500
42 Correct 11 ms 55900 KB n=500
43 Correct 12 ms 56016 KB n=500
44 Correct 12 ms 55896 KB n=500
45 Correct 12 ms 55896 KB n=500
46 Correct 11 ms 56152 KB n=500
47 Correct 11 ms 55900 KB n=500
48 Correct 11 ms 55900 KB n=500
49 Correct 11 ms 55900 KB n=500
50 Correct 12 ms 55900 KB n=500
51 Correct 11 ms 55896 KB n=500
52 Correct 11 ms 55900 KB n=500
53 Correct 11 ms 56104 KB n=500
54 Correct 11 ms 55900 KB n=500
55 Correct 13 ms 56152 KB n=278
56 Correct 12 ms 55900 KB n=500
57 Correct 12 ms 55900 KB n=500
58 Correct 11 ms 55900 KB n=500
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 55896 KB n=5
2 Correct 11 ms 55900 KB n=100
3 Correct 11 ms 56036 KB n=100
4 Correct 11 ms 56048 KB n=100
5 Correct 10 ms 55900 KB n=100
6 Correct 10 ms 55900 KB n=100
7 Correct 11 ms 55896 KB n=100
8 Correct 12 ms 55896 KB n=100
9 Correct 11 ms 55900 KB n=100
10 Correct 11 ms 55896 KB n=100
11 Correct 12 ms 55896 KB n=100
12 Correct 11 ms 55900 KB n=100
13 Correct 11 ms 55900 KB n=100
14 Correct 11 ms 55900 KB n=100
15 Correct 10 ms 55900 KB n=100
16 Correct 11 ms 55896 KB n=100
17 Correct 12 ms 55900 KB n=100
18 Correct 11 ms 55900 KB n=100
19 Correct 12 ms 55996 KB n=100
20 Correct 11 ms 56056 KB n=100
21 Correct 13 ms 55900 KB n=100
22 Correct 12 ms 55900 KB n=100
23 Correct 11 ms 55900 KB n=100
24 Correct 10 ms 55896 KB n=100
25 Correct 10 ms 55900 KB n=100
26 Correct 10 ms 55900 KB n=12
27 Correct 11 ms 55900 KB n=100
28 Correct 12 ms 55900 KB n=500
29 Correct 11 ms 55896 KB n=500
30 Correct 14 ms 56156 KB n=500
31 Correct 11 ms 55900 KB n=500
32 Correct 13 ms 55900 KB n=500
33 Correct 11 ms 55900 KB n=500
34 Correct 12 ms 55900 KB n=500
35 Correct 11 ms 56232 KB n=500
36 Correct 11 ms 55908 KB n=500
37 Correct 11 ms 56108 KB n=500
38 Correct 11 ms 56104 KB n=500
39 Correct 11 ms 55900 KB n=500
40 Correct 11 ms 55896 KB n=500
41 Correct 11 ms 55896 KB n=500
42 Correct 11 ms 55900 KB n=500
43 Correct 12 ms 56016 KB n=500
44 Correct 12 ms 55896 KB n=500
45 Correct 12 ms 55896 KB n=500
46 Correct 11 ms 56152 KB n=500
47 Correct 11 ms 55900 KB n=500
48 Correct 11 ms 55900 KB n=500
49 Correct 11 ms 55900 KB n=500
50 Correct 12 ms 55900 KB n=500
51 Correct 11 ms 55896 KB n=500
52 Correct 11 ms 55900 KB n=500
53 Correct 11 ms 56104 KB n=500
54 Correct 11 ms 55900 KB n=500
55 Correct 13 ms 56152 KB n=278
56 Correct 12 ms 55900 KB n=500
57 Correct 12 ms 55900 KB n=500
58 Correct 11 ms 55900 KB n=500
59 Correct 14 ms 56156 KB n=2000
60 Correct 13 ms 56152 KB n=2000
61 Correct 13 ms 56156 KB n=2000
62 Correct 13 ms 56156 KB n=2000
63 Correct 16 ms 56324 KB n=2000
64 Correct 14 ms 56156 KB n=2000
65 Correct 13 ms 56156 KB n=2000
66 Correct 14 ms 56408 KB n=2000
67 Correct 14 ms 56156 KB n=2000
68 Correct 13 ms 56152 KB n=2000
69 Correct 13 ms 56408 KB n=2000
70 Correct 13 ms 56156 KB n=2000
71 Correct 13 ms 56160 KB n=2000
72 Correct 13 ms 56152 KB n=2000
73 Correct 13 ms 56156 KB n=2000
74 Correct 13 ms 56156 KB n=1844
75 Correct 13 ms 56152 KB n=2000
76 Correct 13 ms 56152 KB n=2000
77 Correct 16 ms 56412 KB n=2000
78 Correct 14 ms 56156 KB n=2000
79 Correct 13 ms 56152 KB n=2000
80 Correct 15 ms 56224 KB n=2000
81 Correct 13 ms 56156 KB n=2000
82 Correct 14 ms 56156 KB n=2000
83 Correct 13 ms 56152 KB n=2000
84 Correct 14 ms 56156 KB n=2000
85 Correct 13 ms 56152 KB n=2000
86 Correct 17 ms 56224 KB n=2000
87 Correct 13 ms 56152 KB n=2000
88 Correct 12 ms 56152 KB n=2000
89 Correct 13 ms 56388 KB n=2000
90 Correct 13 ms 56388 KB n=2000
91 Correct 12 ms 56156 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 55896 KB n=5
2 Correct 11 ms 55900 KB n=100
3 Correct 11 ms 56036 KB n=100
4 Correct 11 ms 56048 KB n=100
5 Correct 10 ms 55900 KB n=100
6 Correct 10 ms 55900 KB n=100
7 Correct 11 ms 55896 KB n=100
8 Correct 12 ms 55896 KB n=100
9 Correct 11 ms 55900 KB n=100
10 Correct 11 ms 55896 KB n=100
11 Correct 12 ms 55896 KB n=100
12 Correct 11 ms 55900 KB n=100
13 Correct 11 ms 55900 KB n=100
14 Correct 11 ms 55900 KB n=100
15 Correct 10 ms 55900 KB n=100
16 Correct 11 ms 55896 KB n=100
17 Correct 12 ms 55900 KB n=100
18 Correct 11 ms 55900 KB n=100
19 Correct 12 ms 55996 KB n=100
20 Correct 11 ms 56056 KB n=100
21 Correct 13 ms 55900 KB n=100
22 Correct 12 ms 55900 KB n=100
23 Correct 11 ms 55900 KB n=100
24 Correct 10 ms 55896 KB n=100
25 Correct 10 ms 55900 KB n=100
26 Correct 10 ms 55900 KB n=12
27 Correct 11 ms 55900 KB n=100
28 Correct 12 ms 55900 KB n=500
29 Correct 11 ms 55896 KB n=500
30 Correct 14 ms 56156 KB n=500
31 Correct 11 ms 55900 KB n=500
32 Correct 13 ms 55900 KB n=500
33 Correct 11 ms 55900 KB n=500
34 Correct 12 ms 55900 KB n=500
35 Correct 11 ms 56232 KB n=500
36 Correct 11 ms 55908 KB n=500
37 Correct 11 ms 56108 KB n=500
38 Correct 11 ms 56104 KB n=500
39 Correct 11 ms 55900 KB n=500
40 Correct 11 ms 55896 KB n=500
41 Correct 11 ms 55896 KB n=500
42 Correct 11 ms 55900 KB n=500
43 Correct 12 ms 56016 KB n=500
44 Correct 12 ms 55896 KB n=500
45 Correct 12 ms 55896 KB n=500
46 Correct 11 ms 56152 KB n=500
47 Correct 11 ms 55900 KB n=500
48 Correct 11 ms 55900 KB n=500
49 Correct 11 ms 55900 KB n=500
50 Correct 12 ms 55900 KB n=500
51 Correct 11 ms 55896 KB n=500
52 Correct 11 ms 55900 KB n=500
53 Correct 11 ms 56104 KB n=500
54 Correct 11 ms 55900 KB n=500
55 Correct 13 ms 56152 KB n=278
56 Correct 12 ms 55900 KB n=500
57 Correct 12 ms 55900 KB n=500
58 Correct 11 ms 55900 KB n=500
59 Correct 14 ms 56156 KB n=2000
60 Correct 13 ms 56152 KB n=2000
61 Correct 13 ms 56156 KB n=2000
62 Correct 13 ms 56156 KB n=2000
63 Correct 16 ms 56324 KB n=2000
64 Correct 14 ms 56156 KB n=2000
65 Correct 13 ms 56156 KB n=2000
66 Correct 14 ms 56408 KB n=2000
67 Correct 14 ms 56156 KB n=2000
68 Correct 13 ms 56152 KB n=2000
69 Correct 13 ms 56408 KB n=2000
70 Correct 13 ms 56156 KB n=2000
71 Correct 13 ms 56160 KB n=2000
72 Correct 13 ms 56152 KB n=2000
73 Correct 13 ms 56156 KB n=2000
74 Correct 13 ms 56156 KB n=1844
75 Correct 13 ms 56152 KB n=2000
76 Correct 13 ms 56152 KB n=2000
77 Correct 16 ms 56412 KB n=2000
78 Correct 14 ms 56156 KB n=2000
79 Correct 13 ms 56152 KB n=2000
80 Correct 15 ms 56224 KB n=2000
81 Correct 13 ms 56156 KB n=2000
82 Correct 14 ms 56156 KB n=2000
83 Correct 13 ms 56152 KB n=2000
84 Correct 14 ms 56156 KB n=2000
85 Correct 13 ms 56152 KB n=2000
86 Correct 17 ms 56224 KB n=2000
87 Correct 13 ms 56152 KB n=2000
88 Correct 12 ms 56152 KB n=2000
89 Correct 13 ms 56388 KB n=2000
90 Correct 13 ms 56388 KB n=2000
91 Correct 12 ms 56156 KB n=2000
92 Correct 547 ms 116580 KB n=200000
93 Correct 624 ms 120392 KB n=200000
94 Correct 484 ms 123268 KB n=200000
95 Correct 530 ms 116756 KB n=200000
96 Correct 531 ms 116412 KB n=200000
97 Correct 693 ms 119552 KB n=200000
98 Correct 534 ms 116408 KB n=200000
99 Correct 593 ms 116048 KB n=200000
100 Correct 589 ms 116680 KB n=200000
101 Correct 406 ms 123984 KB n=200000
102 Correct 323 ms 117844 KB n=200000
103 Correct 306 ms 117588 KB n=200000
104 Correct 310 ms 117584 KB n=200000
105 Correct 305 ms 117332 KB n=200000
106 Correct 317 ms 117224 KB n=200000
107 Correct 317 ms 117296 KB n=200000
108 Correct 554 ms 116220 KB n=200000
109 Correct 604 ms 116204 KB n=200000
110 Correct 619 ms 116304 KB n=200000
111 Correct 522 ms 116528 KB n=200000
112 Correct 441 ms 123328 KB n=200000
113 Correct 699 ms 119436 KB n=200000
114 Correct 520 ms 116496 KB n=200000
115 Correct 781 ms 117788 KB n=200000
116 Correct 530 ms 116292 KB n=200000
117 Correct 423 ms 123868 KB n=200000
118 Correct 756 ms 118324 KB n=200000
119 Correct 511 ms 116224 KB n=200000
120 Correct 413 ms 123740 KB n=200000
121 Correct 348 ms 124084 KB n=200000
122 Correct 342 ms 124244 KB n=200000
123 Correct 326 ms 117072 KB n=200000
124 Incorrect 105 ms 70720 KB Wrong range.
125 Halted 0 ms 0 KB -