제출 #380835

#제출 시각아이디문제언어결과실행 시간메모리
3808352qbingxuanBirthday gift (IZhO18_treearray)C++14
0 / 100
26 ms35692 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 pa[20][maxn], dep[maxn]; void dfs(int i, int p) { for (int j: g[i]) { if (j != p) { dep[j] = dep[i] + 1; pa[0][j] = i; for (int L = 1; L < 20; L++) pa[L][i] = pa[L-1][pa[L-1][i]]; dfs(j, i); } } } int lca(int a, int b) { if (dep[a] < dep[b]) swap(a, b); int dif = dep[a] - dep[b]; for (int i = 19; i >= 0; i--) if (dif >> i & 1) a = pa[i][a]; if (a == b) return a; for (int i = 19; i >= 0; i--) if (pa[i][a] != pa[i][b]) a = pa[i][a], b = pa[i][b]; return pa[0][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); } dfs(1, 0); 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; pair<int,int> ans(-1, -1); for (int j = l; j <= r; j++) if (v[j] == x) ans = {j, j}; for (int j = l; j < r; j++) if (lca(v[j], v[j+1]) == x) ans = {j, j+1}; cout << ans.first << ' ' << ans.second << '\n'; // 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 */

컴파일 시 표준 에러 (stderr) 메시지

treearray.cpp: In function 'std::pair<int, int> query(int, int, int)':
treearray.cpp:57:9: warning: init-statement in selection statements only available with '-std=c++17' or '-std=gnu++17'
   57 |     if (auto it = seg[0][x].lower_bound(l); it != seg[0][x].end() && *it <= r) {
      |         ^~~~
treearray.cpp:61:9: warning: init-statement in selection statements only available with '-std=c++17' or '-std=gnu++17'
   61 |     if (auto it = seg[1][x].lower_bound(l); it != seg[1][x].end() && *it < 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...