Submission #320333

#TimeUsernameProblemLanguageResultExecution timeMemory
320333spike1236Birthday gift (IZhO18_treearray)C++14
56 / 100
1223 ms88932 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define f first #define s second #define sz size() #define ll long long #define ld long double #define all(_v) _v.begin(), _v.end() #define pii pair <int, int> #define pll pair <ll, ll> #define veci vector <int> #define vecll vector <ll> const int dx[4] = {1, -1, 0, 0}; const int dy[4] = {0, 0, -1, 1}; const double PI = 3.1415926535897932384626433832795; const double eps = 1e-9; const int MOD1 = 1e9 + 7; const int MOD2 = 998244353; const int MAXN = 2e5 + 10; int n, m, q; int tin[MAXN], tout[MAXN]; int up[MAXN][25]; vector <int> g[MAXN]; set <int> st[MAXN], poses[MAXN]; int a[MAXN]; int tmr; void dfs(int v = 1, int p = 0) { tin[v] = ++tmr; up[v][0] = p; for(int i = 1; i <= 21; ++i) if(up[v][i - 1]) up[v][i] = up[up[v][i - 1]][i - 1]; for(auto to : g[v]) if(to != p) dfs(to, v); tout[v] = ++tmr; } bool upper(int v, int u) { return (tin[v] <= tin[u] && tout[v] >= tout[u]); } int lca(int a, int b) { if(upper(a, b)) return a; if(upper(b, a)) return b; for(int i = 21; i >= 0; --i) if(up[a][i] && !upper(up[a][i], b)) a = up[a][i]; return up[a][0]; } void solve() { cin >> n >> m >> q; for(int i = 1; i < n; ++i) { int u, v; cin >> u >> v; g[u].pb(v); g[v].pb(u); } dfs(); for(int i = 1; i <= m; ++i) cin >> a[i], poses[a[i]].insert(i); for(int i = 1; i < m; ++i) st[lca(a[i], a[i + 1])].insert(i); for(int i = 1; i <= q; ++i) { int type; cin >> type; if(type == 1) { int pos, v; cin >> pos >> v; poses[a[pos]].erase(pos); poses[v].insert(pos); if(pos > 1) st[lca(a[pos], a[pos - 1])].erase(pos - 1), st[lca(v, a[pos - 1])].insert(pos - 1); if(pos < n) st[lca(a[pos], a[pos + 1])].erase(pos), st[lca(v, a[pos + 1])].insert(pos); a[pos] = v; } else { int l, r, v; cin >> l >> r >> v; if(!poses[v].empty()) { auto it = poses[v].lower_bound(l); if(it != poses[v].end()) { int k = *it; if(k <= r) { cout << k << ' ' << k << '\n'; continue; } } } if(!st[v].empty()) { auto it = st[v].lower_bound(l); if(it != st[v].end()) { if(*it < r) { cout << *it << ' ' << *it + 1 << '\n'; continue; } } } cout << "-1 -1\n"; } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T = 1; ///cin >> T; while(T--) solve(), cout << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...