結果

問題 No.1490 スライムと爆弾
ユーザー nok0nok0
提出日時 2021-04-23 23:18:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 264 ms / 2,000 ms
コード長 2,345 bytes
コンパイル時間 2,376 ms
コンパイル使用メモリ 210,724 KB
実行使用メモリ 36,452 KB
最終ジャッジ日時 2023-09-17 13:08:10
合計ジャッジ時間 5,780 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 115 ms
17,672 KB
testcase_14 AC 140 ms
22,684 KB
testcase_15 AC 71 ms
18,572 KB
testcase_16 AC 103 ms
13,080 KB
testcase_17 AC 59 ms
21,596 KB
testcase_18 AC 140 ms
22,524 KB
testcase_19 AC 122 ms
20,712 KB
testcase_20 AC 89 ms
17,404 KB
testcase_21 AC 53 ms
16,728 KB
testcase_22 AC 122 ms
14,924 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 165 ms
36,360 KB
testcase_26 AC 167 ms
36,452 KB
testcase_27 AC 167 ms
36,264 KB
testcase_28 AC 123 ms
34,600 KB
testcase_29 AC 125 ms
34,456 KB
testcase_30 AC 264 ms
36,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

template <class T = long long>
struct CumulativeSum2D {
private:
	const int h, w;
	std::vector<std::vector<T>> cum;

public:
	CumulativeSum2D() = default;
	CumulativeSum2D(const int n) : cum(n + 2, std::vector<T>(n + 2)), h(n + 2), w(n + 2) {}
	CumulativeSum2D(const int h, const int w) : cum(h + 2, std::vector<T>(w + 2)), h(h + 2), w(w + 2) {}
	CumulativeSum2D(const std::vector<std::vector<T>> &vec) {
		h = vec.size() + 2, w = vec.front().size() + 2;
		cum.assign(h, std::vector<T>(w));
		for(int i = 0; i < h - 2; i++)
			for(int j = 0; j < w - 2; j++) cum[i + 1][j + 1] = vec[i][j];
	};

	void add(const int x, const int y, const T val) {
		add(x, y, x + 1, y + 1, val);
	}

	void add(const int sx, const int sy, const int gx, const int gy, const T val) {
		assert(sx <= gx);
		assert(sy <= gy);
		assert(0 <= sx and sx < h);
		assert(0 <= sy and sy < w);
		assert(0 <= gx and gx < h);
		assert(0 <= gy and gy < w);
		cum[sx + 1][sy + 1] += val;
		cum[sx + 1][gy + 1] -= val;
		cum[gx + 1][sy + 1] -= val;
		cum[gx + 1][gy + 1] += val;
	}

	void build() {
		for(int i = 0; i < h - 1; i++)
			for(int j = 0; j < w - 1; j++)
				cum[i + 1][j + 1] += cum[i + 1][j] + cum[i][j + 1] - cum[i][j];
		for(int i = 0; i < h - 1; i++)
			for(int j = 0; j < w - 1; j++)
				cum[i + 1][j + 1] += cum[i + 1][j] + cum[i][j + 1] - cum[i][j];
	}

	//return [sx, gx) × [sy, gy)
	T query(const int sx, const int sy, const int gx, const int gy) const {
		assert(sx <= gx);
		assert(sy <= gy);
		assert(0 <= sx and sx < h);
		assert(0 <= sy and sy < w);
		assert(0 <= gx and gx < h);
		assert(0 <= gy and gy < w);
		return cum[gx][gy] - cum[sx][gy] - cum[gx][sy] + cum[sx][sy];
	}

	T query(const int x, const int y) const { return query(x, y, x + 1, y + 1); }
};

using namespace std;

using T = tuple<int, int, int, int, int>;
int res, h, w, n, m, t, u, l, r, a, x, y, b, c;
int main() {
	cin >> h >> w >> n >> m;
	CumulativeSum2D cs(h, w);
	vector<T> slimes(n);
	for(int i = 0; i < n; i++) {
		cin >> t >> u >> l >> r >> a;
		slimes[i] = T(--t, u, --l, r, a);
	}

	while(m--) {
		cin >> x >> y >> b >> c;
		--x, --y;
		cs.add(max(x - b, 0), max(y - b, 0), min(x + b + 1, h), min(y + b + 1, w), c);
	}
	cs.build();

	for(auto [sx, gx, sy, gy, a] : slimes)
		res += cs.query(sx, sy, gx, gy) < a;

	cout << res << '\n';

	return 0;
}
0