답안 #556045

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
556045 2022-05-02T08:57:44 Z ngpin04 Birthday gift (IZhO18_treearray) C++14
0 / 100
12 ms 23764 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define TASK ""
#define ALL(x) (x).begin(), (x).end() 
using namespace std;
template <typename T1, typename T2> bool mini(T1 &a, T2 b) {
	if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maxi(T1 &a, T2 b) {
	if (a < b) {a = b; return true;} return false;
}
const int N = 2e5 + 5; 
const int oo = 1e9;
const long long ooo = 1e18;
const int mod = 1e9 + 7; // 998244353;
const long double pi = acos(-1);

vector <int> adj[N];
set <int> pos[N];
set <int> ind[N];

int T[2 * N][20];
int tin[N];
int h[N];
int a[N];
int n,m,q,timer;

int gethigh(int u, int v) {
	return (h[u] < h[v]) ? u : v;
}

int getlca(int u, int v) {
	int l = tin[u];
	int r = tin[v];
	if (l > r)
		swap(l, r);
	int d = __lg(r - l + 1);
	return gethigh(T[l][d], T[l + (1 << d) - 1][d]);
}

void dfs(int u, int p = -1) {
	tin[u] = ++timer;
	T[timer][0] = u;
	for (int v : adj[u]) if (v != p) {
		h[v] = h[u] + 1;
		dfs(v, u);
		T[++timer][0] = u;
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	#ifdef ONLINE_JUDGE
	// freopen(TASK".inp","r",stdin);
	// freopen(TASK".out","w",stdout);
	#endif
	cin >> n >> m >> q;
	for (int i = 1; i < n; i++) {
		int u,v;
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	dfs(1);

	for (int j = 1; j < 20; j++)
	for (int i = 1; i + (1 << j) - 1 <= timer; i++) 
		T[i][j] = gethigh(T[i][j - 1], T[i + (1 << (j - 1))][j - 1]);

	for (int i = 1; i <= m; i++) {
		cin >> a[i];
		if (i > 1)
			pos[getlca(a[i - 1], a[i])].insert(i - 1);
		ind[a[i]].insert(i);
	}

	while (q--) {
		int op; cin >> op;
		if (op == 1) {
			int i,v;
			cin >> i >> v;
			if (i > 1) {
				pos[getlca(a[i - 1], a[i])].erase(i - 1);
				pos[getlca(a[i - 1], v)].insert(i - 1);
			}
			if (i < m) {
				pos[getlca(a[i], a[i + 1])].erase(i);
				pos[getlca(v, a[i + 1])].insert(i);
			}

			ind[a[i]].erase(i);
			a[i] = v;	
			ind[a[i]].insert(i);
		} else {
			int l, r, v;
			cin >> l >> r >> v;
			auto it = pos[v].lower_bound(l);
			if (it == pos[v].end() || (*it) + 1 > r) {
				it = ind[v].lower_bound(l);
				if (it == ind[v].end() || (*it) > r) 
					cout << "-1 -1\n";
				else
					cout << (*it) << " " << (*it) << "\n";
			} else
				cout << (*it) << " " << (*it) + 1 << "\n";
		}
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB n=5
2 Incorrect 12 ms 23764 KB Jury has the answer but participant has not
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB n=5
2 Incorrect 12 ms 23764 KB Jury has the answer but participant has not
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB n=5
2 Incorrect 12 ms 23764 KB Jury has the answer but participant has not
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB n=5
2 Incorrect 12 ms 23764 KB Jury has the answer but participant has not
3 Halted 0 ms 0 KB -