Submission #380760

#TimeUsernameProblemLanguageResultExecution timeMemory
380760JerryLiu06Growing Trees (BOI11_grow)C++11
100 / 100
250 ms5228 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; #define pb push_back #define f first #define s second int N, M; vector<int> A; pii tree[400010]; void build(int x, int l, int r) { int mid = (l + r) / 2; if (l == r) { tree[x].f = A[l]; return ; } build(2 * x + 1, l, mid); build(2 * x + 2, mid + 1, r); tree[x].f = max(tree[2 * x + 1].f, tree[2 * x + 2].f); } void pushdown(int x, int l, int r) { int mid = (l + r) / 2; tree[x].f += tree[x].s; if (l < r) { tree[2 * x + 1].s += tree[x].s; tree[2 * x + 2].s += tree[x].s; } tree[x].s = 0; } void update(int x, int l, int r, int tl, int tr) { int mid = (l + r) / 2; if (r < tl || l > tr) return ; if (tl <= l && r <= tr) { tree[x].s++; return ; } pushdown(x, l, r); update(2 * x + 1, l, mid, tl, tr); update(2 * x + 2, mid + 1, r, tl, tr); pushdown(2 * x + 1, l, mid); pushdown(2 * x + 2, mid + 1, r); tree[x].f = max(tree[2 * x + 1].f, tree[2 * x + 2].f); } int queryMax(int x, int l, int r, int tl, int tr) { int mid = (l + r) / 2; pushdown(x, l, r); if (r < tl || l > tr) return -1; if (tl <= l && r <= tr) return tree[x].f; return max(queryMax(2 * x + 1, l, mid, tl, tr), queryMax(2 * x + 2, mid + 1, r, tl, tr)); } int queryPos(int x, int l, int r, int val) { int mid = (l + r) / 2; pushdown(x, l, r); if (l == r) return l; pushdown(2 * x + 1, l, mid); pushdown(2 * x + 2, mid + 1, r); if (tree[2 * x + 1].f >= val) return queryPos(2 * x + 1, l, mid, val); else if (tree[2 * x + 2].f >= val) return queryPos(2 * x + 2, mid + 1, r, val); return N; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> N >> M; for (int i = 0; i < N; i++) { int X; cin >> X; A.pb(X); } sort(A.begin(), A.end()); build(1, 0, N - 1); for (int i = 0; i < M; i++) { char C; int A, B; cin >> C >> A >> B; if (C == 'F') { int START = queryPos(1, 0, N - 1, B); if (START + A >= N) update(1, 0, N - 1, START, N - 1); else { int LAST = queryMax(1, 0, N - 1, START + A - 1, START + A - 1); int POS1 = queryPos(1, 0, N - 1, LAST); int POS2 = queryPos(1, 0, N - 1, LAST + 1); update(1, 0, N - 1, START, POS1 - 1); update(1, 0, N - 1, POS1 + POS2 - START - A, POS2 - 1); } } if (C == 'C') cout << queryPos(1, 0, N - 1, B + 1) - queryPos(1, 0, N - 1, A) << "\n"; } }

Compilation message (stderr)

grow.cpp: In function 'void pushdown(int, int, int)':
grow.cpp:19:42: warning: unused variable 'mid' [-Wunused-variable]
   19 | void pushdown(int x, int l, int r) { int mid = (l + r) / 2;
      |                                          ^~~
grow.cpp: In function 'void update(int, int, int, int, int)':
grow.cpp:27:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   27 |     if (r < tl || l > tr) return ; if (tl <= l && r <= tr) { tree[x].s++; return ; }
      |     ^~
grow.cpp:27:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   27 |     if (r < tl || l > tr) return ; if (tl <= l && r <= tr) { tree[x].s++; return ; }
      |                                    ^~
grow.cpp: In function 'int queryPos(int, int, int, int)':
grow.cpp:45:5: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
   45 |     else if (tree[2 * x + 2].f >= val) return queryPos(2 * x + 2, mid + 1, r, val); return N;
      |     ^~~~
grow.cpp:45:85: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
   45 |     else if (tree[2 * x + 2].f >= val) return queryPos(2 * x + 2, mid + 1, r, val); return N;
      |                                                                                     ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...