Submission #344972

#TimeUsernameProblemLanguageResultExecution timeMemory
344972Valera_GrinenkoBirthday gift (IZhO18_treearray)C++17
100 / 100
1343 ms92712 KiB
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization ("unroll-loops") #include <iostream> #include <fstream> #include <algorithm> #include <vector> #include <set> #include <stack> #include <map> #include <unordered_map> #include <iomanip> #include <cmath> #include <queue> #include <bitset> #include <numeric> #include <array> #include <cstring> #include <random> #include <chrono> #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin()) typedef long long ll; typedef long double ld; using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // template<class T> // using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; const int N = 2e5 + 42, L = 20; vector<int> g[N]; int a[N]; set<int> haveone[N], havelca[N]; vector<int> tin, tout; vector<vector<int> > up; int n, m, q, l; int timer = 0; void dfs(int v, int p = 0) { tin[v] = ++timer; up[v][0] = p; for(int i = 1; i <= l; i++) up[v][i] = up[up[v][i - 1]][i - 1]; for(auto& x : g[v]) if(x != p) dfs(x, v); tout[v] = ++timer; } bool upper(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; } int lca(int a, int b) { if(upper(a, b)) return a; if(upper(b, a)) return b; for(int i = l; i >= 0; i--) if(!upper(up[a][i], b)) a = up[a][i]; return up[a][0]; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> q; tin.resize(n); tout.resize(n); up.resize(n); l = 1; while((1 << l) <= n) l++; for(int i = 0; i < n; i++) up[i].resize(l + 1); for(int i = 1; i < n; i++) { int u, v; cin >> u >> v; g[--u].pb(--v); g[v].pb(u); } dfs(0); vector<int> a(m); for(int i = 0; i < m; i++) { cin >> a[i]; a[i]--; haveone[a[i]].insert(i); if(i) { havelca[lca(a[i], a[i - 1])].insert(i - 1); } } while(q--) { int type; cin >> type; if(type == 1) { int pos, v; cin >> pos >> v; pos--; v--; haveone[a[pos]].erase(pos); if(pos > 0) havelca[lca(a[pos], a[pos - 1])].erase(pos - 1); if(pos + 1 < m) havelca[lca(a[pos], a[pos + 1])].erase(pos); a[pos] = v; haveone[a[pos]].insert(pos); if(pos > 0) havelca[lca(a[pos], a[pos - 1])].insert(pos - 1); if(pos + 1 < m) havelca[lca(a[pos], a[pos + 1])].insert(pos); } else { int l, r, v; cin >> l >> r >> v; l--; r--; v--; auto it = haveone[v].lower_bound(l); if(it != haveone[v].end()) { int cur = *it; if(cur <= r) { cout << cur + 1 << ' ' << cur + 1 << '\n'; continue; } } it = havelca[v].lower_bound(l); if(it != havelca[v].end()) { int cur = *it; if(cur + 1 <= r) { cout << cur + 1 << ' ' << cur + 2 << '\n'; continue; } } cout << "-1 -1\n"; } } return 0; } /* */

Compilation message (stderr)

treearray.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      |
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...