제출 #760344

#제출 시각아이디문제언어결과실행 시간메모리
760344NK_Birthday gift (IZhO18_treearray)C++17
100 / 100
735 ms75716 KiB
// Success consists of going from failure to failure without loss of enthusiasm #include <bits/stdc++.h> using namespace std; #define nl '\n' #define pb push_back #define f first #define s second #define mp make_pair using pi = pair<int, int>; const int nax = 2e5+5; const int LG = 18; template<class T> using V = vector<T>; int up[nax][LG]; int dep[nax]; int jmp(int u, int d) { for(int i = 0; i < LG; i++) if ((d >> i) & 1) { u = up[u][i]; } return u; } int lca(int a, int b) { if (dep[a] < dep[b]) swap(a, b); a = jmp(a, dep[a] - dep[b]); if (a == b) return a; for(int i = LG - 1; i >= 0; i--) { if (up[a][i] != up[b][i]) a = up[a][i], b = up[b][i]; } return up[a][0]; } int main() { cin.tie(0)->sync_with_stdio(0); int N, M, Q; scanf("%d %d %d", &N, &M, &Q); V<V<int>> adj(N); for(int _ = 0; _ < N-1; _++) { int u, v; scanf("%d %d", &u, &v); --u, --v; adj[u].pb(v); adj[v].pb(u); } function<void(int, int)> dfs = [&](int u, int p) { up[u][0] = p; for(int i = 1; i < LG; i++) up[u][i] = up[up[u][i-1]][i-1]; for(auto v : adj[u]) if (v != p) { dep[v] = dep[u] + 1; dfs(v, u); } }; dep[0] = 0; dfs(0, 0); V<set<pi>> X(N); V<int> A(M), LCA(M-1); for(auto& x : A) { scanf("%d", &x); --x; } for(int i = 0; i < M; i++) { if (i+1 < M) X[(LCA[i] = lca(A[i], A[i+1]))].insert(mp(i, i+1)); X[A[i]].insert(mp(i, i)); } while(Q--) { int t; scanf("%d", &t); if (t == 1) { int i, x; scanf("%d %d", &i, &x); --i, --x; if (i-1 >= 0) X[LCA[i-1]].erase(mp(i-1, i)); if (i+1 < M) X[LCA[i]].erase(mp(i, i+1)); X[A[i]].erase(mp(i, i)); A[i] = x; X[A[i]].insert(mp(i, i)); if (i-1 >= 0) X[(LCA[i-1] = lca(A[i-1], A[i]))].insert(mp(i-1, i)); if (i+1 < M) X[(LCA[i] = lca(A[i], A[i+1]))].insert(mp(i, i+1)); } else { int l, r, x; scanf("%d %d %d", &l, &r, &x); --l, --r, --x; // --r; // BECAUSE NEED TO FIND i SUCH THAT l ≤ i < r // for(auto v : X[x]) cout << "(" << v.f << ", " << v.s << ")" << nl; // cout << nl; auto it = X[x].lower_bound(mp(l, -1)); if (it == end(X[x])) printf("-1 -1\n"); else { int L, R; tie(L, R) = *it; if (R > r) L = R = -1; else ++L, ++R; printf("%d %d\n", L, R); } } } return 0; }

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

treearray.cpp: In function 'int main()':
treearray.cpp:46:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |  int N, M, Q; scanf("%d %d %d", &N, &M, &Q);
      |               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
treearray.cpp:50:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |   int u, v; scanf("%d %d", &u, &v); --u, --v;
      |             ~~~~~^~~~~~~~~~~~~~~~~
treearray.cpp:67:49: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |  V<int> A(M), LCA(M-1); for(auto& x : A) { scanf("%d", &x); --x; }
      |                                            ~~~~~^~~~~~~~~~
treearray.cpp:75:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |   int t; scanf("%d", &t);
      |          ~~~~~^~~~~~~~~~
treearray.cpp:77:19: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |    int i, x; scanf("%d %d", &i, &x); --i, --x;
      |              ~~~~~^~~~~~~~~~~~~~~~~
treearray.cpp:88:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |    int l, r, x; scanf("%d %d %d", &l, &r, &x); --l, --r, --x;
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...