Submission #245587

# Submission time Handle Problem Language Result Execution time Memory
245587 2020-07-06T21:11:46 Z Yera Birthday gift (IZhO18_treearray) C++14
0 / 100
9 ms 7424 KB
// In The Name Of God
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <bitset>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <unordered_set>
#include <unordered_map>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
 
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define sagyndym_seni ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
 
const ll N = 2e5+5, p1 = 911382323, p2 = 972663749, INF = 1e9+123;
 
inline int read(){
	char c = getchar_unlocked();
	bool minus = 0;
	while (c < '0' || '9' < c){
		if(c == '-'){ minus = 1;}
		c = getchar_unlocked();
		if(c == '-'){ minus = 1;}
	}
	int res = 0;
	while ('0' <= c && c <= '9') {
		res = (res << 3) + (res << 1) + c - '0';
		c = getchar_unlocked();
	}
	if(minus){ res = (~res) + 1;}
	return res;
}
 
int n, m, q, tick = 0;
int depth[N], pos[N], LOG[N], inv[N], ans[N], was[N];
pair<int, int> st[N][30];
vector<int> vec, g[N];
vector<pair<int, int>> order;
 
void dfs(int v, int p){
	order.pb({depth[v], v});
	pos[v] = sz(order)-1;
 
	for(auto to : g[v]){
		if(to == p){ continue;}
		depth[to] = depth[v] + 1;
		dfs(to, v);
		order.pb({depth[v], v});
	}
}
 
void precalc(){
	LOG[1] = 0;
	for(int i = 2; i < N; i++){
		LOG[i] = LOG[i >> 1] + 1;
	}
	for(int i = 0; i < sz(order); i++){
		st[i][0] = order[i];
	}
	for(int j = 1; j < 30; j++){
		for(int i = 0; i + (1 << j) < sz(order); i++){
			st[i][j] = min(st[i][j-1], st[i + (1 << (j-1))][j-1]);
		}
	}
}
 
int mn(int l, int r){
	if(r < l){ swap(l, r);}
	int j = LOG[r - l + 1];
	pair<int, int> res = min(st[l][j], st[r - (1 << j) + 1][j]);
	return res.s;
}

int main(){
	n = read(); m = read(); q = read();
	vec.resize(m);
	fill(inv, inv + N, -1);
	fill(was, was + N, -1);
	for(int i = 1; i < n; i++){
		int v = read()-1, u = read()-1;
		g[v].pb(u);
		g[u].pb(v);
	}
	for(int i = 0; i < m; i++){
		vec[i] = read()-1;
		was[vec[i]] = i;
	}
	dfs(0, 0);
	precalc();

	for(int i = 0; i < m - 1; i++){
		ans[i] = mn(pos[vec[i]], pos[vec[i + 1]]);
		inv[ans[i]] = i;
	}
	
	while(q--){
		int tp = read()-1;
		if(!tp){
			int p = read()-1, v = read()-1;
			was[vec[p]] = -1; vec[p] = v; was[vec[p]] = p;
			if(p != m - 1){
				inv[ans[p]] = -1;
				ans[p] = mn(pos[vec[p]], pos[vec[p+1]]);
				inv[ans[p]] = p;
			}
			if(p != 0){
				inv[ans[p-1]] = -1;
				ans[p-1] = mn(pos[vec[p-1]], pos[vec[p]]);
				inv[ans[p-1]] = p-1;
			}
		}else{
			int l = read()-1, r = read()-1, p = read()-1;
			if(l <= was[p] && was[p] <= r){ cout<<'\n'<<was[p]+1<<' '<<was[p]+1; continue;}
			if(inv[p] != -1 && l <= inv[p] && inv[p] < r){ cout<<'\n'<<inv[p]+1<<' '<<inv[p]+2; continue;}
			cout<<"\n-1 -1";
		}
	}
	return 0;
}
//5 4 1
//1 2
//3 1
//3 4
//5 3
//4 5 2 3
//2 1 3 1
/* TIMUS: 292220YC*/
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 7424 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 7424 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 7424 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 7424 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -