답안 #125880

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
125880 2019-07-06T13:30:29 Z eriksuenderhauf Nuclearia (CEOI15_nuclearia) C++11
92 / 100
1000 ms 706764 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];
vector<vector<ll>> offC, slC, offSlC, slSlC;
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);
	offC.resize(h+3), slC.resize(h+3);
	offSlC.resize(h+3), slSlC.resize(h+3);
	for (int i = 0; i <= h+2; i++) {
		offC[i].resize(w+3), slC[i].resize(w+3);
		offSlC[i].resize(w+3), slSlC[i].resize(w+3);
	}
	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[c][2] -= b;
			offSlC[c][l] -= b;
			offSlC[c][l+1] += b;
			offSlC[y-x+1][2] += b;
			offSlC[y-x+1][l] += b;
			offSlC[y-x+1][l+1] -= b;
			slSlC[y-x+1][l] -= b;
			slSlC[y-x+1][l+1] += b;
		} else {
			d1[get(c,loc+1)] -= b;
			slSlC[c][l] -= loc * b;
			slSlC[c][l+1] += loc * b;
			slSlC[c+1][l] += loc * b - b;
			slSlC[c+1][l+1] -= loc * b - b;
		}
		if (lod < 1ll) {
			d2[get(x+y-1,2)] -= b;
			offSlC[x+y][2] -= b;
			offSlC[x+y][l] -= b;
			offSlC[x+y][l+1] += b;
			offSlC[d+1][2] += b;
			offSlC[d+1][l] += b;
			offSlC[d+1][l+1] -= b;
			slSlC[x+y+1][l] -= b;
			slSlC[x+y+1][l+1] += b;
		} else {
			d2[get(d,lod+1)] -= b;
			slSlC[d+1][l] += lod * b - b;
			slSlC[d+1][l+1] -= lod * b - b;
			slSlC[d+2][l] -= lod * b;
			slSlC[d+2][l+1] += lod * b;
		}
		if (hid > (ll)w) {
			offSlC[w+y-x+1][r+1] -= b * w;
			offSlC[w+y-x+1][r+2] += b * w;
			offSlC[d+1][r+1] += b * w;
			offSlC[d+1][r+2] -= b * w;
			slSlC[w+y-x+1][r+1] += (ll)w * b + b;
			slSlC[w+y-x+1][r+2] -= (ll)w * b + b;
			slSlC[w+y-x+2][r+1] -= (ll)w * b;
			slSlC[w+y-x+2][r+2] += (ll)w * b;
		} else {
			d1[get(d+1,hid+2)] += b;
			slSlC[d+1][r+1] += hid * b + b;
			slSlC[d+1][r+2] -= hid * b + b;
			slSlC[d+2][r+1] -= hid * b;
			slSlC[d+2][r+2] += hid * b;
		}
		if (hic > (ll)w) {
			offSlC[c][r+1] -= b * w;
			offSlC[c][r+2] += b * w;
			offSlC[x+y-w][r+1] += b * w;
			offSlC[x+y-w][r+2] -= b * w;
			slSlC[x+y-w][r+1] -= (ll)w * b;
			slSlC[x+y-w][r+2] += (ll)w * b;
			slSlC[x+y-w+1][r+1] += (ll)w*b + b;
			slSlC[x+y-w+1][r+2] -= (ll)w*b + b;
		} else {
			d2[get(c-1,hic+2)] += b;
			slSlC[c][r+1] -= hic * b;
			slSlC[c][r+2] += hic * b;
			slSlC[c+1][r+1] += hic * b + b;
			slSlC[c+1][r+2] -= hic * b + b;
		}
		slSlC[y+1][l] += 2 * b;
		slSlC[y+1][l+1] -= 2 * b;
		slSlC[y+1][r+1] -= 2 * b;
		slSlC[y+1][r+2] += 2 * b;
		offC[c][l] += a;
		offC[c][r+1] -= a;
		offC[d+1][l] -= a;
		offC[d+1][r+1] += a;
		slC[c][l] -= (hic - x) * b;
		slC[c][r+1] += (hic - x) * b;
		slC[c+1][l] += (hic - x) * b + b;
		slC[c+1][r+1] -= (hic - x) * b + b;
		slC[y+1][l] -= 2 * b;
		slC[y+1][r+1] += 2 * b;
		slC[d+1][l] += (hid - x) * b + b;
		slC[d+1][r+1] -= (hid - x) * b + b;
		slC[d+2][l] -= (hid - x) * b;
		slC[d+2][r+1] += (hid - x) * b;
		offSlC[c][l] += b * l;
		offSlC[c][l+1] -= b * (l-1);
		offSlC[c][r+1] += b * (r+1);
		offSlC[c][r+2] -= b * r;
		offSlC[d+1][l] -= b * l;
		offSlC[d+1][l+1] += b * (l-1);
		offSlC[d+1][r+1] -= b * (r+1);
		offSlC[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[i][j] += slC[i-1][j];
		slSlC[i][j] += slSlC[i-1][j];
		offC[i][j] += offC[i-1][j];
		offSlC[i][j] += offSlC[i-1][j];
		for (j = 2; j <= w; j++) {
			slC[i][j] += slC[i-1][j];
			slSlC[i][j] += slSlC[i-1][j];
			d1[get(i,j)] += d1[get(i-1,j-1)];
			offC[i][j] += offC[i-1][j];
			offSlC[i][j] += offSlC[i-1][j];
		}
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			slC[i][j] += slC[i-1][j];
			slSlC[i][j] += slSlC[i-1][j];
		}
		for (int j = 1; j <= w; j++) {
			sl[j] = d1[get(i,j)] + d2[get(i,j)] + offSlC[i][j] + slSlC[i][j];
			sl[j] += sl[j-1];
			off[j] = offC[i][j] + slC[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:27: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:161:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &q);
  ~~~~~^~~~~~~~~~
nuclearia.cpp:164: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 351 ms 372600 KB Output is correct
2 Correct 97 ms 2812 KB Output is correct
3 Correct 90 ms 2428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 346 ms 372600 KB Output is correct
2 Correct 100 ms 2808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 162 ms 137932 KB Output is correct
2 Correct 96 ms 2808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 258 ms 164812 KB Output is correct
2 Correct 97 ms 2808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 517 ms 374644 KB Output is correct
2 Correct 103 ms 3064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 277 ms 152312 KB Output is correct
2 Correct 98 ms 2808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 307 ms 140892 KB Output is correct
2 Correct 103 ms 3072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 255 ms 105488 KB Output is correct
2 Correct 96 ms 2808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 719 ms 413748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 717 ms 413816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 574 ms 140108 KB Output is correct
2 Correct 568 ms 140408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 564 ms 139988 KB Output is correct
2 Correct 556 ms 140664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 582 ms 144848 KB Output is correct
2 Correct 440 ms 141048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 453 ms 140456 KB Output is correct
2 Execution timed out 1123 ms 706764 KB Time limit exceeded