답안 #166809

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
166809 2019-12-04T07:21:21 Z Yaroslaff Birthday gift (IZhO18_treearray) C++14
100 / 100
2382 ms 98416 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
 
#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
 
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
 
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
 
const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;
 
int raise(int a,int n,int m = MOD){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= raise(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}
 
int floor1(int n,int k){
    if(n%k == 0 || n >= 0)return n/k;
    return (n/k)-1;
}
 
int ceil1(int n,int k){
    return floor1(n+k-1,k);
}
 
const int LG = 18;
const int N = 2e5+1;
vector<int> adj[N];
int n,m,q;
int pre[N][LG];
int a[N];
int dist[N];
set<int> ex[N];
set<int> ah[N];
 
void dfs(int u,int p){
	pre[u][0] = p;
	RE(i,LG-1){
		pre[u][i] = pre[pre[u][i-1]][i-1];
	}
	for(int v:adj[u]){
		if(v == p)continue;
		dist[v] = dist[u]+1;
		dfs(v,u);
	}
}
 
int lca(int u,int v){
	if(dist[v] > dist[u])swap(u,v);
	for(int i = LG-1;i > -1;i--){
		if(dist[pre[u][i]] >= dist[v]){
			u = pre[u][i];
		}
	}
	for(int i = LG-1;i > -1;i--){
		if(pre[u][i] != pre[v][i]){
			u = pre[u][i];
			v = pre[v][i];
		}
	}
	if(u == v)return u;
	return pre[u][0];
}
 
void solve(){
  	cin >> n >> m >> q;
  	RE(i,n-1){
  		int a,b;cin >> a >> b;
  		adj[a].pb(b);
  		adj[b].pb(a);
  	}
  	dist[1] = 1;
  	dfs(1,0);
  	RE(i,m){
  		cin >> a[i];
  		ah[a[i]].insert(i);
  	}
  	RE(i,m-1){
  		ex[lca(a[i],a[i+1])].insert(i);
  	}
  	while(q--){
  		int ty;cin >> ty;
  		if(ty == 1){
  			int ind,ok;cin >> ind >> ok;
  			if(ind < m){
  				ex[lca(a[ind],a[ind+1])].erase(ind);
  			}
  			if(ind > 1){
  				ex[lca(a[ind-1],a[ind])].erase(ind-1);
  			}
  			ah[a[ind]].erase(ind);
  			a[ind] = ok;
  			if(ind < m){
  				ex[lca(a[ind],a[ind+1])].insert(ind);
  			}
  			if(ind > 1){
  				ex[lca(a[ind-1],a[ind])].insert(ind-1);
  			}
  			ah[a[ind]].insert(ind);
  		}
  		else{
  			int k;
  			int l,r;cin >> l >> r >> k;
  			if(ex[k].size() and *ex[k].begin() < r){
  				//cout << "NICENICE " << r << endl;
  				//print(ex[k]);
  				auto one = ex[k].upper_bound(r-1);
  				one--;
  				//cout << *one << endl;
  				if(*one >= l and *one < r){
  					cout << *one << " " << *one+1 << endl;
  					continue;
  				}
  			}
  			if(ah[k].size() and *ah[k].begin() <= r){
  				auto one = ah[k].upper_bound(r);one--;
  				if(*one >= l){
  					cout << *one << " " << *one << endl;
  					continue;
  				}
  			}
  		/*	auto two = ah[k].upper_bound(r+1);
  			one--;two--;
  			if(one != ex[k].end() and *one >= l){
  				
  			}
  			else if(two != ah[k].end() and *two >= l){
  				cout << *two << " " << *two << endl;
  			}*/
			cout << "-1 -1\n";
  		}
  	}
}
 
 
signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;
  //cin >> t;
  while(t--){
    solve();
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 23932 KB n=5
2 Correct 25 ms 23916 KB n=100
3 Correct 26 ms 23800 KB n=100
4 Correct 26 ms 23800 KB n=100
5 Correct 25 ms 23800 KB n=100
6 Correct 25 ms 23800 KB n=100
7 Correct 27 ms 23804 KB n=100
8 Correct 26 ms 23800 KB n=100
9 Correct 82 ms 23800 KB n=100
10 Correct 25 ms 23800 KB n=100
11 Correct 25 ms 23928 KB n=100
12 Correct 25 ms 23928 KB n=100
13 Correct 25 ms 23928 KB n=100
14 Correct 26 ms 23800 KB n=100
15 Correct 25 ms 23928 KB n=100
16 Correct 25 ms 23928 KB n=100
17 Correct 38 ms 23800 KB n=100
18 Correct 26 ms 23928 KB n=100
19 Correct 25 ms 23928 KB n=100
20 Correct 25 ms 23800 KB n=100
21 Correct 25 ms 23928 KB n=100
22 Correct 25 ms 23800 KB n=100
23 Correct 24 ms 23928 KB n=100
24 Correct 25 ms 23928 KB n=100
25 Correct 26 ms 23896 KB n=100
26 Correct 25 ms 23800 KB n=12
27 Correct 26 ms 23928 KB n=100
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 23932 KB n=5
2 Correct 25 ms 23916 KB n=100
3 Correct 26 ms 23800 KB n=100
4 Correct 26 ms 23800 KB n=100
5 Correct 25 ms 23800 KB n=100
6 Correct 25 ms 23800 KB n=100
7 Correct 27 ms 23804 KB n=100
8 Correct 26 ms 23800 KB n=100
9 Correct 82 ms 23800 KB n=100
10 Correct 25 ms 23800 KB n=100
11 Correct 25 ms 23928 KB n=100
12 Correct 25 ms 23928 KB n=100
13 Correct 25 ms 23928 KB n=100
14 Correct 26 ms 23800 KB n=100
15 Correct 25 ms 23928 KB n=100
16 Correct 25 ms 23928 KB n=100
17 Correct 38 ms 23800 KB n=100
18 Correct 26 ms 23928 KB n=100
19 Correct 25 ms 23928 KB n=100
20 Correct 25 ms 23800 KB n=100
21 Correct 25 ms 23928 KB n=100
22 Correct 25 ms 23800 KB n=100
23 Correct 24 ms 23928 KB n=100
24 Correct 25 ms 23928 KB n=100
25 Correct 26 ms 23896 KB n=100
26 Correct 25 ms 23800 KB n=12
27 Correct 26 ms 23928 KB n=100
28 Correct 27 ms 24056 KB n=500
29 Correct 26 ms 23972 KB n=500
30 Correct 29 ms 24056 KB n=500
31 Correct 26 ms 24056 KB n=500
32 Correct 26 ms 24028 KB n=500
33 Correct 26 ms 24028 KB n=500
34 Correct 26 ms 24056 KB n=500
35 Correct 29 ms 23928 KB n=500
36 Correct 27 ms 24060 KB n=500
37 Correct 27 ms 23928 KB n=500
38 Correct 27 ms 24056 KB n=500
39 Correct 25 ms 23928 KB n=500
40 Correct 25 ms 24056 KB n=500
41 Correct 26 ms 24056 KB n=500
42 Correct 26 ms 24056 KB n=500
43 Correct 27 ms 23928 KB n=500
44 Correct 26 ms 24060 KB n=500
45 Correct 26 ms 23928 KB n=500
46 Correct 26 ms 24056 KB n=500
47 Correct 31 ms 24028 KB n=500
48 Correct 26 ms 23928 KB n=500
49 Correct 26 ms 24028 KB n=500
50 Correct 26 ms 24056 KB n=500
51 Correct 26 ms 24056 KB n=500
52 Correct 26 ms 24056 KB n=500
53 Correct 26 ms 24056 KB n=500
54 Correct 26 ms 24056 KB n=500
55 Correct 25 ms 23928 KB n=278
56 Correct 26 ms 24056 KB n=500
57 Correct 26 ms 24056 KB n=500
58 Correct 25 ms 23928 KB n=500
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 23932 KB n=5
2 Correct 25 ms 23916 KB n=100
3 Correct 26 ms 23800 KB n=100
4 Correct 26 ms 23800 KB n=100
5 Correct 25 ms 23800 KB n=100
6 Correct 25 ms 23800 KB n=100
7 Correct 27 ms 23804 KB n=100
8 Correct 26 ms 23800 KB n=100
9 Correct 82 ms 23800 KB n=100
10 Correct 25 ms 23800 KB n=100
11 Correct 25 ms 23928 KB n=100
12 Correct 25 ms 23928 KB n=100
13 Correct 25 ms 23928 KB n=100
14 Correct 26 ms 23800 KB n=100
15 Correct 25 ms 23928 KB n=100
16 Correct 25 ms 23928 KB n=100
17 Correct 38 ms 23800 KB n=100
18 Correct 26 ms 23928 KB n=100
19 Correct 25 ms 23928 KB n=100
20 Correct 25 ms 23800 KB n=100
21 Correct 25 ms 23928 KB n=100
22 Correct 25 ms 23800 KB n=100
23 Correct 24 ms 23928 KB n=100
24 Correct 25 ms 23928 KB n=100
25 Correct 26 ms 23896 KB n=100
26 Correct 25 ms 23800 KB n=12
27 Correct 26 ms 23928 KB n=100
28 Correct 27 ms 24056 KB n=500
29 Correct 26 ms 23972 KB n=500
30 Correct 29 ms 24056 KB n=500
31 Correct 26 ms 24056 KB n=500
32 Correct 26 ms 24028 KB n=500
33 Correct 26 ms 24028 KB n=500
34 Correct 26 ms 24056 KB n=500
35 Correct 29 ms 23928 KB n=500
36 Correct 27 ms 24060 KB n=500
37 Correct 27 ms 23928 KB n=500
38 Correct 27 ms 24056 KB n=500
39 Correct 25 ms 23928 KB n=500
40 Correct 25 ms 24056 KB n=500
41 Correct 26 ms 24056 KB n=500
42 Correct 26 ms 24056 KB n=500
43 Correct 27 ms 23928 KB n=500
44 Correct 26 ms 24060 KB n=500
45 Correct 26 ms 23928 KB n=500
46 Correct 26 ms 24056 KB n=500
47 Correct 31 ms 24028 KB n=500
48 Correct 26 ms 23928 KB n=500
49 Correct 26 ms 24028 KB n=500
50 Correct 26 ms 24056 KB n=500
51 Correct 26 ms 24056 KB n=500
52 Correct 26 ms 24056 KB n=500
53 Correct 26 ms 24056 KB n=500
54 Correct 26 ms 24056 KB n=500
55 Correct 25 ms 23928 KB n=278
56 Correct 26 ms 24056 KB n=500
57 Correct 26 ms 24056 KB n=500
58 Correct 25 ms 23928 KB n=500
59 Correct 32 ms 24568 KB n=2000
60 Correct 32 ms 24568 KB n=2000
61 Correct 32 ms 24568 KB n=2000
62 Correct 33 ms 24440 KB n=2000
63 Correct 32 ms 24440 KB n=2000
64 Correct 32 ms 24568 KB n=2000
65 Correct 35 ms 24440 KB n=2000
66 Correct 31 ms 24568 KB n=2000
67 Correct 32 ms 24568 KB n=2000
68 Correct 32 ms 24568 KB n=2000
69 Correct 34 ms 24568 KB n=2000
70 Correct 33 ms 24568 KB n=2000
71 Correct 35 ms 24572 KB n=2000
72 Correct 27 ms 24440 KB n=2000
73 Correct 30 ms 24568 KB n=2000
74 Correct 32 ms 24440 KB n=1844
75 Correct 28 ms 24440 KB n=2000
76 Correct 33 ms 24440 KB n=2000
77 Correct 35 ms 24440 KB n=2000
78 Correct 33 ms 24568 KB n=2000
79 Correct 32 ms 24440 KB n=2000
80 Correct 31 ms 24568 KB n=2000
81 Correct 32 ms 24568 KB n=2000
82 Correct 31 ms 24440 KB n=2000
83 Correct 31 ms 24568 KB n=2000
84 Correct 30 ms 24568 KB n=2000
85 Correct 31 ms 24568 KB n=2000
86 Correct 33 ms 24440 KB n=2000
87 Correct 31 ms 24568 KB n=2000
88 Correct 30 ms 24636 KB n=2000
89 Correct 29 ms 24568 KB n=2000
90 Correct 34 ms 24568 KB n=2000
91 Correct 31 ms 24536 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 23932 KB n=5
2 Correct 25 ms 23916 KB n=100
3 Correct 26 ms 23800 KB n=100
4 Correct 26 ms 23800 KB n=100
5 Correct 25 ms 23800 KB n=100
6 Correct 25 ms 23800 KB n=100
7 Correct 27 ms 23804 KB n=100
8 Correct 26 ms 23800 KB n=100
9 Correct 82 ms 23800 KB n=100
10 Correct 25 ms 23800 KB n=100
11 Correct 25 ms 23928 KB n=100
12 Correct 25 ms 23928 KB n=100
13 Correct 25 ms 23928 KB n=100
14 Correct 26 ms 23800 KB n=100
15 Correct 25 ms 23928 KB n=100
16 Correct 25 ms 23928 KB n=100
17 Correct 38 ms 23800 KB n=100
18 Correct 26 ms 23928 KB n=100
19 Correct 25 ms 23928 KB n=100
20 Correct 25 ms 23800 KB n=100
21 Correct 25 ms 23928 KB n=100
22 Correct 25 ms 23800 KB n=100
23 Correct 24 ms 23928 KB n=100
24 Correct 25 ms 23928 KB n=100
25 Correct 26 ms 23896 KB n=100
26 Correct 25 ms 23800 KB n=12
27 Correct 26 ms 23928 KB n=100
28 Correct 27 ms 24056 KB n=500
29 Correct 26 ms 23972 KB n=500
30 Correct 29 ms 24056 KB n=500
31 Correct 26 ms 24056 KB n=500
32 Correct 26 ms 24028 KB n=500
33 Correct 26 ms 24028 KB n=500
34 Correct 26 ms 24056 KB n=500
35 Correct 29 ms 23928 KB n=500
36 Correct 27 ms 24060 KB n=500
37 Correct 27 ms 23928 KB n=500
38 Correct 27 ms 24056 KB n=500
39 Correct 25 ms 23928 KB n=500
40 Correct 25 ms 24056 KB n=500
41 Correct 26 ms 24056 KB n=500
42 Correct 26 ms 24056 KB n=500
43 Correct 27 ms 23928 KB n=500
44 Correct 26 ms 24060 KB n=500
45 Correct 26 ms 23928 KB n=500
46 Correct 26 ms 24056 KB n=500
47 Correct 31 ms 24028 KB n=500
48 Correct 26 ms 23928 KB n=500
49 Correct 26 ms 24028 KB n=500
50 Correct 26 ms 24056 KB n=500
51 Correct 26 ms 24056 KB n=500
52 Correct 26 ms 24056 KB n=500
53 Correct 26 ms 24056 KB n=500
54 Correct 26 ms 24056 KB n=500
55 Correct 25 ms 23928 KB n=278
56 Correct 26 ms 24056 KB n=500
57 Correct 26 ms 24056 KB n=500
58 Correct 25 ms 23928 KB n=500
59 Correct 32 ms 24568 KB n=2000
60 Correct 32 ms 24568 KB n=2000
61 Correct 32 ms 24568 KB n=2000
62 Correct 33 ms 24440 KB n=2000
63 Correct 32 ms 24440 KB n=2000
64 Correct 32 ms 24568 KB n=2000
65 Correct 35 ms 24440 KB n=2000
66 Correct 31 ms 24568 KB n=2000
67 Correct 32 ms 24568 KB n=2000
68 Correct 32 ms 24568 KB n=2000
69 Correct 34 ms 24568 KB n=2000
70 Correct 33 ms 24568 KB n=2000
71 Correct 35 ms 24572 KB n=2000
72 Correct 27 ms 24440 KB n=2000
73 Correct 30 ms 24568 KB n=2000
74 Correct 32 ms 24440 KB n=1844
75 Correct 28 ms 24440 KB n=2000
76 Correct 33 ms 24440 KB n=2000
77 Correct 35 ms 24440 KB n=2000
78 Correct 33 ms 24568 KB n=2000
79 Correct 32 ms 24440 KB n=2000
80 Correct 31 ms 24568 KB n=2000
81 Correct 32 ms 24568 KB n=2000
82 Correct 31 ms 24440 KB n=2000
83 Correct 31 ms 24568 KB n=2000
84 Correct 30 ms 24568 KB n=2000
85 Correct 31 ms 24568 KB n=2000
86 Correct 33 ms 24440 KB n=2000
87 Correct 31 ms 24568 KB n=2000
88 Correct 30 ms 24636 KB n=2000
89 Correct 29 ms 24568 KB n=2000
90 Correct 34 ms 24568 KB n=2000
91 Correct 31 ms 24536 KB n=2000
92 Correct 1358 ms 89668 KB n=200000
93 Correct 2185 ms 94748 KB n=200000
94 Correct 2239 ms 97424 KB n=200000
95 Correct 1427 ms 89424 KB n=200000
96 Correct 1393 ms 89568 KB n=200000
97 Correct 2243 ms 93692 KB n=200000
98 Correct 1389 ms 89524 KB n=200000
99 Correct 1693 ms 89784 KB n=200000
100 Correct 1406 ms 89488 KB n=200000
101 Correct 2225 ms 98416 KB n=200000
102 Correct 1225 ms 91012 KB n=200000
103 Correct 1187 ms 91104 KB n=200000
104 Correct 1223 ms 90872 KB n=200000
105 Correct 1230 ms 91472 KB n=200000
106 Correct 1180 ms 91292 KB n=200000
107 Correct 1194 ms 91240 KB n=200000
108 Correct 1670 ms 89600 KB n=200000
109 Correct 1633 ms 89708 KB n=200000
110 Correct 1691 ms 89660 KB n=200000
111 Correct 1338 ms 88888 KB n=200000
112 Correct 2197 ms 97428 KB n=200000
113 Correct 2382 ms 93640 KB n=200000
114 Correct 1330 ms 89028 KB n=200000
115 Correct 2198 ms 91568 KB n=200000
116 Correct 1149 ms 89504 KB n=200000
117 Correct 2019 ms 97520 KB n=200000
118 Correct 1996 ms 92228 KB n=200000
119 Correct 1137 ms 89596 KB n=200000
120 Correct 1775 ms 97140 KB n=200000
121 Correct 1805 ms 97088 KB n=200000
122 Correct 2061 ms 97332 KB n=200000
123 Correct 921 ms 90996 KB n=200000
124 Correct 500 ms 40784 KB n=25264