Submission #1094409

#TimeUsernameProblemLanguageResultExecution timeMemory
1094409cpptowinBirthday gift (IZhO18_treearray)C++17
100 / 100
681 ms122448 KiB
#include <bits/stdc++.h> #define fo(i, d, c) for (int i = d; i <= c; i++) #define fod(i, c, d) for (int i = c; i >= d; i--) #define maxn 500010 #define N 1010 #define fi first #define se second #define pb emplace_back #define en cout << "\n"; #define inf (int)1e18 #define bitcount(x) __builtin_popcountll(x) #define pii pair<int, int> #define vii vector<pii> #define lb(x) x & -x #define bit(i, j) ((i >> j) & 1) #define offbit(i, j) (i ^ (1LL << j)) #define onbit(i, j) (i | (1LL << j)) #define vi vector<int> #define all(x) x.begin(), x.end() #define ss(x) (int)x.size() template <typename T1, typename T2> bool minimize(T1 &a, T2 b) { if (a > b) { a = b; return true; } return false; } template <typename T1, typename T2> bool maximize(T1 &a, T2 b) { if (a < b) { a = b; return true; } return false; } using namespace std; const int nsqrt = 450; const int mod = 1e9 + 7; void add(int &x, int k) { x += k; x %= mod; if(x < 0) x += mod; } void del(int &x, int k) { x -= k; x %= mod; if(x < 0) x += mod; } int n,m,q,a[maxn],h[maxn],par[maxn][20]; vi ke[maxn]; set<int> s1[maxn],s[maxn]; void dfs(int u) { for(int v : ke[u]) if(v != par[u][0]) { h[v] = h[u] + 1; par[v][0] = u; fo(i,1,19) par[v][i] = par[par[v][i - 1]][i - 1]; dfs(v); } } int lca(int u, int v) { if (h[u] < h[v]) swap(u, v); int del = h[u] - h[v]; fod(i, 19, 0) if (bit(del, i)) u = par[u][i]; if (u == v) return u; fod(i, 19, 0) if (par[u][i] != par[v][i]) u = par[u][i], v = par[v][i]; return par[u][0]; } main() { #define name "bai1" if (fopen(name ".inp", "r")) { freopen(name ".inp", "r", stdin); freopen(name ".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m >> q; fo(i,1,n - 1) { int u,v; cin >> u >> v; ke[u].pb(v); ke[v].pb(u); } dfs(1); fo(i,1,m) { cin >> a[i]; s[a[i]].insert(i); } fo(i,1,m - 1) s1[lca(a[i],a[i + 1])].insert(i); while(q--) { int t; cin >> t; if(t == 1) { int i,u; cin >> i >> u; s[a[i]].erase(i); if(i < m) s1[lca(a[i],a[i + 1])].erase(i); if(i > 1) s1[lca(a[i - 1],a[i])].erase(i - 1); a[i] = u; s[a[i]].insert(i); s1[lca(a[i],a[i + 1])].insert(i); if(i > 1) s1[lca(a[i - 1],a[i])].insert(i - 1); } else { int l,r,u; cin >> l >> r >> u; auto it = s[u].lower_bound(l); pii ans = {-1,-1}; if(it != s[u].end() and *it <= r) ans = {*it,*it}; else { it = s1[u].lower_bound(l); if(it != s1[u].end() and *it < r) ans = {*it,*it + 1}; } cout << ans.fi << ' ' << ans.se << "\n"; } } }

Compilation message (stderr)

treearray.cpp:80:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   80 | main()
      | ^~~~
treearray.cpp: In function 'int main()':
treearray.cpp:85:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |         freopen(name ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
treearray.cpp:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |         freopen(name ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...