Submission #697878

# Submission time Handle Problem Language Result Execution time Memory
697878 2023-02-11T09:21:38 Z vjudge1 Birthday gift (IZhO18_treearray) C++17
0 / 100
11 ms 21512 KB
//#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 <bits/stdc++.h>
 
#define file ""
 
#define all(x) x.begin(), x.end()
 
#define fr first
#define sc second
 
#define pb push_back
                                                         
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
const int N = 3e5;
const int inf = 1e9 + 5;

map <int, pii> mp;
int a[N], tin[N], tout[N], t[4 * N], timer = 1;
int up[N][25];
vector <int> g[N];
multiset <int> s [N];


void dfs (int x, int pr) {
	tin[x] = timer++;
	up[x][0] = pr;
	for (int i = 1; i <= 20; i++) {
		up[x][i] = up[up[x][i - 1]][i - 1];
	}
	for (int to : g[x]) {
		if (to != pr) dfs(to, x);
	}
	tout[x] = timer;
}

bool upper (int x, int y) {
	if (tin[x] <= tin[y] && tout[x] >= tout[y]) return true;
	return false;
}

int lca (int x, int y) {
	if (x == 0) return y;
	if (y == 0) return x;
	if (upper(x, y)) return x;
	if (upper(y, x)) return y;
	for (int i = 20; i >= 0; i--) {
		if (!upper(up[x][i], y)) x = up[x][i];
	}
	return up[x][0];
}



int main(){



	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);
	srand(time(NULL));
	int n, m, q;
	cin >> n >> m >> q;
	int u, v, tp;
	for  (int i = 1; i < n; i++) {
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	dfs(1, 1);
	for (int i = 1; i <= m; i++) {
		cin >> a[i];
		s[a[i]].insert(i);
		
	}
	a[0] = a[1];
	for (int i = 1; i < m; i++) {
		s[lca(a[i], a[i + 1])].insert(i);
	}
	while (q--) {
		cin >> tp;
		if (tp == 1) {
			int pos, val;
			cin >> pos >> val;
			if (pos > 1 && pos < m) {
				s[a[pos]].erase(pos);
				s[lca(a[pos], a[pos + 1])].erase(pos);
				s[lca(a[pos], a[pos - 1])].erase(pos - 1);
				a[pos] = val;
				s[a[pos]].insert(pos);
				s[lca(a[pos], a[pos + 1])].insert(pos);
				s[lca(a[pos], a[pos - 1])].insert(pos - 1);
			}
			else if (pos == 1) {
				s[a[pos]].erase(pos);
				s[lca(a[pos], a[pos + 1])].erase(pos);
  	    a[pos] = val;
  	    s[a[pos]].insert(pos);
				s[lca(a[pos], a[pos + 1])].insert(pos);
			
			}
			else {
				s[a[pos]].erase(pos);
				s[lca(a[pos], a[pos - 1])].erase(pos - 1);
    	  a[pos] = val;
    	  s[a[pos]].insert(pos);
				s[lca(a[pos], a[pos - 1])].insert(pos - 1);
				
			}
			
		} 
		else {
			int l, r, val;
			cin >> l >> r >> val;
			auto it = s[val].lower_bound(l);
			if (*it != m + 1) {
				int ans = *it;
				if (a[ans] == val && ans >= l && ans <= r) cout << ans << " " << ans;
				else if (ans >= l && ans + 1 <= r) cout << ans << " " << ans + 1;
				else cout << -1 << " " << -1;
				cout << "\n";
			}
			else cout << -1 << " " << -1 << "\n";
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 21460 KB n=5
2 Correct 11 ms 21460 KB n=100
3 Correct 11 ms 21460 KB n=100
4 Correct 11 ms 21460 KB n=100
5 Incorrect 11 ms 21512 KB Jury has the answer but participant has not
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 21460 KB n=5
2 Correct 11 ms 21460 KB n=100
3 Correct 11 ms 21460 KB n=100
4 Correct 11 ms 21460 KB n=100
5 Incorrect 11 ms 21512 KB Jury has the answer but participant has not
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 21460 KB n=5
2 Correct 11 ms 21460 KB n=100
3 Correct 11 ms 21460 KB n=100
4 Correct 11 ms 21460 KB n=100
5 Incorrect 11 ms 21512 KB Jury has the answer but participant has not
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 21460 KB n=5
2 Correct 11 ms 21460 KB n=100
3 Correct 11 ms 21460 KB n=100
4 Correct 11 ms 21460 KB n=100
5 Incorrect 11 ms 21512 KB Jury has the answer but participant has not
6 Halted 0 ms 0 KB -