답안 #878612

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
878612 2023-11-25T01:22:31 Z 8pete8 Birthday gift (IZhO18_treearray) C++14
56 / 100
4000 ms 82820 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<pii,pii>
#define vi vector<int>
#define pb push_back
//#define p push
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-lopps")
using namespace std;
#define int long long
const int mod=9901,mxn=3*1e5+5,inf=1e18,lg=30,minf=-1e18;
vector<int>adj[mxn+10];
int h[mxn+10],up[mxn+10][lg+5],v[mxn+10],d[mxn+10];
void dfs(int cur,int p){for(auto i:adj[cur])if(i!=p)h[i]=h[cur]+1,up[i][0]=cur,dfs(i,cur);}
int lca(int a,int b){
	if(h[a]<h[b])swap(a,b);
	int k=h[a]-h[b];
	for(int i=0;i<=lg;i++)if(k&(1<<i))a=up[a][i];
	if(a==b)return a;
	for(int i=lg;i>=0;i--)if(up[a][i]!=up[b][i])a=up[a][i],b=up[b][i];
	return up[a][0];
}
int32_t main(){
	fastio
	int n,m,q;cin>>n>>m>>q;
	for(int i=0;i<n-1;i++){
		int a,b;cin>>a>>b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	dfs(1,-1);
	for(int i=1;i<=lg;i++)for(int j=1;j<=n;j++)up[j][i]=up[up[j][i-1]][i-1];
	for(int i=0;i<m;i++)cin>>v[i];
	for(int i=0;i<m-1;i++)d[i]=lca(v[i],v[i+1]);
	while(q--){
		int t;cin>>t;
		if(t==1){
			int pos,val;cin>>pos>>val;
			pos--;
			v[pos]=val;
			d[pos]=lca(v[pos],v[pos+1]);
			if(pos)d[pos-1]=lca(v[pos-1],v[pos]);
		}
		else{
			int l,r,ver;cin>>l>>r>>ver;
			bool yes=false;
			l--,r--;
			for(int i=l;i<=r;i++){
				if(i<r&&d[i]==ver&&!yes)cout<<i+1<<" "<<i+2,yes=true;
				if(v[i]==ver&&!yes)cout<<i+1<<" "<<i+1,yes=true;
			}
			if(!yes)cout<<-1<<" "<<-1;
			cout<<'\n';
		}
	}
}

Compilation message

treearray.cpp:30:40: warning: bad option '-funroll-lopps' to pragma 'optimize' [-Wpragmas]
   30 | #pragma GCC optimize ("03,unroll-lopps")
      |                                        ^
treearray.cpp:36:23: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   36 | void dfs(int cur,int p){for(auto i:adj[cur])if(i!=p)h[i]=h[cur]+1,up[i][0]=cur,dfs(i,cur);}
      |                       ^
treearray.cpp:37:20: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   37 | int lca(int a,int b){
      |                    ^
treearray.cpp:45:14: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   45 | int32_t main(){
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12380 KB n=5
2 Correct 2 ms 12376 KB n=100
3 Correct 3 ms 12380 KB n=100
4 Correct 3 ms 12304 KB n=100
5 Correct 3 ms 12380 KB n=100
6 Correct 3 ms 12380 KB n=100
7 Correct 3 ms 12380 KB n=100
8 Correct 3 ms 12380 KB n=100
9 Correct 4 ms 12380 KB n=100
10 Correct 3 ms 12384 KB n=100
11 Correct 3 ms 12380 KB n=100
12 Correct 2 ms 12380 KB n=100
13 Correct 3 ms 12380 KB n=100
14 Correct 3 ms 12380 KB n=100
15 Correct 3 ms 12628 KB n=100
16 Correct 3 ms 12380 KB n=100
17 Correct 3 ms 12424 KB n=100
18 Correct 3 ms 12632 KB n=100
19 Correct 3 ms 12380 KB n=100
20 Correct 2 ms 12380 KB n=100
21 Correct 3 ms 12380 KB n=100
22 Correct 3 ms 12380 KB n=100
23 Correct 3 ms 12380 KB n=100
24 Correct 3 ms 12376 KB n=100
25 Correct 3 ms 12380 KB n=100
26 Correct 3 ms 12376 KB n=12
27 Correct 3 ms 12376 KB n=100
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12380 KB n=5
2 Correct 2 ms 12376 KB n=100
3 Correct 3 ms 12380 KB n=100
4 Correct 3 ms 12304 KB n=100
5 Correct 3 ms 12380 KB n=100
6 Correct 3 ms 12380 KB n=100
7 Correct 3 ms 12380 KB n=100
8 Correct 3 ms 12380 KB n=100
9 Correct 4 ms 12380 KB n=100
10 Correct 3 ms 12384 KB n=100
11 Correct 3 ms 12380 KB n=100
12 Correct 2 ms 12380 KB n=100
13 Correct 3 ms 12380 KB n=100
14 Correct 3 ms 12380 KB n=100
15 Correct 3 ms 12628 KB n=100
16 Correct 3 ms 12380 KB n=100
17 Correct 3 ms 12424 KB n=100
18 Correct 3 ms 12632 KB n=100
19 Correct 3 ms 12380 KB n=100
20 Correct 2 ms 12380 KB n=100
21 Correct 3 ms 12380 KB n=100
22 Correct 3 ms 12380 KB n=100
23 Correct 3 ms 12380 KB n=100
24 Correct 3 ms 12376 KB n=100
25 Correct 3 ms 12380 KB n=100
26 Correct 3 ms 12376 KB n=12
27 Correct 3 ms 12376 KB n=100
28 Correct 3 ms 12380 KB n=500
29 Correct 3 ms 12380 KB n=500
30 Correct 3 ms 12432 KB n=500
31 Correct 3 ms 12888 KB n=500
32 Correct 3 ms 12380 KB n=500
33 Correct 3 ms 12380 KB n=500
34 Correct 3 ms 12380 KB n=500
35 Correct 3 ms 12384 KB n=500
36 Correct 4 ms 12384 KB n=500
37 Correct 3 ms 12380 KB n=500
38 Correct 3 ms 12380 KB n=500
39 Correct 3 ms 12380 KB n=500
40 Correct 3 ms 12380 KB n=500
41 Correct 4 ms 12380 KB n=500
42 Correct 3 ms 12380 KB n=500
43 Correct 3 ms 12376 KB n=500
44 Correct 3 ms 12380 KB n=500
45 Correct 3 ms 12380 KB n=500
46 Correct 3 ms 12376 KB n=500
47 Correct 3 ms 12376 KB n=500
48 Correct 3 ms 12380 KB n=500
49 Correct 3 ms 12380 KB n=500
50 Correct 3 ms 12380 KB n=500
51 Correct 3 ms 12380 KB n=500
52 Correct 3 ms 12376 KB n=500
53 Correct 3 ms 12376 KB n=500
54 Correct 3 ms 12632 KB n=500
55 Correct 3 ms 12376 KB n=278
56 Correct 3 ms 12380 KB n=500
57 Correct 3 ms 12380 KB n=500
58 Correct 3 ms 12376 KB n=500
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12380 KB n=5
2 Correct 2 ms 12376 KB n=100
3 Correct 3 ms 12380 KB n=100
4 Correct 3 ms 12304 KB n=100
5 Correct 3 ms 12380 KB n=100
6 Correct 3 ms 12380 KB n=100
7 Correct 3 ms 12380 KB n=100
8 Correct 3 ms 12380 KB n=100
9 Correct 4 ms 12380 KB n=100
10 Correct 3 ms 12384 KB n=100
11 Correct 3 ms 12380 KB n=100
12 Correct 2 ms 12380 KB n=100
13 Correct 3 ms 12380 KB n=100
14 Correct 3 ms 12380 KB n=100
15 Correct 3 ms 12628 KB n=100
16 Correct 3 ms 12380 KB n=100
17 Correct 3 ms 12424 KB n=100
18 Correct 3 ms 12632 KB n=100
19 Correct 3 ms 12380 KB n=100
20 Correct 2 ms 12380 KB n=100
21 Correct 3 ms 12380 KB n=100
22 Correct 3 ms 12380 KB n=100
23 Correct 3 ms 12380 KB n=100
24 Correct 3 ms 12376 KB n=100
25 Correct 3 ms 12380 KB n=100
26 Correct 3 ms 12376 KB n=12
27 Correct 3 ms 12376 KB n=100
28 Correct 3 ms 12380 KB n=500
29 Correct 3 ms 12380 KB n=500
30 Correct 3 ms 12432 KB n=500
31 Correct 3 ms 12888 KB n=500
32 Correct 3 ms 12380 KB n=500
33 Correct 3 ms 12380 KB n=500
34 Correct 3 ms 12380 KB n=500
35 Correct 3 ms 12384 KB n=500
36 Correct 4 ms 12384 KB n=500
37 Correct 3 ms 12380 KB n=500
38 Correct 3 ms 12380 KB n=500
39 Correct 3 ms 12380 KB n=500
40 Correct 3 ms 12380 KB n=500
41 Correct 4 ms 12380 KB n=500
42 Correct 3 ms 12380 KB n=500
43 Correct 3 ms 12376 KB n=500
44 Correct 3 ms 12380 KB n=500
45 Correct 3 ms 12380 KB n=500
46 Correct 3 ms 12376 KB n=500
47 Correct 3 ms 12376 KB n=500
48 Correct 3 ms 12380 KB n=500
49 Correct 3 ms 12380 KB n=500
50 Correct 3 ms 12380 KB n=500
51 Correct 3 ms 12380 KB n=500
52 Correct 3 ms 12376 KB n=500
53 Correct 3 ms 12376 KB n=500
54 Correct 3 ms 12632 KB n=500
55 Correct 3 ms 12376 KB n=278
56 Correct 3 ms 12380 KB n=500
57 Correct 3 ms 12380 KB n=500
58 Correct 3 ms 12376 KB n=500
59 Correct 5 ms 12380 KB n=2000
60 Correct 6 ms 12632 KB n=2000
61 Correct 5 ms 12632 KB n=2000
62 Correct 4 ms 12376 KB n=2000
63 Correct 5 ms 12376 KB n=2000
64 Correct 5 ms 12376 KB n=2000
65 Correct 6 ms 12380 KB n=2000
66 Correct 5 ms 12632 KB n=2000
67 Correct 5 ms 12380 KB n=2000
68 Correct 5 ms 12380 KB n=2000
69 Correct 7 ms 12436 KB n=2000
70 Correct 6 ms 12380 KB n=2000
71 Correct 6 ms 12380 KB n=2000
72 Correct 6 ms 12380 KB n=2000
73 Correct 5 ms 12376 KB n=2000
74 Correct 4 ms 12380 KB n=1844
75 Correct 5 ms 12380 KB n=2000
76 Correct 5 ms 12616 KB n=2000
77 Correct 5 ms 12388 KB n=2000
78 Correct 5 ms 12392 KB n=2000
79 Correct 5 ms 12380 KB n=2000
80 Correct 6 ms 12644 KB n=2000
81 Correct 6 ms 12380 KB n=2000
82 Correct 4 ms 12376 KB n=2000
83 Correct 5 ms 12536 KB n=2000
84 Correct 4 ms 12604 KB n=2000
85 Correct 5 ms 12380 KB n=2000
86 Correct 4 ms 12380 KB n=2000
87 Correct 4 ms 12380 KB n=2000
88 Correct 6 ms 12636 KB n=2000
89 Correct 5 ms 12632 KB n=2000
90 Correct 6 ms 12632 KB n=2000
91 Correct 7 ms 12380 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12380 KB n=5
2 Correct 2 ms 12376 KB n=100
3 Correct 3 ms 12380 KB n=100
4 Correct 3 ms 12304 KB n=100
5 Correct 3 ms 12380 KB n=100
6 Correct 3 ms 12380 KB n=100
7 Correct 3 ms 12380 KB n=100
8 Correct 3 ms 12380 KB n=100
9 Correct 4 ms 12380 KB n=100
10 Correct 3 ms 12384 KB n=100
11 Correct 3 ms 12380 KB n=100
12 Correct 2 ms 12380 KB n=100
13 Correct 3 ms 12380 KB n=100
14 Correct 3 ms 12380 KB n=100
15 Correct 3 ms 12628 KB n=100
16 Correct 3 ms 12380 KB n=100
17 Correct 3 ms 12424 KB n=100
18 Correct 3 ms 12632 KB n=100
19 Correct 3 ms 12380 KB n=100
20 Correct 2 ms 12380 KB n=100
21 Correct 3 ms 12380 KB n=100
22 Correct 3 ms 12380 KB n=100
23 Correct 3 ms 12380 KB n=100
24 Correct 3 ms 12376 KB n=100
25 Correct 3 ms 12380 KB n=100
26 Correct 3 ms 12376 KB n=12
27 Correct 3 ms 12376 KB n=100
28 Correct 3 ms 12380 KB n=500
29 Correct 3 ms 12380 KB n=500
30 Correct 3 ms 12432 KB n=500
31 Correct 3 ms 12888 KB n=500
32 Correct 3 ms 12380 KB n=500
33 Correct 3 ms 12380 KB n=500
34 Correct 3 ms 12380 KB n=500
35 Correct 3 ms 12384 KB n=500
36 Correct 4 ms 12384 KB n=500
37 Correct 3 ms 12380 KB n=500
38 Correct 3 ms 12380 KB n=500
39 Correct 3 ms 12380 KB n=500
40 Correct 3 ms 12380 KB n=500
41 Correct 4 ms 12380 KB n=500
42 Correct 3 ms 12380 KB n=500
43 Correct 3 ms 12376 KB n=500
44 Correct 3 ms 12380 KB n=500
45 Correct 3 ms 12380 KB n=500
46 Correct 3 ms 12376 KB n=500
47 Correct 3 ms 12376 KB n=500
48 Correct 3 ms 12380 KB n=500
49 Correct 3 ms 12380 KB n=500
50 Correct 3 ms 12380 KB n=500
51 Correct 3 ms 12380 KB n=500
52 Correct 3 ms 12376 KB n=500
53 Correct 3 ms 12376 KB n=500
54 Correct 3 ms 12632 KB n=500
55 Correct 3 ms 12376 KB n=278
56 Correct 3 ms 12380 KB n=500
57 Correct 3 ms 12380 KB n=500
58 Correct 3 ms 12376 KB n=500
59 Correct 5 ms 12380 KB n=2000
60 Correct 6 ms 12632 KB n=2000
61 Correct 5 ms 12632 KB n=2000
62 Correct 4 ms 12376 KB n=2000
63 Correct 5 ms 12376 KB n=2000
64 Correct 5 ms 12376 KB n=2000
65 Correct 6 ms 12380 KB n=2000
66 Correct 5 ms 12632 KB n=2000
67 Correct 5 ms 12380 KB n=2000
68 Correct 5 ms 12380 KB n=2000
69 Correct 7 ms 12436 KB n=2000
70 Correct 6 ms 12380 KB n=2000
71 Correct 6 ms 12380 KB n=2000
72 Correct 6 ms 12380 KB n=2000
73 Correct 5 ms 12376 KB n=2000
74 Correct 4 ms 12380 KB n=1844
75 Correct 5 ms 12380 KB n=2000
76 Correct 5 ms 12616 KB n=2000
77 Correct 5 ms 12388 KB n=2000
78 Correct 5 ms 12392 KB n=2000
79 Correct 5 ms 12380 KB n=2000
80 Correct 6 ms 12644 KB n=2000
81 Correct 6 ms 12380 KB n=2000
82 Correct 4 ms 12376 KB n=2000
83 Correct 5 ms 12536 KB n=2000
84 Correct 4 ms 12604 KB n=2000
85 Correct 5 ms 12380 KB n=2000
86 Correct 4 ms 12380 KB n=2000
87 Correct 4 ms 12380 KB n=2000
88 Correct 6 ms 12636 KB n=2000
89 Correct 5 ms 12632 KB n=2000
90 Correct 6 ms 12632 KB n=2000
91 Correct 7 ms 12380 KB n=2000
92 Execution timed out 4094 ms 82820 KB Time limit exceeded
93 Halted 0 ms 0 KB -