Submission #125840

# Submission time Handle Problem Language Result Execution time Memory
125840 2019-07-06T12:51:26 Z eriksuenderhauf Nuclearia (CEOI15_nuclearia) C++11
92 / 100
1000 ms 789500 KB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<vector<ll>> off, sl, sm, d1, d2;
vector<vector<ll>> offC, slC, offSlC, slSlC;
 
int main() {
	int w, h, n;
	scanf("%d %d %d", &w, &h, &n);
	off.resize(h+1); sl.resize(h+1), sm.resize(h+1);
	d1.resize(h+3), d2.resize(h+3), offC.resize(h+3), slC.resize(h+3);
	offSlC.resize(h+3), slSlC.resize(h+3);
	for (int i = 0; i <= h; i++)
		off[i].resize(w+1), sl[i].resize(w+1), sm[i].resize(w+1);
	for (int i = 0; i <= h+2; i++) {
		d1[i].resize(w+3), d2[i].resize(w+3);
		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);
		if (x-abs(y-c) < 1ll) {
			d1[y-x+1][2] -= b;
			offSlC[c][2] -= b;
			offSlC[y-x+1][2] += b;
			offSlC[c][l] -= b;
			offSlC[y-x+1][l] += b;
			offSlC[c][l+1] += b;
			offSlC[y-x+1][l+1] -= b;
			slSlC[y-x+1][l] -= b;
			slSlC[y-x+1][l+1] += b;
		} else {
			d1[c][x-abs(y-c)+1] -= b;
			slSlC[c][l] -= (x - abs(y-c)) * b;
			slSlC[c+1][l] += (x - abs(y-c)) * b - b;
			slSlC[c][l+1] += (x - abs(y-c)) * b;
			slSlC[c+1][l+1] -= (x - abs(y-c)) * b - b;
		}
		slSlC[y+1][l] += 2 * b;
		slSlC[y+1][l+1] -= 2 * b;
		if (x-abs(y-d) < 1ll) {
			d2[x+y-1][2] -= b;
			offSlC[x+y][2] -= b;
			offSlC[d+1][2] += b;
			offSlC[x+y][l] -= b;
			offSlC[d+1][l] += b;
			offSlC[x+y][l+1] += b;
			offSlC[d+1][l+1] -= b;
			slSlC[x+y+1][l] -= b;
			slSlC[x+y+1][l+1] += b;
		} else {
			d2[d][x-abs(y-d)+1] -= b;
			slSlC[d+1][l] += (x-abs(y-d)) * b - b;
			slSlC[d+2][l] -= (x-abs(y-d)) * b;
			slSlC[d+1][l+1] -= (x-abs(y-d)) * b - b;
			slSlC[d+2][l+1] += (x-abs(y-d)) * b;
		}
		if (x+abs(y-d) > (ll)w) {
			offSlC[w+y-x+1][r+1] -= b * w;
			offSlC[d+1][r+1] += b * w;
			offSlC[w+y-x+1][r+2] += b * w;
			offSlC[d+1][r+2] -= b * w;
			slSlC[w+y-x+1][r+1] += (ll)w * b + b;
			slSlC[w+y-x+2][r+1] -= (ll)w * b;
			slSlC[w+y-x+1][r+2] -= (ll)w * b + b;
			slSlC[w+y-x+2][r+2] += (ll)w * b;
		} else {
			d1[d+1][x+abs(y-d)+2] += b;
			slSlC[d+1][r+1] += (x+abs(y-d)) * b + b;
			slSlC[d+2][r+1] -= (x+abs(y-d)) * b;
			slSlC[d+1][r+2] -= (x+abs(y-d)) * b + b;
			slSlC[d+2][r+2] += (x+abs(y-d)) * b;
		}
		slSlC[y+1][r+1] -= 2 * b;
		slSlC[y+1][r+2] += 2 * b;
		if (x+abs(y-c) > (ll)w) {
			offSlC[c][r+1] -= b * w;
			offSlC[x+y-w][r+1] += b * w;
			offSlC[c][r+2] += b * w;
			offSlC[x+y-w][r+2] -= b * w;
			slSlC[x+y-w][r+1] -= (ll)w * b;
			slSlC[x+y-w+1][r+1] += (ll)w*b + b;
			slSlC[x+y-w][r+2] += (ll)w * b;
			slSlC[x+y-w+1][r+2] -= (ll)w*b + b;
		} else {
			d2[c-1][x+abs(y-c)+2] += b;
			slSlC[c][r+1] -= (x+abs(y-c)) * b;
			slSlC[c+1][r+1] += (x+abs(y-c)) * b + b;
			slSlC[c][r+2] += (x+abs(y-c)) * b;
			slSlC[c+1][r+2] -= (x+abs(y-c)) * b + b;
		}
		offC[c][l] += a;
		offC[d+1][l] -= a;
		offC[c][r+1] -= a;
		offC[d+1][r+1] += a;
		slC[c][l] -= abs(y-c) * b;
		slC[c+1][l] += abs(y-c) * b + b;
		slC[y+1][l] -= 2 * b;
		slC[d+1][l] += abs(y-d) * b + b;
		slC[d+2][l] -= abs(y-d) * b;
		slC[c][r+1] += abs(y-c) * b;
		slC[c+1][r+1] -= abs(y-c) * b + b;
		slC[y+1][r+1] += 2 * b;
		slC[d+1][r+1] -= abs(y-d) * b + b;
		slC[d+2][r+1] += abs(y-d) * b;
		offSlC[c][l] += b * l;
		offSlC[d+1][l] -= b * l;
		offSlC[c][l+1] -= b * (l-1);
		offSlC[d+1][l+1] += b * (l-1);
		offSlC[c][r+1] += b * (r+1);
		offSlC[d+1][r+1] -= b * (r+1);
		offSlC[c][r+2] -= b * r;
		offSlC[d+1][r+2] += b * r;
	}
	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 i = h-1; i > 0; i--)
		for (int j = 1; j <= w; j++)
			d2[i][j] += d2[i+1][j-1];
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			d1[i][j] += d1[i-1][j-1];
			offC[i][j] += offC[i-1][j];
			offSlC[i][j] += offSlC[i-1][j];
			slC[i][j] += slC[i-1][j];
			slSlC[i][j] += slSlC[i-1][j];
		}
		for (int j = 1; j <= w; j++) {
			sl[i][j] += d1[i][j] + d2[i][j] + offSlC[i][j] + slSlC[i][j];
			off[i][j] += offC[i][j] + slC[i][j];
			off[i][j] += off[i][j-1];
			sl[i][j] += sl[i][j-1];
		}
		for (int j = 1; j <= w; j++)
			sl[i][j] += sl[i][j-1];
		for (int j = 1; j <= w; j++)
			sm[i][j] = sm[i-1][j] + sm[i][j-1] - sm[i-1][j-1] + sl[i][j] + off[i][j];
	}
	int q; scanf("%d", &q);
	while (q--) {
		ll x1, y1, x2, y2;
		scanf("%lld %lld %lld %lld", &x1, &y1, &x2, &y2);
		ll ans = sm[y2][x2] - sm[y1-1][x2] - sm[y2][x1-1] + sm[y1-1][x1-1];
		x1 = (x2-x1+1) * (y2-y1+1);
		if ((ans % x1) * 2 >= x1)
			printf("%lld\n", ans / x1 + 1);
		else
			printf("%lld\n", ans / x1);
	}
    return 0;
}

Compilation message

nuclearia.cpp: In function 'int main()':
nuclearia.cpp:10: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:23: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:147:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int q; scanf("%d", &q);
         ~~~~~^~~~~~~~~~
nuclearia.cpp:150: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);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 552 ms 587512 KB Output is correct
2 Correct 98 ms 2808 KB Output is correct
3 Correct 87 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 559 ms 587640 KB Output is correct
2 Correct 98 ms 2808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 196 ms 177528 KB Output is correct
2 Correct 96 ms 2832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 449 ms 232388 KB Output is correct
2 Correct 98 ms 2808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 710 ms 589612 KB Output is correct
2 Correct 106 ms 3160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 382 ms 237600 KB Output is correct
2 Correct 98 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 346 ms 181112 KB Output is correct
2 Correct 102 ms 3060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 299 ms 155448 KB Output is correct
2 Correct 95 ms 2808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 968 ms 589796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 942 ms 589964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 610 ms 180596 KB Output is correct
2 Correct 613 ms 180984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 606 ms 180736 KB Output is correct
2 Correct 620 ms 181932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 679 ms 190400 KB Output is correct
2 Correct 483 ms 181752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 500 ms 181016 KB Output is correct
2 Execution timed out 1109 ms 789500 KB Time limit exceeded