Submission #380862

#TimeUsernameProblemLanguageResultExecution timeMemory
3808622qbingxuanBirthday gift (IZhO18_treearray)C++14
56 / 100
4057 ms66136 KiB
#include <bits/stdc++.h> #ifdef local #define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n" #define debug(a...) qqbx(#a, a) #define pary(a...) danb(#a, a) template <typename ...T> void qqbx(const char *s, T ...a) { int cnt = sizeof...(T); ((std::cerr << "\033[1;32m(" << s << ") = (") , ... , (std::cerr << a << (--cnt ? ", " : ")\033[0m\n"))); } template <typename T> void danb(const char *s, T L, T R) { std::cerr << "\033[1;32m[ " << s << " ] = [ "; for (auto it = L; it != R; ++it) std::cerr << *it << ' '; std::cerr << "]\033[0m\n"; } #else #define safe ((void)0) #define debug(...) ((void)0) #define pary(...) ((void)0) #endif // local #define all(v) begin(v),end(v) #define pb emplace_back #define sort_uni(v) sort(all(v)),v.erase(unique(all(v)), v.end()) #define get_pos(u,v) int(lower_bound(all(u), v) - u.begin()) using namespace std; using ll = int64_t; template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>; template <typename T> using max_heap = priority_queue<T, vector<T>, less<T>>; const int maxn = 300025, inf = 1e9, MOD = 1000000007; const ll INF = 1e18; vector<int> g[maxn]; int dep[maxn], pa[maxn], jump[maxn]; void dfs(int i, int p) { dep[i] = dep[p] + 1; pa[i] = p; if (dep[jump[jump[p]]] - dep[jump[p]] == dep[p] - dep[jump[p]]) jump[i] = jump[jump[p]]; else jump[i] = p; for (int j: g[i]) { if (j != p) { dfs(j, i); } } } int lca(int a, int b) { if (dep[a] < dep[b]) swap(a, b); while (dep[a] != dep[b]) { if (dep[jump[a]] >= dep[b]) { a = jump[a]; } else { a = pa[a]; } } while (a != b) { if (jump[a] == jump[b]) { a = jump[a]; b = jump[b]; } else { a = pa[a]; b = pa[b]; } } return a; } set<int> seg[2][maxn]; pair<int,int> query(int x, int l, int r) { // [l, r] if (auto it = seg[0][x].lower_bound(l); it != seg[0][x].end() && *it <= r) { return {*it, *it}; } if (auto it = seg[1][x].lower_bound(l); it != seg[1][x].end() && *it < r) { return {*it, *it+1}; } return {-1, -1}; } int v[maxn]; signed main() { ios_base::sync_with_stdio(0), cin.tie(0); int n, m, q; cin >> n >> m >> q; for (int i = 1; i < n; i++) { int a, b; cin >> a >> b; g[a].emplace_back(b); g[b].emplace_back(a); } for (int i = 1; i <= n; i++) jump[i] = 1; dfs(1, 0); dep[0] = -1; for (int i = 1; i <= m; i++) cin >> v[i]; for (int i = 1; i <= m; i++) seg[0][v[i]].insert(i); for (int i = 1; i < m; i++) seg[1][lca(v[i], v[i+1])].insert(i); safe; while (q--) { int t; cin >> t; if (t == 1) { int i, x; cin >> i >> x; seg[0][v[i]].erase(i); if (i < m) seg[1][lca(v[i], v[i+1])].erase(i); if (i > 1) seg[1][lca(v[i], v[i-1])].erase(i-1); v[i] = x; seg[0][v[i]].insert(i); if (i < m) seg[1][lca(v[i], v[i+1])].insert(i); if (i > 1) seg[1][lca(v[i], v[i-1])].insert(i-1); } else if (t == 2) { int l, r, x; cin >> l >> r >> x; auto [a, b] = query(x, l, r); cout << a << ' ' << b << '\n'; } } } /* 5 4 4 1 2 3 1 3 4 5 3 4 5 2 3 2 1 3 1 1 3 5 2 3 4 5 2 1 3 1 */

Compilation message (stderr)

treearray.cpp: In function 'std::pair<int, int> query(int, int, int)':
treearray.cpp:71:9: warning: init-statement in selection statements only available with '-std=c++17' or '-std=gnu++17'
   71 |     if (auto it = seg[0][x].lower_bound(l); it != seg[0][x].end() && *it <= r) {
      |         ^~~~
treearray.cpp:75:9: warning: init-statement in selection statements only available with '-std=c++17' or '-std=gnu++17'
   75 |     if (auto it = seg[1][x].lower_bound(l); it != seg[1][x].end() && *it < r) {
      |         ^~~~
treearray.cpp: In function 'int main()':
treearray.cpp:122:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  122 |             auto [a, b] = query(x, l, r);
      |                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...