Submission #545398

#TimeUsernameProblemLanguageResultExecution timeMemory
545398shmadBirthday gift (IZhO18_treearray)C++17
0 / 100
14 ms23892 KiB
#pragma GCC optimize("O3", "unroll-loops") // "Ofast" #pragma GCC target("avx2", "bmi", "bmi2", "lzcnt", "popcnt") #include <bits/stdc++.h> #define int long long #define vt vector #define pb push_back #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() #define ff first #define ss second #define dbg(x) cerr << #x << " = " << x << '\n' #define nl '\n' using namespace std; using ll = long long; using pii = pair<int, int>; using vvt = vt< vt<int> >; const int N = 2e5 + 5, mod = 1e9 + 7, inf = 1e18 + 7, W = 500, LIM = (1ll << 60); const double eps = 1e-6; int n, m, q, up[N][21], tin[N], tout[N], timer; vt<int> g[N]; void dfs (int v, int p = 1) { tin[v] = timer++; up[v][0] = p; for (int i = 1; i <= 20; i++) { int jump = up[v][i - 1]; up[v][i] = up[jump][i - 1]; } for (auto to: g[v]) { if (to != p) dfs(to, v); } tout[v] = timer++; } bool is_parent (int a, int b) { return (tin[a] <= tin[b] && tout[a] >= tout[b]); } int lca (int a, int b) { if (is_parent(a, b)) return a; if (is_parent(b, a)) return b; for (int i = 20; i >= 0; i--) { if (!is_parent(up[a][i], b)) a = up[a][i]; } return up[a][0]; } int a[N]; set<int> s[N], st[N]; void upd (int i, int x) { st[a[i]].erase(i); if (i + 1 <= m) { int lc = lca(a[i], a[i + 1]); s[lc].erase(i); } if (i - 1 >= 1) { int lc = lca(a[i], a[i - 1]); s[lc].erase(i - 1); } a[i] = x; st[a[i]].insert(i); if (i + 1 <= m) { int lc = lca(a[i], a[i + 1]); s[lc].insert(i); } if (i - 1 >= 1) { int lc = lca(a[i], a[i - 1]); s[lc].insert(i - 1); } } pii get (int l, int r, int v) { auto it = s[v].lower_bound(l); if (it != s[v].end()) { int x = *it; if (x + 1 <= r) return {x, x + 1}; } it = st[v].lower_bound(l); if (it != st[v].end()) { int x = *it; if (x <= r) return {x, x}; } return {-1, -1}; } void solve () { cin >> n >> m >> q; for (int i = 1; i < n; i++) { int x, y; cin >> x >> y; g[x].pb(y); g[y].pb(x); } dfs(1); for (int i = 1; i <= m; i++) cin >> a[i], st[a[i]].insert(i); for (int i = 1; i < m; i++) s[lca(a[i], a[i + 1])].insert(i); while (q--) { int tp; cin >> tp; if (tp == 1) { int pos, x; cin >> pos >> x; upd(pos, x); } if (tp == 2) { int l, r, v; cin >> l >> r >> v; pii ans = get(l, r, v); cout << ans.ff << ' ' << ans.ss << '\n'; } } cout << '\n'; } bool testcases = 0; signed main() { #ifndef ONLINE_JUDGE freopen(".in", "r", stdin); freopen(".out", "w", stdout); #endif cin.tie(0) -> sync_with_stdio(0); int test = 1; if (testcases) cin >> test; for (int cs = 1; cs <= test; cs++) { solve(); } }

Compilation message (stderr)

treearray.cpp: In function 'int main()':
treearray.cpp:125:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  125 |  freopen(".in", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~
treearray.cpp:126:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  126 |  freopen(".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...