結果

問題 No.60 魔法少女
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-09-29 22:15:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 221 ms / 5,000 ms
コード長 1,087 bytes
コンパイル時間 810 ms
コンパイル使用メモリ 67,448 KB
実行使用メモリ 8,832 KB
最終ジャッジ日時 2024-05-01 07:51:28
合計ジャッジ時間 2,770 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 123 ms
7,808 KB
testcase_05 AC 124 ms
8,704 KB
testcase_06 AC 212 ms
8,832 KB
testcase_07 AC 160 ms
8,440 KB
testcase_08 AC 101 ms
8,320 KB
testcase_09 AC 45 ms
7,680 KB
testcase_10 AC 203 ms
8,576 KB
testcase_11 AC 22 ms
6,784 KB
testcase_12 AC 88 ms
8,448 KB
testcase_13 AC 221 ms
8,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
const int INF = 1e9;

//2次元BIT
const int MAX_W = 1010, MAX_H = 1010;
int bit[MAX_W + 1][MAX_H + 1];
void add(int a, int b, ll w){
	for (int y = a; y < MAX_W; y += y & -y){
		for (int x = b; x < MAX_H; x += x & -x){
			bit[y][x] += w;
		}
	}
}

ll sum(int a, int b){
	ll ret = 0;
	for (int y = a; y > 0; y -= y & -y){
		for (int x = b; x > 0; x -= x & -x){
			ret += bit[y][x];
		}
	}
	return ret;
}

int n, k;
int x[100010], y[100010], hp[100010];

int main(void){
	cin >> n >> k;
	rep(i, n){
		cin >> x[i] >> y[i] >> hp[i];
		x[i] += 501; y[i] += 501;// -500を1に1index
	}
	rep(i, k){
		int ax, ay, w, h, d;
		cin >> ax >> ay >> w >> h >> d;
		ax += 501; ay += 501;
		add(ay, ax, d);
		add(ay + h + 1, ax, -d);
		add(ay, ax + w + 1, -d);
		add(ay + h + 1, ax + w + 1, d);
	}

	ll ans = 0;
	rep(i, n){
		ans += max((ll)0, hp[i] - sum(y[i], x[i]));
	}
	printf("%lld\n", ans);
	return 0;
}
0