답안 #160744

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
160744 2019-10-29T17:36:19 Z shashwatchandra Birthday gift (IZhO18_treearray) C++17
100 / 100
2114 ms 98584 KB
/*input
5 4 4
1 2
3 1
3 4
5 3
4 5 2 3
2 1 3 1
1 3 5
2 3 4 5
2 1 3 1

4 5 5 3
*/
#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 22 ms 23800 KB n=5
2 Correct 23 ms 23800 KB n=100
3 Correct 25 ms 23788 KB n=100
4 Correct 23 ms 23928 KB n=100
5 Correct 23 ms 23860 KB n=100
6 Correct 23 ms 23800 KB n=100
7 Correct 23 ms 23800 KB n=100
8 Correct 28 ms 23876 KB n=100
9 Correct 23 ms 24004 KB n=100
10 Correct 24 ms 23928 KB n=100
11 Correct 24 ms 23928 KB n=100
12 Correct 23 ms 23928 KB n=100
13 Correct 23 ms 23928 KB n=100
14 Correct 23 ms 23928 KB n=100
15 Correct 29 ms 23928 KB n=100
16 Correct 23 ms 23932 KB n=100
17 Correct 24 ms 23928 KB n=100
18 Correct 24 ms 23928 KB n=100
19 Correct 23 ms 23800 KB n=100
20 Correct 23 ms 23800 KB n=100
21 Correct 24 ms 23928 KB n=100
22 Correct 24 ms 23928 KB n=100
23 Correct 23 ms 23928 KB n=100
24 Correct 23 ms 23800 KB n=100
25 Correct 23 ms 23928 KB n=100
26 Correct 23 ms 23928 KB n=12
27 Correct 24 ms 23800 KB n=100
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 23800 KB n=5
2 Correct 23 ms 23800 KB n=100
3 Correct 25 ms 23788 KB n=100
4 Correct 23 ms 23928 KB n=100
5 Correct 23 ms 23860 KB n=100
6 Correct 23 ms 23800 KB n=100
7 Correct 23 ms 23800 KB n=100
8 Correct 28 ms 23876 KB n=100
9 Correct 23 ms 24004 KB n=100
10 Correct 24 ms 23928 KB n=100
11 Correct 24 ms 23928 KB n=100
12 Correct 23 ms 23928 KB n=100
13 Correct 23 ms 23928 KB n=100
14 Correct 23 ms 23928 KB n=100
15 Correct 29 ms 23928 KB n=100
16 Correct 23 ms 23932 KB n=100
17 Correct 24 ms 23928 KB n=100
18 Correct 24 ms 23928 KB n=100
19 Correct 23 ms 23800 KB n=100
20 Correct 23 ms 23800 KB n=100
21 Correct 24 ms 23928 KB n=100
22 Correct 24 ms 23928 KB n=100
23 Correct 23 ms 23928 KB n=100
24 Correct 23 ms 23800 KB n=100
25 Correct 23 ms 23928 KB n=100
26 Correct 23 ms 23928 KB n=12
27 Correct 24 ms 23800 KB n=100
28 Correct 25 ms 24056 KB n=500
29 Correct 25 ms 24056 KB n=500
30 Correct 25 ms 24056 KB n=500
31 Correct 25 ms 23928 KB n=500
32 Correct 24 ms 24056 KB n=500
33 Correct 25 ms 24028 KB n=500
34 Correct 25 ms 24056 KB n=500
35 Correct 24 ms 23928 KB n=500
36 Correct 25 ms 23928 KB n=500
37 Correct 25 ms 24056 KB n=500
38 Correct 25 ms 24056 KB n=500
39 Correct 24 ms 24056 KB n=500
40 Correct 24 ms 24056 KB n=500
41 Correct 25 ms 24056 KB n=500
42 Correct 25 ms 24056 KB n=500
43 Correct 25 ms 23928 KB n=500
44 Correct 25 ms 24056 KB n=500
45 Correct 24 ms 24056 KB n=500
46 Correct 25 ms 24056 KB n=500
47 Correct 25 ms 24056 KB n=500
48 Correct 25 ms 23928 KB n=500
49 Correct 24 ms 24056 KB n=500
50 Correct 25 ms 23928 KB n=500
51 Correct 24 ms 23928 KB n=500
52 Correct 24 ms 24056 KB n=500
53 Correct 24 ms 24056 KB n=500
54 Correct 25 ms 24056 KB n=500
55 Correct 24 ms 23928 KB n=278
56 Correct 24 ms 24056 KB n=500
57 Correct 24 ms 24056 KB n=500
58 Correct 25 ms 24056 KB n=500
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 23800 KB n=5
2 Correct 23 ms 23800 KB n=100
3 Correct 25 ms 23788 KB n=100
4 Correct 23 ms 23928 KB n=100
5 Correct 23 ms 23860 KB n=100
6 Correct 23 ms 23800 KB n=100
7 Correct 23 ms 23800 KB n=100
8 Correct 28 ms 23876 KB n=100
9 Correct 23 ms 24004 KB n=100
10 Correct 24 ms 23928 KB n=100
11 Correct 24 ms 23928 KB n=100
12 Correct 23 ms 23928 KB n=100
13 Correct 23 ms 23928 KB n=100
14 Correct 23 ms 23928 KB n=100
15 Correct 29 ms 23928 KB n=100
16 Correct 23 ms 23932 KB n=100
17 Correct 24 ms 23928 KB n=100
18 Correct 24 ms 23928 KB n=100
19 Correct 23 ms 23800 KB n=100
20 Correct 23 ms 23800 KB n=100
21 Correct 24 ms 23928 KB n=100
22 Correct 24 ms 23928 KB n=100
23 Correct 23 ms 23928 KB n=100
24 Correct 23 ms 23800 KB n=100
25 Correct 23 ms 23928 KB n=100
26 Correct 23 ms 23928 KB n=12
27 Correct 24 ms 23800 KB n=100
28 Correct 25 ms 24056 KB n=500
29 Correct 25 ms 24056 KB n=500
30 Correct 25 ms 24056 KB n=500
31 Correct 25 ms 23928 KB n=500
32 Correct 24 ms 24056 KB n=500
33 Correct 25 ms 24028 KB n=500
34 Correct 25 ms 24056 KB n=500
35 Correct 24 ms 23928 KB n=500
36 Correct 25 ms 23928 KB n=500
37 Correct 25 ms 24056 KB n=500
38 Correct 25 ms 24056 KB n=500
39 Correct 24 ms 24056 KB n=500
40 Correct 24 ms 24056 KB n=500
41 Correct 25 ms 24056 KB n=500
42 Correct 25 ms 24056 KB n=500
43 Correct 25 ms 23928 KB n=500
44 Correct 25 ms 24056 KB n=500
45 Correct 24 ms 24056 KB n=500
46 Correct 25 ms 24056 KB n=500
47 Correct 25 ms 24056 KB n=500
48 Correct 25 ms 23928 KB n=500
49 Correct 24 ms 24056 KB n=500
50 Correct 25 ms 23928 KB n=500
51 Correct 24 ms 23928 KB n=500
52 Correct 24 ms 24056 KB n=500
53 Correct 24 ms 24056 KB n=500
54 Correct 25 ms 24056 KB n=500
55 Correct 24 ms 23928 KB n=278
56 Correct 24 ms 24056 KB n=500
57 Correct 24 ms 24056 KB n=500
58 Correct 25 ms 24056 KB n=500
59 Correct 34 ms 24524 KB n=2000
60 Correct 31 ms 24568 KB n=2000
61 Correct 31 ms 24440 KB n=2000
62 Correct 32 ms 24440 KB n=2000
63 Correct 31 ms 24508 KB n=2000
64 Correct 31 ms 24572 KB n=2000
65 Correct 30 ms 24440 KB n=2000
66 Correct 31 ms 24440 KB n=2000
67 Correct 31 ms 24440 KB n=2000
68 Correct 30 ms 24444 KB n=2000
69 Correct 32 ms 24440 KB n=2000
70 Correct 32 ms 24444 KB n=2000
71 Correct 32 ms 24440 KB n=2000
72 Correct 26 ms 24568 KB n=2000
73 Correct 26 ms 24440 KB n=2000
74 Correct 30 ms 24440 KB n=1844
75 Correct 27 ms 24568 KB n=2000
76 Correct 31 ms 24508 KB n=2000
77 Correct 32 ms 24440 KB n=2000
78 Correct 31 ms 24444 KB n=2000
79 Correct 31 ms 24444 KB n=2000
80 Correct 30 ms 24568 KB n=2000
81 Correct 31 ms 24440 KB n=2000
82 Correct 31 ms 24440 KB n=2000
83 Correct 30 ms 24440 KB n=2000
84 Correct 30 ms 24440 KB n=2000
85 Correct 30 ms 24444 KB n=2000
86 Correct 29 ms 24524 KB n=2000
87 Correct 31 ms 24440 KB n=2000
88 Correct 46 ms 24568 KB n=2000
89 Correct 28 ms 24568 KB n=2000
90 Correct 30 ms 24440 KB n=2000
91 Correct 31 ms 24412 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 23800 KB n=5
2 Correct 23 ms 23800 KB n=100
3 Correct 25 ms 23788 KB n=100
4 Correct 23 ms 23928 KB n=100
5 Correct 23 ms 23860 KB n=100
6 Correct 23 ms 23800 KB n=100
7 Correct 23 ms 23800 KB n=100
8 Correct 28 ms 23876 KB n=100
9 Correct 23 ms 24004 KB n=100
10 Correct 24 ms 23928 KB n=100
11 Correct 24 ms 23928 KB n=100
12 Correct 23 ms 23928 KB n=100
13 Correct 23 ms 23928 KB n=100
14 Correct 23 ms 23928 KB n=100
15 Correct 29 ms 23928 KB n=100
16 Correct 23 ms 23932 KB n=100
17 Correct 24 ms 23928 KB n=100
18 Correct 24 ms 23928 KB n=100
19 Correct 23 ms 23800 KB n=100
20 Correct 23 ms 23800 KB n=100
21 Correct 24 ms 23928 KB n=100
22 Correct 24 ms 23928 KB n=100
23 Correct 23 ms 23928 KB n=100
24 Correct 23 ms 23800 KB n=100
25 Correct 23 ms 23928 KB n=100
26 Correct 23 ms 23928 KB n=12
27 Correct 24 ms 23800 KB n=100
28 Correct 25 ms 24056 KB n=500
29 Correct 25 ms 24056 KB n=500
30 Correct 25 ms 24056 KB n=500
31 Correct 25 ms 23928 KB n=500
32 Correct 24 ms 24056 KB n=500
33 Correct 25 ms 24028 KB n=500
34 Correct 25 ms 24056 KB n=500
35 Correct 24 ms 23928 KB n=500
36 Correct 25 ms 23928 KB n=500
37 Correct 25 ms 24056 KB n=500
38 Correct 25 ms 24056 KB n=500
39 Correct 24 ms 24056 KB n=500
40 Correct 24 ms 24056 KB n=500
41 Correct 25 ms 24056 KB n=500
42 Correct 25 ms 24056 KB n=500
43 Correct 25 ms 23928 KB n=500
44 Correct 25 ms 24056 KB n=500
45 Correct 24 ms 24056 KB n=500
46 Correct 25 ms 24056 KB n=500
47 Correct 25 ms 24056 KB n=500
48 Correct 25 ms 23928 KB n=500
49 Correct 24 ms 24056 KB n=500
50 Correct 25 ms 23928 KB n=500
51 Correct 24 ms 23928 KB n=500
52 Correct 24 ms 24056 KB n=500
53 Correct 24 ms 24056 KB n=500
54 Correct 25 ms 24056 KB n=500
55 Correct 24 ms 23928 KB n=278
56 Correct 24 ms 24056 KB n=500
57 Correct 24 ms 24056 KB n=500
58 Correct 25 ms 24056 KB n=500
59 Correct 34 ms 24524 KB n=2000
60 Correct 31 ms 24568 KB n=2000
61 Correct 31 ms 24440 KB n=2000
62 Correct 32 ms 24440 KB n=2000
63 Correct 31 ms 24508 KB n=2000
64 Correct 31 ms 24572 KB n=2000
65 Correct 30 ms 24440 KB n=2000
66 Correct 31 ms 24440 KB n=2000
67 Correct 31 ms 24440 KB n=2000
68 Correct 30 ms 24444 KB n=2000
69 Correct 32 ms 24440 KB n=2000
70 Correct 32 ms 24444 KB n=2000
71 Correct 32 ms 24440 KB n=2000
72 Correct 26 ms 24568 KB n=2000
73 Correct 26 ms 24440 KB n=2000
74 Correct 30 ms 24440 KB n=1844
75 Correct 27 ms 24568 KB n=2000
76 Correct 31 ms 24508 KB n=2000
77 Correct 32 ms 24440 KB n=2000
78 Correct 31 ms 24444 KB n=2000
79 Correct 31 ms 24444 KB n=2000
80 Correct 30 ms 24568 KB n=2000
81 Correct 31 ms 24440 KB n=2000
82 Correct 31 ms 24440 KB n=2000
83 Correct 30 ms 24440 KB n=2000
84 Correct 30 ms 24440 KB n=2000
85 Correct 30 ms 24444 KB n=2000
86 Correct 29 ms 24524 KB n=2000
87 Correct 31 ms 24440 KB n=2000
88 Correct 46 ms 24568 KB n=2000
89 Correct 28 ms 24568 KB n=2000
90 Correct 30 ms 24440 KB n=2000
91 Correct 31 ms 24412 KB n=2000
92 Correct 1296 ms 83304 KB n=200000
93 Correct 2055 ms 90440 KB n=200000
94 Correct 1981 ms 97416 KB n=200000
95 Correct 1267 ms 89412 KB n=200000
96 Correct 1276 ms 89436 KB n=200000
97 Correct 2017 ms 93816 KB n=200000
98 Correct 1329 ms 89560 KB n=200000
99 Correct 1571 ms 89976 KB n=200000
100 Correct 1280 ms 89492 KB n=200000
101 Correct 2114 ms 98584 KB n=200000
102 Correct 1174 ms 91072 KB n=200000
103 Correct 1168 ms 91136 KB n=200000
104 Correct 1167 ms 91092 KB n=200000
105 Correct 1132 ms 91432 KB n=200000
106 Correct 1128 ms 91512 KB n=200000
107 Correct 1163 ms 91352 KB n=200000
108 Correct 1541 ms 89792 KB n=200000
109 Correct 1529 ms 89876 KB n=200000
110 Correct 1575 ms 89868 KB n=200000
111 Correct 1322 ms 89016 KB n=200000
112 Correct 1974 ms 97736 KB n=200000
113 Correct 2013 ms 93712 KB n=200000
114 Correct 1284 ms 88964 KB n=200000
115 Correct 2062 ms 91640 KB n=200000
116 Correct 1323 ms 89712 KB n=200000
117 Correct 1812 ms 97992 KB n=200000
118 Correct 1929 ms 92536 KB n=200000
119 Correct 1132 ms 89532 KB n=200000
120 Correct 1679 ms 97356 KB n=200000
121 Correct 1768 ms 97364 KB n=200000
122 Correct 1902 ms 97784 KB n=200000
123 Correct 889 ms 90992 KB n=200000
124 Correct 464 ms 41000 KB n=25264