結果

問題 No.60 魔法少女
ユーザー purupuru
提出日時 2016-03-06 15:07:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 105 ms / 5,000 ms
コード長 3,704 bytes
コンパイル時間 1,511 ms
コンパイル使用メモリ 169,748 KB
実行使用メモリ 7,872 KB
最終ジャッジ日時 2023-10-24 20:07:25
合計ジャッジ時間 3,083 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,080 KB
testcase_01 AC 4 ms
7,080 KB
testcase_02 AC 4 ms
7,080 KB
testcase_03 AC 4 ms
7,080 KB
testcase_04 AC 60 ms
7,344 KB
testcase_05 AC 58 ms
7,872 KB
testcase_06 AC 101 ms
7,872 KB
testcase_07 AC 76 ms
7,608 KB
testcase_08 AC 48 ms
7,608 KB
testcase_09 AC 22 ms
7,344 KB
testcase_10 AC 94 ms
7,872 KB
testcase_11 AC 11 ms
7,344 KB
testcase_12 AC 40 ms
7,608 KB
testcase_13 AC 105 ms
7,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back
#define debug( fmt, ... ) \
        fprintf( stderr, \
                  fmt "\n", \
                  ##__VA_ARGS__ \
        )

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1 << 29;
const double EPS = 1e-10;

double zero(double d) {
    return d < EPS ? 0.0 : d;
}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &a) {
    os << '[';
    rep(i, a.size()) os << (i ? " " : "") << a[i];
    return os << ']';
}

string toString(int i) {
    stringstream ss;
    ss << i;
    return ss.str();
}

const int MOD = 1000000007;
// a^k
ll fpow(ll a, ll k, int M) {
    ll res = 1ll;
    ll x = a;
    while (k != 0) {
        if ((k & 1) == 1)
            res = (res * x) % M;
        x = (x * x) % M;
        k >>= 1;
    }
    return res;
}

struct prepare {
	prepare() {
	    cout.setf(ios::fixed, ios::floatfield);
	    cout.precision(8);
	    ios_base::sync_with_stdio(false);
	}
} _prepare;


// BIT
struct BIT {
    int n;
    vi bit;

    BIT(int n) : n(n), bit(n + 1, 0) {
    }

    int sum(int i) {
        int s = 0;
        while (i > 0) {
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }

    void add(int i, int x) {
        while (i <= n) {
            bit[i] += x;
            i += i & -i;
        }
    }
};

// BIT 2x
struct BIT2 {
    int n;
    vector<BIT> bit;

    BIT2(int n, int n2): n(n), bit(n+1, BIT(n2)) {
    }

    int sum(int i, int j) {
        int s = 0;
        while (i > 0) {
            s += bit[i].sum(j);
            i -= i & -i;
        }
        return s;
    }

    void add(int i, int j, int x) {
        while (i <= n) {
            bit[i].add(j, x);
            i += i & -i;
        }
    }
};

const int MAX_W = 1010;
const int MAX_H = 1010;

int conv(int x, int y) {
    x += 501, y += 501;
    return (x*MAX_W + y);
}

int main() {
    int N, K;
    cin >> N >> K;

    vector<pii> enemies(N);
    rep(i, N) {
        int x, y, hp;
        cin >> x >> y >> hp;
        enemies[i] = mp(conv(x,y), hp);
    }

    BIT2 bit2(MAX_W, MAX_H);

    rep(i, K) {
        int ax, ay, w, h, d;
        cin >> ax >> ay >> w >> h >> d;
        ax += 501, ay += 501;

        bit2.add(ax, ay, d);

        bit2.add(min(ax+w+1, MAX_W-1), ay, -1 * d);
        bit2.add(ax, min(ay+h+1, MAX_H-1), -1 * d);
        bit2.add(min(ax+w+1, MAX_W-1), min(ay+h+1, MAX_H-1), d);
    }

    ll ans = 0;
    rep(i, N) {
        int xy = enemies[i].first;
        int x = xy / MAX_W;
        int y = xy % MAX_H;
        ans += max(0, enemies[i].second - bit2.sum(x,y));
    }
    cout << ans << endl;

    return 0;
}
0