Submission #495986

#TimeUsernameProblemLanguageResultExecution timeMemory
495986mansurBirthday gift (IZhO18_treearray)C++14
0 / 100
13 ms23820 KiB
#include<bits/stdc++.h> #pragma optimize ("g",on) #pragma GCC optimize ("inline") #pragma GCC optimize ("Ofast") #pragma GCC optimize ("unroll-loops") #pragma GCC optimize ("03") #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native") #pragma comment(linker, "/stack:200000000") //01001101 01100001 01101011 01101000 01100001 01100111 01100001 01111001 using namespace std; #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define ll long long #define pb push_back #define sz(a) a.size() #define nl '\n' #define popb pop_back() #define ld double #define ull unsigned long long #define ff first #define ss second #define fix fixed << setprecision #define pii pair<int, int> #define E exit (0) const int inf = 1e9, N = 1e6 + 1, mod = 998244353; vector<pii> dir = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; int tin[N], tout[N], timer; int up[N][18]; vector<int> adj[N]; void dfs(int u, int p) { tin[u] = timer++; up[u][0] = p; for (int i = 1; i < 18; i++) up[u][i] = up[up[u][i - 1]][i - 1]; for (auto e: adj[u]) { if (e != p) dfs(e, u); } tout[u] = timer; } bool is(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; } int lca(int u, int v) { if (is(u, v)) return u; if (is(v, u)) return v; for (int i = 17; i >= 0; i--) { int x = up[u][i]; if (is(x, v)) continue; u = x; } return up[u][0]; } main() { //freopen("cowrect.in", "r", stdin); //freopen("cowrect.out", "w", stdout); ios_base::sync_with_stdio(NULL); cin.tie(NULL); int n, m, q; cin >> n >> m >> q; for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } dfs(1, 1); int a[m + 1]; vector<set<pii>> s(n + 1); for (int i = 1; i <= m; i++) { cin >> a[i]; s[a[i]].insert({i, i}); if (i > 1) { int lc = lca(a[i], a[i - 1]); s[lc].insert({i - 1, i}); } } while (q--) { int t; cin >> t; if (t == 1) { int pos, v; cin >> pos >> v; s[a[pos]].erase({pos, pos}); s[v].insert({pos, pos}); if (pos > 1) { int lc = lca(a[pos], a[pos - 1]); s[lc].erase({pos - 1, pos}); lc = lca(v, a[pos - 1]); s[lc].insert({pos - 1, pos}); } if (pos < m) { int lc = lca(a[pos], a[pos + 1]); s[lc].erase({pos, pos + 1}); lc = lca(v, a[pos + 1]); s[lc].insert({pos, pos + 1}); } a[pos] = v; }else { int l, r, v; cin >> l >> r >> v; auto it = s[v].lower_bound({l, l}); if (it == s[v].end()) cout << -1 << ' ' << -1 << nl; else cout << (*it).ff << ' ' << (*it).ss << nl; } } }

Compilation message (stderr)

treearray.cpp:3: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    3 | #pragma optimize ("g",on)
      | 
treearray.cpp:9: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
    9 | #pragma comment(linker, "/stack:200000000")
      | 
treearray.cpp:65:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   65 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...