Submission #865577

# Submission time Handle Problem Language Result Execution time Memory
865577 2023-10-24T11:08:25 Z vjudge1 Birthday gift (IZhO18_treearray) C++17
0 / 100
8 ms 31424 KB
//order_of_key(k): Number of items strictly smaller than k .
//find_by_order(k): K-th element in a set (counting from zero).

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define file(s) if(fopen(s".in","r")) freopen(s".in","r",stdin);freopen(s".out","w",stdout)
#define all(x) (x).begin(), (x).end()
#define len(x) (int)x.size()
#define tm (tl + tr >> 1)
#define ls v << 1, tl, tm
#define rs v << 1 | 1, tm + 1, tr
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define elif else if
#define F first
#define S second
#define int long long

using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
typedef long double ld;

const int MOD = 1e9 + 7;
const int N = 2e5 + 7;
const int P = 911;
const ll INF = 1e18;

int rnd() {
	int x = rand() << 15;
	return x ^ rand();
}

int tin[N], tout[N], up[N][19], t[N << 2], a[N], temp, m;
vector <int> g[N];

void dfs(int v, int pr) {
	tin[v] = ++temp;
	up[v][0] = pr;
	for (int i = 1; i <= 18; i++) {
		up[v][i] = up[up[v][i - 1]][i - 1];
	}
	for (int u: g[v]) if (u != pr) {
		dfs(u, v);
	}
	tout[v] = temp;
}

bool upper(int v, int u) {
	return tin[v] <= tin[u] && tout[v] >= tout[u];
}

int lca(int v, int u) {
	if (v && (!u || upper(v, u))) return v;
	if (u && (!v || upper(u, v))) return u;
	for (int i = 18; i >= 0; i--) {
		if (!up[v][i]) continue;
		if (!upper(up[v][i], u)) v = up[v][i];
	}
	return up[v][0];
}

set <int> pos[N], ext[N];

void GazizMadi() {
	int n, q;
	cin >> n >> m >> q;
	for (int i = 1, v, u; i < n; i++) {
		cin >> v >> u;
		g[v].pb(u);
		g[u].pb(v);
	}
	dfs(1, 0);
	for (int i = 1; i <= m; i++) {
		cin >> a[i];
		pos[a[i]].insert(i);
		if (i > 1) {
			ext[lca(a[i - 1], a[i])].insert(i - 1);
		}
	}
	while (q--) {
		int ty;
		cin >> ty;
		if (ty == 1) {
			int i, val;
			cin >> i >> val;
			if (i < m) ext[lca(a[i], a[i + 1])].erase(i);
			if (i > 1) ext[lca(a[i - 1], a[i])].erase(i - 1);
			pos[a[i]].erase(i);
			a[i] = val;
			pos[a[i]].insert(i);
			if (i < m) ext[lca(a[i], a[i + 1])].insert(i);
			if (i > 1) ext[lca(a[i - 1], a[i])].insert(i - 1);
		} else {
			int l, r, v;
			cin >> l >> r >> v;
			if (pos[v].lower_bound(l) != pos[v].end() && (*pos[v].lower_bound(l)) <= r) {
				int x = *(pos[v].lower_bound(l));
				cout << x << ' ' << x << '\n';
			} elif (ext[v].lower_bound(l) != ext[v].end() && (*ext[v].lower_bound(l)) <= r) {
				int x = *(ext[v].lower_bound(l));
				cout << x << ' ' << x + 1 << '\n';
			} else {
				cout << -1 << ' ' << -1 << '\n';
			}
		}
	}
	
}

const bool Cases = 0;

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	srand(time(0));
	int TT = 1;
	if (Cases) cin >> TT;
	for (int i = 1; i <= TT; i++) {
		//cout << "Case " << i << ": ";
		GazizMadi();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 31324 KB n=5
2 Correct 6 ms 31424 KB n=100
3 Correct 8 ms 31324 KB n=100
4 Correct 7 ms 31324 KB n=100
5 Correct 6 ms 31324 KB n=100
6 Correct 6 ms 31396 KB n=100
7 Correct 6 ms 31324 KB n=100
8 Correct 6 ms 31324 KB n=100
9 Correct 7 ms 31324 KB n=100
10 Correct 6 ms 31324 KB n=100
11 Correct 6 ms 31324 KB n=100
12 Incorrect 7 ms 31324 KB Wrong output format.
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 31324 KB n=5
2 Correct 6 ms 31424 KB n=100
3 Correct 8 ms 31324 KB n=100
4 Correct 7 ms 31324 KB n=100
5 Correct 6 ms 31324 KB n=100
6 Correct 6 ms 31396 KB n=100
7 Correct 6 ms 31324 KB n=100
8 Correct 6 ms 31324 KB n=100
9 Correct 7 ms 31324 KB n=100
10 Correct 6 ms 31324 KB n=100
11 Correct 6 ms 31324 KB n=100
12 Incorrect 7 ms 31324 KB Wrong output format.
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 31324 KB n=5
2 Correct 6 ms 31424 KB n=100
3 Correct 8 ms 31324 KB n=100
4 Correct 7 ms 31324 KB n=100
5 Correct 6 ms 31324 KB n=100
6 Correct 6 ms 31396 KB n=100
7 Correct 6 ms 31324 KB n=100
8 Correct 6 ms 31324 KB n=100
9 Correct 7 ms 31324 KB n=100
10 Correct 6 ms 31324 KB n=100
11 Correct 6 ms 31324 KB n=100
12 Incorrect 7 ms 31324 KB Wrong output format.
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 31324 KB n=5
2 Correct 6 ms 31424 KB n=100
3 Correct 8 ms 31324 KB n=100
4 Correct 7 ms 31324 KB n=100
5 Correct 6 ms 31324 KB n=100
6 Correct 6 ms 31396 KB n=100
7 Correct 6 ms 31324 KB n=100
8 Correct 6 ms 31324 KB n=100
9 Correct 7 ms 31324 KB n=100
10 Correct 6 ms 31324 KB n=100
11 Correct 6 ms 31324 KB n=100
12 Incorrect 7 ms 31324 KB Wrong output format.
13 Halted 0 ms 0 KB -