Submission #126319

#TimeUsernameProblemLanguageResultExecution timeMemory
126319imyujin단층 (JOI16_ho_t5)C++14
100 / 100
145 ms15736 KiB
#include<stdio.h> #define MAXN 200005 typedef long long lint; lint X[MAXN], L[MAXN]; int D[MAXN]; lint segX[4 * MAXN], segY[4 * MAXN]; void mkseg(int idx, int l, int r, lint seg[]) { seg[idx] = r - l + 1; if(l < r) { int m = (l + r) / 2; mkseg(idx * 2, l, m, seg); mkseg(idx * 2 + 1, m + 1, r, seg); } } int ub(int idx, int l, int r, lint x, lint seg[]) { if(seg[idx] <= x) return r + 1; if(x < 0 || l == r) return l; int m = (l + r) / 2; return x < seg[idx * 2] ? ub(idx * 2, l, m, x, seg) : ub(idx * 2 + 1, m + 1, r, x - seg[idx * 2], seg); } void updseg(int idx, int l, int r, int x, lint y, lint seg[]) { seg[idx] += y; if(l < r) { int m = (l + r) / 2; if(x <= m) updseg(idx * 2, l, m, x, y, seg); else updseg(idx * 2 + 1, m + 1, r, x, y, seg); } } void print(int idx, int l, int r, lint x, lint y) { if(l == r) printf("%lld\n", (y + segY[idx] - x - segX[idx]) / 2); else { int m = (l + r) / 2; print(idx * 2, l, m, x, y); print(idx * 2 + 1, m + 1, r, x + segX[idx * 2], y + segY[idx * 2]); } } int main() { int N, Q; lint x0 = 0ll; scanf("%d%d", &N, &Q); for(int i = 0; i < Q; i++) scanf("%lld%d%lld", X + i, D + i, L + i); mkseg(1, 0, N - 1, segX); mkseg(1, 0, N - 1, segY); for(int i = Q - 1; i >= 0; i--) { if(D[i] == 1) { int t = ub(1, 0, N - 1, X[i], segY); if(t < N) updseg(1, 0, N - 1, t, 2 * L[i], segX); x0 -= 2 * L[i]; } else { int t = ub(1, 0, N - 1, X[i] - x0, segX); if(t < N) updseg(1, 0, N - 1, t, 2 * L[i], segY); } } print(1, 0, N - 1, x0, 0); return 0; }

Compilation message (stderr)

2016_ho_t5.cpp: In function 'int main()':
2016_ho_t5.cpp:49:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &Q);
  ~~~~~^~~~~~~~~~~~~~~~
2016_ho_t5.cpp:50:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 0; i < Q; i++) scanf("%lld%d%lld", X + i, D + i, L + i);
                             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...