結果

問題 No.60 魔法少女
ユーザー 0w10w1
提出日時 2016-12-06 17:36:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 141 ms / 5,000 ms
コード長 2,305 bytes
コンパイル時間 1,724 ms
コンパイル使用メモリ 172,440 KB
実行使用メモリ 10,232 KB
最終ジャッジ日時 2023-08-18 19:34:26
合計ジャッジ時間 3,781 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
7,548 KB
testcase_01 AC 23 ms
7,340 KB
testcase_02 AC 23 ms
7,400 KB
testcase_03 AC 24 ms
7,480 KB
testcase_04 AC 81 ms
8,600 KB
testcase_05 AC 93 ms
8,836 KB
testcase_06 AC 141 ms
10,232 KB
testcase_07 AC 104 ms
9,088 KB
testcase_08 AC 75 ms
8,696 KB
testcase_09 AC 46 ms
7,956 KB
testcase_10 AC 124 ms
9,852 KB
testcase_11 AC 36 ms
7,608 KB
testcase_12 AC 71 ms
8,380 KB
testcase_13 AC 136 ms
10,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair< int, int > pii;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef vector< pii > vp;
typedef vector< vp > vvp;
typedef vector< string > vs;
typedef vector< double > vd;
typedef vector< vd > vvd;

template< class T1, class T2 >
int upmin( T1 &x, T2 v ){
  if( x > v ){
    x = v;
    return 1;
  }
  return 0;
}

template< class T1, class T2 >
int upmax( T1 &x, T2 v ){
  if( x < v ){
    x = v;
    return 1;
  }
  return 0;
}

const int INF = 0x3f3f3f3f;

int N, K;
vi X, Y, HP;
vi AX, AY, W, H, D;

void init(){
  cin >> N >> K;
  X = Y = HP = vi( N );
  for( int i = 0; i < N; ++i )
    cin >> X[ i ] >> Y[ i ] >> HP[ i ];
  AX = AY = W = H = D = vi( K );
  for( int i = 0; i < K; ++i )
    cin >> AX[ i ] >> AY[ i ] >> W[ i ] >> H[ i ] >> D[ i ];
}

struct BIT2{
  vvi dat;
  BIT2( int n, int m ){
    dat = vvi( n, vi( m ) );
  }
  void add( int x, int y, int v ){
    for( int i = x; i < dat.size(); i += i & -i )
      for( int j = y; j < dat[ i ].size(); j += j & -j )
        dat[ i ][ j ] += v;
  }
  int sum( int x, int y ){
    int res = 0;
    for( int i = x; i > 0; i -= i & -i )
      for( int j = y; j > 0; j -= j & -j )
        res += dat[ i ][ j ];
    return res;
  }
};

BIT2 *bit2;

void preprocess(){
  bit2 = new BIT2( 1001 + 1, 1001 + 1 );
  for( int i = 0; i < N; ++i )
    bit2->add( X[ i ] + 501, Y[ i ] + 501, HP[ i ] ),
    bit2->add( X[ i ] + 501 + 1, Y[ i ] + 501, -HP[ i ] ),
    bit2->add( X[ i ] + 501, Y[ i ] + 501 + 1, -HP[ i ] ),
    bit2->add( X[ i ] + 501 + 1, Y[ i ] + 501 + 1, HP[ i ] );
  for( int i = 0; i < K; ++i )
    bit2->add( AX[ i ] + 501, AY[ i ] + 501, -D[ i ] ),
    bit2->add( AX[ i ] + 501 + W[ i ] + 1, AY[ i ] + 501, D[ i ] ),
    bit2->add( AX[ i ] + 501, AY[ i ] + 501 + H[ i ] + 1, D[ i ] ),
    bit2->add( AX[ i ] + 501 + W[ i ] + 1, AY[ i ] + 501 + H[ i ] + 1, -D[ i ] );
}

void solve(){
  int ans = 0;
  for( int i = -500 + 501; i <= 500 + 501; ++i )
    for( int j = -500 + 501; j <= 500 + 501; ++j ){
      int v = bit2->sum( i, j );
      if( v > 0 )
        ans += v;
    }
  cout << ans << endl;
}

signed main(){
  ios::sync_with_stdio( 0 );
  init();
  preprocess();
  solve();
  return 0;
}
0