답안 #259611

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
259611 2020-08-08T04:12:57 Z Berted Nuclearia (CEOI15_nuclearia) C++14
69 / 100
1000 ms 560204 KB
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <iomanip>
#define ll long long
#define vi vector<ll>
#define pub push_back
#define pii pair<int, int>
#define fst first
#define snd second
#define ppi pair<pii, int>

using namespace std;

int w, h, n, q;
vector<vi> ar, ar2, ar3, ar4;
vi ar6;

pii C[200001];
int A[200001], B[200001];

inline int getDist(pii a, pii b)
{
	return max(abs(a.fst - b.fst), abs(a.snd - b.snd));
}

inline void insert(int x, int y, vector<vi>& v, ll val)
{
	if (x < 0) {x = 0;}
	if (x > w) {x = w + 1;}
	if (y < 1) {y = 1;}
	if (y > h) {y = h + 1;}
	v[x][y] += val;
}

inline void reset(vector<vi> &v)
{
	for (int i = 0; i <= w + 1; i++)
	{
		for (int j = 0; j <= h + 1; j++)
		{
			v[i][j] = 0;
		}
	}
}

inline void outputDebug(const vector<vi> &v)
{
	cout << "\n";
	for (int i = 0; i <= h + 1; i++)
	{
		for (int j = 0; j <= w + 1; j++)
		{
			cout << setw(2) << v[j][i] << " ";
		}
		cout << "\n";
	}
}

