結果

問題 No.60 魔法少女
ユーザー chaemonchaemon
提出日時 2014-11-09 23:37:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 254 ms / 5,000 ms
コード長 2,493 bytes
コンパイル時間 615 ms
コンパイル使用メモリ 79,128 KB
実行使用メモリ 7,600 KB
最終ジャッジ日時 2023-08-30 02:50:57
合計ジャッジ時間 3,371 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
7,328 KB
testcase_01 AC 27 ms
7,304 KB
testcase_02 AC 27 ms
7,332 KB
testcase_03 AC 27 ms
7,304 KB
testcase_04 AC 143 ms
7,380 KB
testcase_05 AC 158 ms
7,380 KB
testcase_06 AC 247 ms
7,384 KB
testcase_07 AC 186 ms
7,440 KB
testcase_08 AC 127 ms
7,600 KB
testcase_09 AC 70 ms
7,432 KB
testcase_10 AC 229 ms
7,392 KB
testcase_11 AC 49 ms
7,460 KB
testcase_12 AC 119 ms
7,308 KB
testcase_13 AC 254 ms
7,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #includes {{{
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <cmath>
using namespace std;
// }}}
// pre-written code {{{
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

const int INF=0x3f3f3f3f;

typedef long long Int;
typedef unsigned long long uInt;
#ifdef __MINGW32__
typedef double rn;
#else
typedef long double rn;
#endif

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}


//range i..j (inclusive)
//larger range which contains k
inline int up(const int &k){return k|(k+1);}
//previous range adjacent to k
inline int left(const int &k){return (k&(k+1))-1;}

//{{{ Fenwick Tree type2 2D
template <class T>
struct fenwick_tree {
	vector<vector<T> > x;
	fenwick_tree(int n) : x(n, vector<T>(n,0)) { }
	void add(int i0, int i1, int j0,int j1,T a) {
		if (i0 == 0 and i1 == 0) {
			int J0=j0,J1=j1;
			for (j0=J0; j0 >= 0; j0 = left(j0))
				for (j1=J1; j1 >= 0; j1 = left(j1)) x[j0][j1] += a;
		} else {
			add(0,0,j0,j1,a);
			add(0,0,i0-1,j1,-a);
			add(0,0,j0,i1-1,-a);
			add(0,0,i0-1,i1-1,a);
		}
	}
	T get(int k0,int k1) {
		T ret = 0;
		const int K0=k0,K1=k1;
		for(k0=K0; k0<x.size();k0=up(k0))
			for (k1=K1; k1 < x.size(); k1=up(k1)) ret += x[k0][k1];
		return ret;
	}
};
//}}}
int B = 505;

int main(){
	int N,K;
	cin>>N>>K;
	const int T = B*2;
	fenwick_tree<int> ft(T);
	REP(i,N){
		int X,Y,H;
		cin>>X>>Y>>H;
		X+=B;Y+=B;
		ft.add(X,Y,X,Y,H);
	}
	REP(i,K){
		int AX,AY,W,H,D;
		cin>>AX>>AY>>W>>H>>D;
		AX+=B;AY+=B;
		ft.add(AX,AY,min(AX+W,T-1),min(AY+H,T-1),-D);
	}
	Int ans = 0;
	REP(i,T)REP(j,T){
		int g = ft.get(i,j);
		if(g>0)ans+=g;
	}
	cout<<ans<<endl;
	return 0;
}
0