답안 #125883

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
125883 2019-07-06T13:37:43 Z eriksuenderhauf Nuclearia (CEOI15_nuclearia) C++11
100 / 100
591 ms 178936 KB
#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

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]
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 59768 KB Output is correct
2 Correct 98 ms 2780 KB Output is correct
3 Correct 89 ms 2424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 59964 KB Output is correct
2 Correct 98 ms 2780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 163 ms 137352 KB Output is correct
2 Correct 98 ms 2736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 135 ms 137268 KB Output is correct
2 Correct 98 ms 2816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 243 ms 61568 KB Output is correct
2 Correct 104 ms 3064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 180 ms 27952 KB Output is correct
2 Correct 97 ms 2812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 286 ms 139644 KB Output is correct
2 Correct 103 ms 3064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 193 ms 43440 KB Output is correct
2 Correct 97 ms 2808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 491 ms 178936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 483 ms 178896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 588 ms 139384 KB Output is correct
2 Correct 587 ms 139512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 591 ms 139684 KB Output is correct
2 Correct 568 ms 139512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 476 ms 139748 KB Output is correct
2 Correct 438 ms 140152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 461 ms 139800 KB Output is correct
2 Correct 455 ms 106104 KB Output is correct