Submission #572147

# Submission time Handle Problem Language Result Execution time Memory
572147 2022-06-03T19:01:17 Z vovamr Birthday gift (IZhO18_treearray) C++17
0 / 100
12 ms 23824 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fi first
#define se second
#define ll long long
#define ld long double
#define sz(x) ((int)(x).size())
#define all(x) 	(x).begin(), (x).end()
#define pb push_back
#define mpp make_pair
#define ve vector
using namespace std;
using namespace __gnu_pbds;
template<class T> using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll inf = 1e18; const int iinf = 1e9;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> inline bool chmin(T& a, T b) { return (a > b ? a = b, 1 : 0); }
template <typename T> inline bool chmax(T& a, T b) { return (a < b ? a = b, 1 : 0); }

const int N = 2e5 + 100;
ve<int> gr[N];
const int lg = 19;
int in[N], out[N], up[N][lg];
int tim = 0;

inline void dfs(int v, int p) {
	up[v][0] = p;
	in[v] = ++tim;
	for (auto &to : gr[v]) {
		if (to == p) continue;
		dfs(to, v);
	} out[v] = ++tim;
}
inline bool anc(int a, int b) { return in[a] <= in[b] && out[b] <= out[a]; }
inline int lca(int a, int b) {
	if (anc(a, b)) return a;
	if (anc(b, a)) return b;
	for (int i = lg - 1; ~i; --i) {
		if (!anc(up[a][i], b)) {
			a = up[a][i];
		}
	} return up[a][0];
}

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

inline void solve() {
	int n, m, q;
	cin >> n >> m >> q;
	for (int i = 1; i < n; ++i) {
		int v, u;
		cin >> v >> u, --v, --u;
		gr[v].pb(u), gr[u].pb(v);
	} dfs(0, 0);
	for (int i = 1; i < lg; ++i) {
		for (int v = 0; v < n; ++v) {
			up[v][i] = up[up[v][i - 1]][i - 1];
		}
	}

	ve<int> a(m);
	for (auto &i : a) cin >> i, --i;
	for (int i = 0; i < m; ++i) s1[a[i]].insert(i);
	for (int i = 1; i < m; ++i) s2[lca(a[i], a[i - 1])].insert(i);

	while (q--) {
		int e;
		cin >> e;
		if (e == 1) {
			int pos, x;
			cin >> pos >> x, --pos, --x;

			s1[a[pos]].erase(pos);
			if (pos) s2[lca(a[pos], a[pos - 1])].erase(pos);
			if (pos + 1 < m) s1[lca(a[pos], a[pos + 1])].erase(pos + 1);

			a[pos] = x;

			s1[a[pos]].insert(pos);
			if (pos) s2[lca(a[pos], a[pos - 1])].insert(pos);
			if (pos + 1 < m) s1[lca(a[pos], a[pos + 1])].insert(pos + 1);
		}
		else {
			int l, r, v;
			cin >> l >> r >> v, --l, --r, --v;

			auto it = s1[v].lower_bound(l);
			if (it != s1[v].end() && *it <= r) cout << *it + 1 << " " << *it + 1 << '\n';
			else {
				it = s2[v].lower_bound(l + 1);
				if (it != s2[v].end() && *it <= r) cout << *it << " " << *it + 1 << '\n';
				else cout << "-1 -1" << '\n';
			}
		}
	}
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int q = 1; // cin >> q;
	while (q--) solve();
	cerr << fixed << setprecision(3) << "Time execution: " << (double)clock() / CLOCKS_PER_SEC << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23764 KB n=5
2 Incorrect 12 ms 23824 KB Wrong range.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23764 KB n=5
2 Incorrect 12 ms 23824 KB Wrong range.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23764 KB n=5
2 Incorrect 12 ms 23824 KB Wrong range.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23764 KB n=5
2 Incorrect 12 ms 23824 KB Wrong range.
3 Halted 0 ms 0 KB -