int main()
{
	ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> w >> h;

	ar.assign(w + 2, vi(h + 2, 0));
	ar2.assign(w + 2, vi(h + 2, 0));
	ar3.assign(w + 2, vi(h + 2, 0));
	ar4.assign(w + 2, vi(h + 2, 0));
	ar6.assign(h + 2, 0);

	cin >> n;	

	for (int i = 0; i < n; i++)
	{
		cin >> C[i].fst >> C[i].snd >> A[i] >> B[i];
		int d = A[i] / B[i];
		pii a = {max(1, C[i].fst - d), max(1, C[i].snd - d)};
		pii b = {max(1, C[i].fst - d), min(h, C[i].snd + d)};

		insert(a.fst, a.snd, ar2, B[i]);
		insert(b.fst, C[i].snd + d, ar2, -B[i]);

		insert(a.fst, a.snd, ar, A[i] - B[i] * getDist(a, C[i]));
		insert(b.fst, b.snd + 1, ar, -(A[i] - B[i] * getDist(b, C[i])));

		insert(a.fst, C[i].snd - d, ar3, B[i]);
		insert(a.fst, C[i].snd - (C[i].fst - a.fst), ar3, -B[i]);
		insert(a.fst, C[i].snd + (C[i].fst - a.fst), ar3, -B[i]);
		insert(a.fst, C[i].snd + d, ar3, B[i]);

		a = {min(w, C[i].fst + d), max(1, C[i].snd - d)};
		b = {min(w, C[i].fst + d), min(h, C[i].snd + d)};

		insert(a.fst, a.snd, ar2, B[i]);
		insert(b.fst, C[i].snd + d, ar2, -B[i]);

		insert(a.fst + 1, a.snd, ar, -(A[i] - B[i] * getDist(a, C[i])));
		insert(b.fst + 1, b.snd + 1, ar, (A[i] - B[i] * getDist(b, C[i])));

		insert(a.fst + 1, C[i].snd - d, ar3, -B[i]);
		insert(a.fst + 1, C[i].snd - (C[i].fst - a.fst), ar3, B[i]);
		insert(a.fst + 1, C[i].snd + (C[i].fst - a.fst), ar3, B[i]);
		insert(a.fst + 1, C[i].snd + d, ar3, -B[i]);
	}

	for (int i = 0; i <= w + 1; i++)
	{
		for (int j = 1; j <= h + 1; j++)
		{
			ar2[i][j] += ar2[i][j - 1];
			ar[i][j] += ar[i][j - 1] + ar3[i][j - 1];
			ar3[i][j] += ar3[i][j - 1];
		}
	}
	
	reset(ar3);

	for (int i = 0; i < n; i++)
	{
		int d = A[i] / B[i];
		int dst = min(d, min(C[i].fst - 1, C[i].snd - 1));
		ar3[C[i].fst - dst][C[i].snd - dst] -= B[i];
		if (dst < d)
		{
			if (C[i].fst - 1 < C[i].snd - 1)
			{
				ar6[max(0, C[i].snd - d)] -= B[i];
				ar6[C[i].snd - dst] += B[i];
			}
		}
		dst = min(d, min(w - C[i].fst, C[i].snd - 1));
		ar4[C[i].fst + dst][C[i].snd - dst] -= B[i];
		dst = min(d, min(w + 1 - C[i].fst, h + 1 - C[i].snd));
		ar3[C[i].fst + dst][C[i].snd + dst] += B[i];
		dst = min(d, min(C[i].fst, h + 1 - C[i].snd));
		ar4[C[i].fst - dst][C[i].snd + dst] += B[i];
		if (dst < d)
		{
			if (C[i].fst < h + 1 - C[i].snd)
			{
				ar6[C[i].snd + dst] -= B[i];
				ar6[min(h + 1, C[i].snd + d)] += B[i];
			}
		}
	}

	for (int i = 1; i <= w + 1; i++)
	{
		for (int j = 1; j <= h + 1; j++) 
		{
			ar3[i][j] += ar3[i - 1][j - 1];
		}
	}

	for (int i = w; i >= 0; i--)
	{
		for (int j = 1; j <= h + 1; j++)
		{
			ar4[i][j] += ar4[i + 1][j - 1];
		}
	}

	for (int j = 1; j <= h + 1; j++) {ar6[j] += ar6[j - 1];}

	for (int i = 0; i <= w + 1; i++)
	{
		for (int j = 0; j <= h + 1; j++)
		{
			ar2[i][j] += ar3[i][j];
			ar2[i][j] += ar4[i][j];
		}
	}
	for (int j = 0; j <= h + 1; j++) ar2[0][j] += ar6[j];

	for (int i = 0; i <= w + 1; i++)
	{
		for (int j = 0; j <= h + 1; j++)
		{
			if (i) ar[i][j] = ar[i][j] + ar[i - 1][j];
			if (i > 1) ar[i][j] = ar[i][j] + ar2[i - 1][j];
			if (i) ar2[i][j] = ar2[i - 1][j] + ar2[i][j];
		}
	}

	for (int i = 0; i <= w + 1; i++)
	{
		for (int j = 0; j <= h + 1; j++)
		{
			if (j) ar[i][j] += ar[i][j - 1];
			if (i) ar[i][j] += ar[i - 1][j];
			if (i && j) ar[i][j] -= ar[i - 1][j - 1];
		}
	}

	cin >> q;

	for (int i = 0; i < q; i++) 
	{
		int s, l, e, r; ll sz = 0;
		cin >> s >> l >> e >> r;
		sz = ((ll)(r - l + 1) * (e - s + 1));
		ll res = ar[e][r] - ar[e][l - 1] - ar[s - 1][r] + ar[s - 1][l - 1];
		if (2 * (res % sz) >= sz) cout << res / sz + 1 << "\n";
		else cout << res / sz << "\n";
	}

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 819 ms 548476 KB Output is correct
2 Correct 86 ms 4728 KB Output is correct
3 Correct 80 ms 3960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 864 ms 548344 KB Output is correct
2 Correct 89 ms 4728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 79736 KB Output is correct
2 Correct 86 ms 4344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 87588 KB Output is correct
2 Correct 88 ms 4744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1010 ms 554488 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 525 ms 225528 KB Output is correct
2 Correct 91 ms 4728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 233 ms 84856 KB Output is correct
2 Correct 91 ms 5016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 358 ms 147192 KB Output is correct
2 Correct 84 ms 4344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1110 ms 560204 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1108 ms 559552 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 467 ms 92408 KB Output is correct
2 Correct 420 ms 91688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 472 ms 91896 KB Output is correct
2 Correct 430 ms 91768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 377 ms 93016 KB Output is correct
2 Correct 388 ms 93560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 357 ms 92280 KB Output is correct
2 Correct 612 ms 267752 KB Output is correct