답안 #868955

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
868955 2023-11-02T14:20:06 Z vjudge1 Birthday gift (IZhO18_treearray) C++17
0 / 100
9 ms 37556 KB
#include <bits/stdc++.h>

#define file(s) freopen(s".in", "r", stdin); freopen(s".out", "w", stdout);
#define adiyer(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define pb emplace_back
#define elif else if
#define uns unsigned
#define emp empty()
#define nll nullptr
#define S second
#define F first

using namespace std;

typedef long long ll;
typedef long double ldb;
typedef vector < ll > vll;
typedef vector < int > vi;
typedef pair < ll, ll > pll;
typedef pair < int, int > pi;
typedef pair < ldb, ldb > pldb;
typedef vector < pair < ll, ll > > vpll;
typedef vector < pair < int, int > > vpi;

const int N = 3e5 + 11;
const int M = 1e4 + 123;
const int mod = 1e9 + 7;
const int mxlg = 19;
const int K = 20;
const int P = 31;
const ll inf = 1e9 + 10;

//mt19937 rnd(07062006);

int n, m, q;
int a[N], d[N];
int up[N][K];

set < int > s1[N], s2[N];

vector < int > g[N];

void dfs(int v = 1, int p = 0){
	up[v][0] = p;
	for(int i = 1; i < mxlg; i++) up[v][i] = up[up[v][i - 1]][i - 1];
	for(auto to : g[v])
		if(to != p)
			d[to] = d[v] + 1,
			dfs(to, v);
}

int lca(int a, int b) {
	if(d[a] < d[b]) swap(a, b);
	int k = d[a] - d[b];
	for(int i = 0; i < mxlg; i++) 
		if(((k >> i) & 1)) 
			a = up[a][i];
	if(a == b) return a;
	for(int i = mxlg - 1; i >= 0; i--) 
		if(up[a][i] != up[b][i])
			a = up[a][i], b = up[b][i];
	return up[a][0];
}

void output(){
	cin >> n >> m >> q;
	for(int u, v, i = 1; i < n; i++){
		cin >> u >> v;
		g[u].pb(v), g[v].pb(u);
	}
	dfs();
	for(int i = 1; i <= m; i++) cin >> a[i];
	for(int i = 1; i < m; i++){
		s1[a[i]].insert(i), s2[lca(a[i], a[i + 1])].insert(i);
//		cout << lca(a[i], a[i + 1]) << ' ';
	}
	while(q--){
		int tp;
		cin >> tp;
		if(tp == 1){
			int k, x;
			cin >> k >> x;
			s1[a[k]].erase(k);
			if(k != 1) s2[lca(a[k - 1], a[k])].erase(k - 1);
			if(k != n) s2[lca(a[k], a[k + 1])].erase(k);
			a[k] = x;
			s1[a[k]].insert(k);
			if(k != 1) s2[lca(a[k - 1], a[k])].insert(k - 1);
			if(k != n) s2[lca(a[k], a[k + 1])].insert(k);
		}
		else{
			int l, r, v;
			cin >> l >> r >> v;
			auto it1 = s1[v].lower_bound(l);
			auto it2 = s2[v].lower_bound(l);
			if(it1 != s1[v].end() && *it1 <= r) cout << *it1 << ' ' << *it1 << '\n';
			else if(it2 != s2[v].end() && *it2 < r) cout << *it2 << ' ' << *it2 + 1 << '\n';
			else cout << "-1 -1\n";
		}
	}
}

const bool cases = 0;

signed main(){
//  file("disrupt");
    adiyer();
    int tt = 1;
    if(cases) cin >> tt;
    for(int i = 1; i <= tt; i++){
//      cout << "Case " << i << ":\n";
        output();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 37464 KB n=5
2 Correct 9 ms 37464 KB n=100
3 Correct 7 ms 37468 KB n=100
4 Correct 7 ms 37468 KB n=100
5 Correct 7 ms 37468 KB n=100
6 Correct 7 ms 37468 KB n=100
7 Correct 7 ms 37468 KB n=100
8 Correct 7 ms 37468 KB n=100
9 Correct 8 ms 37468 KB n=100
10 Correct 7 ms 37468 KB n=100
11 Correct 8 ms 37468 KB n=100
12 Correct 7 ms 37468 KB n=100
13 Correct 8 ms 37468 KB n=100
14 Correct 8 ms 37468 KB n=100
15 Correct 7 ms 37468 KB n=100
16 Correct 7 ms 37464 KB n=100
17 Incorrect 7 ms 37556 KB Jury has the answer but participant has not
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 37464 KB n=5
2 Correct 9 ms 37464 KB n=100
3 Correct 7 ms 37468 KB n=100
4 Correct 7 ms 37468 KB n=100
5 Correct 7 ms 37468 KB n=100
6 Correct 7 ms 37468 KB n=100
7 Correct 7 ms 37468 KB n=100
8 Correct 7 ms 37468 KB n=100
9 Correct 8 ms 37468 KB n=100
10 Correct 7 ms 37468 KB n=100
11 Correct 8 ms 37468 KB n=100
12 Correct 7 ms 37468 KB n=100
13 Correct 8 ms 37468 KB n=100
14 Correct 8 ms 37468 KB n=100
15 Correct 7 ms 37468 KB n=100
16 Correct 7 ms 37464 KB n=100
17 Incorrect 7 ms 37556 KB Jury has the answer but participant has not
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 37464 KB n=5
2 Correct 9 ms 37464 KB n=100
3 Correct 7 ms 37468 KB n=100
4 Correct 7 ms 37468 KB n=100
5 Correct 7 ms 37468 KB n=100
6 Correct 7 ms 37468 KB n=100
7 Correct 7 ms 37468 KB n=100
8 Correct 7 ms 37468 KB n=100
9 Correct 8 ms 37468 KB n=100
10 Correct 7 ms 37468 KB n=100
11 Correct 8 ms 37468 KB n=100
12 Correct 7 ms 37468 KB n=100
13 Correct 8 ms 37468 KB n=100
14 Correct 8 ms 37468 KB n=100
15 Correct 7 ms 37468 KB n=100
16 Correct 7 ms 37464 KB n=100
17 Incorrect 7 ms 37556 KB Jury has the answer but participant has not
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 37464 KB n=5
2 Correct 9 ms 37464 KB n=100
3 Correct 7 ms 37468 KB n=100
4 Correct 7 ms 37468 KB n=100
5 Correct 7 ms 37468 KB n=100
6 Correct 7 ms 37468 KB n=100
7 Correct 7 ms 37468 KB n=100
8 Correct 7 ms 37468 KB n=100
9 Correct 8 ms 37468 KB n=100
10 Correct 7 ms 37468 KB n=100
11 Correct 8 ms 37468 KB n=100
12 Correct 7 ms 37468 KB n=100
13 Correct 8 ms 37468 KB n=100
14 Correct 8 ms 37468 KB n=100
15 Correct 7 ms 37468 KB n=100
16 Correct 7 ms 37464 KB n=100
17 Incorrect 7 ms 37556 KB Jury has the answer but participant has not
18 Halted 0 ms 0 KB -