Submission #495756

#TimeUsernameProblemLanguageResultExecution timeMemory
495756mansurBirthday gift (IZhO18_treearray)C++14
30 / 100
4053 ms24152 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); } int a[m + 1]; for (int i = 1; i <= m; i++) { cin >> a[i]; } dfs(1, 1); while (q--) { int t; cin >> t; if (t == 1) { int pos, v; cin >> pos >> v; a[pos] = v; }else { int l, r, v; cin >> l >> r >> v; bool ok = 0; for (int x = l; x <= r && !ok; x++) { int lc = a[x]; for (int y = x; y <= r; y++) { lc = lca(lc, a[y]); if (lc == v) { cout << x << ' ' << y << nl; ok = 1; break; } } } if (!ok) cout << -1 << ' ' << -1 << 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...