제출 #441920

#제출 시각아이디문제언어결과실행 시간메모리
441920parsabahramiBirthday gift (IZhO18_treearray)C++17
56 / 100
581 ms89664 KiB
/* I do it for the glory */ #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> pii; #define SZ(x) (int) x.size() #define F first #define S second const int N = 2e5 + 10, MOD = 1e9 + 7, SQ = 400; int H[N], P[19][N], A[N], B[N], n, m, q; vector<int> adj[N]; multiset<int> M[SQ], M2[SQ]; void preDFS(int v, int p = -1) { if (!~p) P[0][v] = v; for (int i = 1; i < 19; i++) P[i][v] = P[i - 1][P[i - 1][v]]; for (int &u : adj[v]) if (u != p) H[u] = H[v] + 1, P[0][u] = v, preDFS(u, v); } int LCA(int u, int v) { if (H[u] < H[v]) swap(u, v); for (int i = H[u] - H[v]; i; i -= i & -i) u = P[__builtin_ctz(i)][u]; for (int i = 18; ~i; i--) if (P[i][u] != P[i][v]) u = P[i][u], v = P[i][v]; return u == v ? v : P[0][v]; } void upd(int id, int v) { M2[id / SQ].erase(M2[id / SQ].find(A[id])); A[id] = v; M2[id / SQ].insert(A[id]); if (id) { M[(id - 1) / SQ].erase(M[(id - 1) / SQ].find(B[id - 1])); B[id - 1] = LCA(A[id], A[id - 1]); M[(id - 1) / SQ].insert(B[id - 1]); } if (id + 1 < m) { M[id / SQ].erase(M[id / SQ].find(B[id])); B[id] = LCA(A[id], A[id + 1]); M[id / SQ].insert(B[id]); } } int main() { scanf("%d%d%d", &n, &m, &q); for (int i = 1; i < n; i++) { int u, v; scanf("%d%d", &u, &v); adj[u].push_back(v), adj[v].push_back(u); } preDFS(1); for (int i = 0; i < m; i++) { scanf("%d", &A[i]); M2[i / SQ].insert(A[i]); if (i) B[i - 1] = LCA(A[i - 1], A[i]), M[(i - 1) / SQ].insert(B[i - 1]); } for (; q; q--) { int t; scanf("%d", &t); if (t < 2) { int p, v; scanf("%d%d", &p, &v); upd(p - 1, v); } else { int l, r, v; scanf("%d%d%d", &l, &r, &v); pii ret = {-1, -1}; int f = 0; l--, r--; r--; for (int i = l; i <= r && !f; ) { if (i % SQ == 0 && i + SQ - 1 <= r) { if (M[i / SQ].count(v)) { for (int j = i; j < i + SQ && !f; j++) if (B[j] == v) { f = 1, ret = {j + 1, j + 2}; } } else i += SQ; } else { if (B[i] == v) { f = 1, ret = {i + 1, i + 2}; } else i++; } } for (int i = l; i <= r + 1 && !f; ) { if (i % SQ == 0 && i + SQ <= r) { if (M2[i / SQ].count(v)) { for (int j = i; j < i + SQ && !f; j++) if (A[j] == v) { f = 1; ret = {j + 1, j + 1}; } } else i += SQ; } else { if (A[i] == v) { f = 1, ret = {i + 1, i + 1}; } else i++; } } printf("%d %d\n", ret.F, ret.S); } } return 0; }

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

treearray.cpp: In function 'int main()':
treearray.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |     scanf("%d%d%d", &n, &m, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
treearray.cpp:55:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |         int u, v; scanf("%d%d", &u, &v);
      |                   ~~~~~^~~~~~~~~~~~~~~~
treearray.cpp:60:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         scanf("%d", &A[i]); M2[i / SQ].insert(A[i]);
      |         ~~~~~^~~~~~~~~~~~~
treearray.cpp:64:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         int t; scanf("%d", &t);
      |                ~~~~~^~~~~~~~~~
treearray.cpp:66:28: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |             int p, v; scanf("%d%d", &p, &v);
      |                       ~~~~~^~~~~~~~~~~~~~~~
treearray.cpp:69:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |             int l, r, v; scanf("%d%d%d", &l, &r, &v);
      |                          ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...