Submission #823946

#TimeUsernameProblemLanguageResultExecution timeMemory
823946rainboyTriangle Collection (CCO23_day2problem3)C11
25 / 25
192 ms16680 KiB
#include <stdio.h> #define N 200000 #define N_ (1 << 18) /* N_ = pow2(ceil(log2(N))) */ long long min(long long a, long long b) { return a < b ? a : b; } long long ss[N_ * 2], qq[N_ * 2]; int n_; void pul(int i) { int l = i << 1, r = l | 1; ss[i] = ss[l] + ss[r]; qq[i] = min(qq[l] + ss[r], qq[r]); } void build(int *aa, int n) { int i; n_ = 1; while (n_ < n) n_ <<= 1; for (i = 0; i < n; i++) { ss[n_ + i] += aa[i] / 2; if (aa[i] % 2 != 0) ss[n_ + (i + 1) / 2]--; } for (i = 0; i < n_; i++) qq[n_ + i] = min(ss[n_ + i], 0); for (i = n_ - 1; i > 0; i--) pul(i); } void update(int i, int x) { i += n_; qq[i] = min(ss[i] += x, 0); while (i > 1) pul(i >>= 1); } int main() { static int aa[N]; int n, q, i, d; long long sum; scanf("%d%d", &n, &q); sum = 0; for (i = 0; i < n; i++) { scanf("%d", &aa[i]); sum += aa[i]; } build(aa, n); while (q--) { scanf("%d%d", &i, &d), i--; update(i, -(aa[i] / 2)); if (aa[i] % 2 != 0) update((i + 1) / 2, 1); aa[i] += d, sum += d; update(i, aa[i] / 2); if (aa[i] % 2 != 0) update((i + 1) / 2, -1); printf("%lld\n", (sum + qq[1]) / 3); } return 0; }

Compilation message (stderr)

Main.c: In function 'main':
Main.c:46:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |  scanf("%d%d", &n, &q);
      |  ^~~~~~~~~~~~~~~~~~~~~
Main.c:49:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
Main.c:54:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |   scanf("%d%d", &i, &d), i--;
      |   ^~~~~~~~~~~~~~~~~~~~~
#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...