結果

問題 No.60 魔法少女
ユーザー hotpepsihotpepsi
提出日時 2015-08-09 00:39:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,863 ms / 5,000 ms
コード長 1,627 bytes
コンパイル時間 485 ms
コンパイル使用メモリ 66,896 KB
実行使用メモリ 21,028 KB
最終ジャッジ日時 2023-09-25 07:23:41
合計ジャッジ時間 17,871 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
19,860 KB
testcase_01 AC 13 ms
19,892 KB
testcase_02 AC 14 ms
20,028 KB
testcase_03 AC 15 ms
19,872 KB
testcase_04 AC 2,102 ms
20,060 KB
testcase_05 AC 1,002 ms
21,028 KB
testcase_06 AC 2,680 ms
20,948 KB
testcase_07 AC 2,049 ms
20,764 KB
testcase_08 AC 1,125 ms
20,508 KB
testcase_09 AC 544 ms
20,288 KB
testcase_10 AC 2,483 ms
20,964 KB
testcase_11 AC 39 ms
20,200 KB
testcase_12 AC 655 ms
20,648 KB
testcase_13 AC 2,863 ms
21,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <sstream>
#include <vector>

using namespace std;
typedef long long LL;

class BIT {
	std::vector<LL> bit;
	int size;
public:
	BIT() { }
	BIT(int sz) { init(sz); }
	void init(int sz) {
		bit.resize((size = sz) + 1);
	}
	LL sum(int i) {
		LL s = 0;
		while (i > 0) {
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}
	void add(int i, LL x) {
		if (i == 163) {
			++i;
			--i;
		}

		while (i <= size) {
			bit[i] += x;
			i += i & -i;
		}
	}
};

class RangedSUM {
	BIT high;
	BIT low;

public:
	RangedSUM() { }
	RangedSUM(int sz) : high(sz), low(sz) { }
	void init(int sz) {
		high.init(sz);
		low.init(sz);
	}
	void add(int start, int end, LL value) {
		low.add(start, (start - 1) * -value);
		high.add(start, value);
		low.add(end + 1, end * value);
		high.add(end + 1, -value);
	}
	LL sum(int start, int end) {
		return low.sum(end) + high.sum(end) * end - low.sum(start - 1) - high.sum(start - 1) * (start - 1);
	}
};

int main(int argc, char *argv[])
{
	RangedSUM rsum[1024];
	for (int i = 0; i < 1024; ++i) {
		rsum[i].init(1024);
	}

	int ex[100000], ey[100000], ehp[100000];

	int N, K;
	cin >> N >> K;
	for (int i = 0; i < N; ++i) {
		cin >> ex[i] >> ey[i] >> ehp[i];
		ex[i] += 512, ey[i] += 512;
	}
	for (int i = 0; i < K; ++i) {
		int ax, ay, w, h, d;
		cin >> ax >> ay >> w >> h >> d;
		ax += 512, ay += 512;
		int ex = min(1020, ax + w);
		for (int y = ay; y <= min(1020, ay + h); ++y) {
			rsum[y].add(ax, ex, d);
		}
	}
	LL ans = 0;
	for (int i = 0; i < N; ++i) {
		ans += max(0LL, ehp[i] - rsum[ey[i]].sum(ex[i], ex[i]));
	}
	cout << ans << endl;
	return 0;
}
0