結果
問題 |
No.1490 スライムと爆弾
|
ユーザー |
![]() |
提出日時 | 2021-04-23 23:18:56 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 313 ms / 2,000 ms |
コード長 | 2,345 bytes |
コンパイル時間 | 2,197 ms |
コンパイル使用メモリ | 203,932 KB |
最終ジャッジ日時 | 2025-01-21 00:26:57 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#include <bits/stdc++.h> template <class T = long long> struct CumulativeSum2D { private: const int h, w; std::vector<std::vector<T>> cum; public: CumulativeSum2D() = default; CumulativeSum2D(const int n) : cum(n + 2, std::vector<T>(n + 2)), h(n + 2), w(n + 2) {} CumulativeSum2D(const int h, const int w) : cum(h + 2, std::vector<T>(w + 2)), h(h + 2), w(w + 2) {} CumulativeSum2D(const std::vector<std::vector<T>> &vec) { h = vec.size() + 2, w = vec.front().size() + 2; cum.assign(h, std::vector<T>(w)); for(int i = 0; i < h - 2; i++) for(int j = 0; j < w - 2; j++) cum[i + 1][j + 1] = vec[i][j]; }; void add(const int x, const int y, const T val) { add(x, y, x + 1, y + 1, val); } void add(const int sx, const int sy, const int gx, const int gy, const T val) { assert(sx <= gx); assert(sy <= gy); assert(0 <= sx and sx < h); assert(0 <= sy and sy < w); assert(0 <= gx and gx < h); assert(0 <= gy and gy < w); cum[sx + 1][sy + 1] += val; cum[sx + 1][gy + 1] -= val; cum[gx + 1][sy + 1] -= val; cum[gx + 1][gy + 1] += val; } void build() { for(int i = 0; i < h - 1; i++) for(int j = 0; j < w - 1; j++) cum[i + 1][j + 1] += cum[i + 1][j] + cum[i][j + 1] - cum[i][j]; for(int i = 0; i < h - 1; i++) for(int j = 0; j < w - 1; j++) cum[i + 1][j + 1] += cum[i + 1][j] + cum[i][j + 1] - cum[i][j]; } //return [sx, gx) × [sy, gy) T query(const int sx, const int sy, const int gx, const int gy) const { assert(sx <= gx); assert(sy <= gy); assert(0 <= sx and sx < h); assert(0 <= sy and sy < w); assert(0 <= gx and gx < h); assert(0 <= gy and gy < w); return cum[gx][gy] - cum[sx][gy] - cum[gx][sy] + cum[sx][sy]; } T query(const int x, const int y) const { return query(x, y, x + 1, y + 1); } }; using namespace std; using T = tuple<int, int, int, int, int>; int res, h, w, n, m, t, u, l, r, a, x, y, b, c; int main() { cin >> h >> w >> n >> m; CumulativeSum2D cs(h, w); vector<T> slimes(n); for(int i = 0; i < n; i++) { cin >> t >> u >> l >> r >> a; slimes[i] = T(--t, u, --l, r, a); } while(m--) { cin >> x >> y >> b >> c; --x, --y; cs.add(max(x - b, 0), max(y - b, 0), min(x + b + 1, h), min(y + b + 1, w), c); } cs.build(); for(auto [sx, gx, sy, gy, a] : slimes) res += cs.query(sx, sy, gx, gy) < a; cout << res << '\n'; return 0; }