結果

問題 No.60 魔法少女
ユーザー chaemonchaemon
提出日時 2014-11-09 23:31:45
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 2,475 bytes
コンパイル時間 872 ms
コンパイル使用メモリ 78,672 KB
実行使用メモリ 7,516 KB
最終ジャッジ日時 2023-08-30 02:49:56
合計ジャッジ時間 4,117 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
7,380 KB
testcase_01 AC 29 ms
7,516 KB
testcase_02 AC 28 ms
7,380 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
権限があれば一括ダウンロードができます

ソースコード

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 D = B*2;
	fenwick_tree<int> ft(D);
	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,AX+W,AY+H,-D);
	}
	Int ans = 0;
	REP(i,D)REP(j,D){
		int g = ft.get(i,j);
		if(g>0)ans+=g;
	}
	cout<<ans<<endl;
	return 0;
}
0