Submission #125883

#TimeUsernameProblemLanguageResultExecution timeMemory
125883eriksuenderhaufNuclearia (CEOI15_nuclearia)C++11
100 / 100
591 ms178936 KiB
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; const int MAXN = 2500005; typedef long long ll; ll d1[MAXN], d2[MAXN]; ll offC[MAXN], slC[MAXN], offSlC[MAXN], slSlC[MAXN]; ll sm[MAXN], sl[MAXN], off[MAXN]; int w, h, n, q; int get(int y, int x) { if (y == 0 || x == 0 || y > h || x > w) return 0; return (y-1) * w + x; } int main() { scanf("%d %d %d", &w, &h, &n); for (int i = 0; i < n; i++) { ll x, y, a, b; scanf("%lld %lld %lld %lld", &x, &y, &a, &b); ll l = max(1ll, x - a / b), r = min((ll)w, x + a / b); ll c = max(1ll, y - a / b), d = min((ll)h, y + a / b); ll loc = x - abs(y-c), hic = x + abs(y-c); ll lod = x - abs(y-d), hid = x + abs(y-d); if (loc < 1ll) { d1[get(y-x+1,2)] -= b; offSlC[get(c,2)] -= b; offSlC[get(c,l)] -= b; offSlC[get(c,l+1)] += b; offSlC[get(y-x+1,2)] += b; offSlC[get(y-x+1,l)] += b; offSlC[get(y-x+1,l+1)] -= b; slSlC[get(y-x+1,l)] -= b; slSlC[get(y-x+1,l+1)] += b; } else { d1[get(c,loc+1)] -= b; slSlC[get(c,l)] -= loc * b; slSlC[get(c,l+1)] += loc * b; slSlC[get(c+1,l)] += loc * b - b; slSlC[get(c+1,l+1)] -= loc * b - b; } if (lod < 1ll) { d2[get(x+y-1,2)] -= b; offSlC[get(x+y,2)] -= b; offSlC[get(x+y,l)] -= b; offSlC[get(x+y,l+1)] += b; offSlC[get(d+1,2)] += b; offSlC[get(d+1,l)] += b; offSlC[get(d+1,l+1)] -= b; slSlC[get(x+y+1,l)] -= b; slSlC[get(x+y+1,l+1)] += b; } else { d2[get(d,lod+1)] -= b; slSlC[get(d+1,l)] += lod * b - b; slSlC[get(d+1,l+1)] -= lod * b - b; slSlC[get(d+2,l)] -= lod * b; slSlC[get(d+2,l+1)] += lod * b; } if (hid > (ll)w) { offSlC[get(w+y-x+1,r+1)] -= b * w; offSlC[get(w+y-x+1,r+2)] += b * w; offSlC[get(d+1,r+1)] += b * w; offSlC[get(d+1,r+2)] -= b * w; slSlC[get(w+y-x+1,r+1)] += (ll)w * b + b; slSlC[get(w+y-x+1,r+2)] -= (ll)w * b + b; slSlC[get(w+y-x+2,r+1)] -= (ll)w * b; slSlC[get(w+y-x+2,r+2)] += (ll)w * b; } else { d1[get(d+1,hid+2)] += b; slSlC[get(d+1,r+1)] += hid * b + b; slSlC[get(d+1,r+2)] -= hid * b + b; slSlC[get(d+2,r+1)] -= hid * b; slSlC[get(d+2,r+2)] += hid * b; } if (hic > (ll)w) { offSlC[get(c,r+1)] -= b * w; offSlC[get(c,r+2)] += b * w; offSlC[get(x+y-w,r+1)] += b * w; offSlC[get(x+y-w,r+2)] -= b * w; slSlC[get(x+y-w,r+1)] -= (ll)w * b; slSlC[get(x+y-w,r+2)] += (ll)w * b; slSlC[get(x+y-w+1,r+1)] += (ll)w*b + b; slSlC[get(x+y-w+1,r+2)] -= (ll)w*b + b; } else { d2[get(c-1,hic+2)] += b; slSlC[get(c,r+1)] -= hic * b; slSlC[get(c,r+2)] += hic * b; slSlC[get(c+1,r+1)] += hic * b + b; slSlC[get(c+1,r+2)] -= hic * b + b; } slSlC[get(y+1,l)] += 2 * b; slSlC[get(y+1,l+1)] -= 2 * b; slSlC[get(y+1,r+1)] -= 2 * b; slSlC[get(y+1,r+2)] += 2 * b; offC[get(c,l)] += a; offC[get(c,r+1)] -= a; offC[get(d+1,l)] -= a; offC[get(d+1,r+1)] += a; slC[get(c,l)] -= (hic - x) * b; slC[get(c,r+1)] += (hic - x) * b; slC[get(c+1,l)] += (hic - x) * b + b; slC[get(c+1,r+1)] -= (hic - x) * b + b; slC[get(y+1,l)] -= 2 * b; slC[get(y+1,r+1)] += 2 * b; slC[get(d+1,l)] += (hid - x) * b + b; slC[get(d+1,r+1)] -= (hid - x) * b + b; slC[get(d+2,l)] -= (hid - x) * b; slC[get(d+2,r+1)] += (hid - x) * b; offSlC[get(c,l)] += b * l; offSlC[get(c,l+1)] -= b * (l-1); offSlC[get(c,r+1)] += b * (r+1); offSlC[get(c,r+2)] -= b * r; offSlC[get(d+1,l)] -= b * l; offSlC[get(d+1,l+1)] += b * (l-1); offSlC[get(d+1,r+1)] -= b * (r+1); offSlC[get(d+1,r+2)] += b * r; } for (int i = h-1; i > 0; i--) for (int j = 2; j <= w; j++) d2[get(i,j)] += d2[get(i+1,j-1)]; for (int i = 2; i <= h; i++) { int j = 1; slC[get(i,j)] += slC[get(i-1,j)]; slSlC[get(i,j)] += slSlC[get(i-1,j)]; offC[get(i,j)] += offC[get(i-1,j)]; offSlC[get(i,j)] += offSlC[get(i-1,j)]; for (j = 2; j <= w; j++) { slC[get(i,j)] += slC[get(i-1,j)]; slSlC[get(i,j)] += slSlC[get(i-1,j)]; d1[get(i,j)] += d1[get(i-1,j-1)]; offC[get(i,j)] += offC[get(i-1,j)]; offSlC[get(i,j)] += offSlC[get(i-1,j)]; } } for (int i = 1; i <= h; i++) { if (i > 1) { for (int j = 1; j <= w; j++) { slC[get(i,j)] += slC[get(i-1,j)]; slSlC[get(i,j)] += slSlC[get(i-1,j)]; } } for (int j = 1; j <= w; j++) { sl[j] = d1[get(i,j)] + d2[get(i,j)] + offSlC[get(i,j)] + slSlC[get(i,j)]; sl[j] += sl[j-1]; off[j] = offC[get(i,j)] + slC[get(i,j)]; off[j] += off[j-1]; } for (int j = 1; j <= w; j++) { sl[j] += sl[j-1]; sm[get(i,j)] = sm[get(i-1,j)] + sm[get(i,j-1)] - sm[get(i-1,j-1)] + sl[j] + off[j]; off[j] = 0; } for (int j = 1; j <= w; j++) sl[j] = 0; } scanf("%d", &q); while (q--) { ll x1, y1, x2, y2; scanf("%lld %lld %lld %lld", &x1, &y1, &x2, &y2); ll ans = sm[get(y2,x2)] - sm[get(y1-1,x2)] - sm[get(y2,x1-1)] + sm[get(y1-1,x1-1)]; x1 = (x2-x1+1) * (y2-y1+1); ans += x1 / 2; printf("%lld\n", ans / x1); } return 0; }

Compilation message (stderr)

nuclearia.cpp: In function 'int main()':
nuclearia.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d", &w, &h, &n);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
nuclearia.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld %lld %lld", &x, &y, &a, &b);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nuclearia.cpp:158:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &q);
  ~~~~~^~~~~~~~~~
nuclearia.cpp:161:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld %lld %lld", &x1, &y1, &x2, &y2);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: warning: assuming signed overflow does not occur when assuming that (X - c) > X is always false [-Wstrict-overflow]
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...