結果
| 問題 | No.60 魔法少女 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-05-04 01:32:39 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 470 ms / 5,000 ms | 
| コード長 | 1,855 bytes | 
| コンパイル時間 | 3,016 ms | 
| コンパイル使用メモリ | 197,028 KB | 
| 最終ジャッジ日時 | 2025-01-21 06:36:04 | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 10 | 
ソースコード
#include <bits/stdc++.h>
#define int int64_t
using namespace std;
/**
 * @brief いもす法 (2D)
 */
template <typename T>
class imos_2d {
public:
    /**
     * @note field is [0, N) × [0, M)
     */
    imos_2d(std::uint32_t N, std::uint32_t M) : N(N), M(M), data(N + 1, std::vector<T>(M + 1, 0)) {}
    void build() {
        for (std::uint32_t i = 0; i < N; ++i) {
            for (std::uint32_t j = 0; j < M; ++j) {
                data[i][j + 1] += data[i][j];
            }
        }
        for (std::uint32_t j = 0; j < M; ++j) {
            for (std::uint32_t i = 0; i < N; ++i) {
                data[i + 1][j] += data[i][j];
            }
        }
    }
    const std::vector<T>& operator [] (std::uint32_t i) const {
        return (data.at(i));
    }
    std::vector<T>& operator [] (std::uint32_t i) {
        return (data.at(i));
    }
    /**
     * @note add val to [y1, y2) × [x1, x2)
     */
    void add(std::uint32_t y1, std::uint32_t x1, std::uint32_t y2, std::uint32_t x2, const T& val) {
        data[y1][x1] += val;
        data[y1][x2] -= val;
        data[y2][x1] -= val;
        data[y2][x2] += val;
    }
private:
    const std::uint32_t N, M;
    std::vector<std::vector<T>> data;
};
signed main() {
    int N, K;
    cin >> N >> K;
    auto hp = imos_2d<int>(2010, 2010);
    for (int i = 0; i < N; ++i) {
        int X, Y, HP;
        cin >> X >> Y >> HP;
        X += 500; Y += 500;
        hp.add(Y, X, Y + 1, X + 1, HP);
    }
    for (int i = 0; i < K; ++i) {
        int AX, AY, W, H, D;
        cin >> AX >> AY >> W >> H >> D;
        AX += 500; AY += 500;
        hp.add(AY, AX, AY + H + 1, AX + W + 1, -D);
    }
    hp.build();
    int ans = 0;
    for (int i = 0; i < 2010; ++i) {
        for (int j = 0; j < 2010; ++j) {
            ans += max(0L, hp[i][j]);
        }
    }
    cout << ans << endl;
}
            
            
            
        