結果

問題 No.1490 スライムと爆弾
ユーザー 👑 emthrmemthrm
提出日時 2021-04-24 04:36:12
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 672 ms / 2,000 ms
コード長 3,910 bytes
コンパイル時間 2,691 ms
コンパイル使用メモリ 209,920 KB
実行使用メモリ 130,348 KB
最終ジャッジ日時 2023-09-17 13:25:04
合計ジャッジ時間 7,974 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 198 ms
58,704 KB
testcase_14 AC 241 ms
76,248 KB
testcase_15 AC 132 ms
63,976 KB
testcase_16 AC 155 ms
39,516 KB
testcase_17 AC 116 ms
74,848 KB
testcase_18 AC 249 ms
76,220 KB
testcase_19 AC 219 ms
70,140 KB
testcase_20 AC 161 ms
58,524 KB
testcase_21 AC 101 ms
56,636 KB
testcase_22 AC 189 ms
45,868 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 346 ms
130,240 KB
testcase_26 AC 352 ms
130,348 KB
testcase_27 AC 352 ms
130,248 KB
testcase_28 AC 304 ms
128,392 KB
testcase_29 AC 383 ms
128,444 KB
testcase_30 AC 672 ms
130,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

template <typename Abelian>
struct FenwickTree2DSupportingRangeAddQuery {
  FenwickTree2DSupportingRangeAddQuery(int height_, int width_, const Abelian ID = 0) : height(height_), width(width_), ID(ID) {
    ++height; ++width;
    dat_const.assign(height, std::vector<Abelian>(width, ID));
    dat_linear[0].assign(height, std::vector<Abelian>(width, ID));
    dat_linear[1].assign(height, std::vector<Abelian>(width, ID));
    dat_quadratic.assign(height, std::vector<Abelian>(width, ID));
  }

  void add(int y1, int x1, int y2, int x2, const Abelian val) {
    ++y1; ++x1; ++y2; ++x2;
    for (int i = y1; i < height; i += i & -i) for (int j = x1; j < width; j += j & -j) {
      dat_const[i][j] += val * (y1 - 1) * (x1 - 1);
      dat_linear[0][i][j] -= val * (x1 - 1);
      dat_linear[1][i][j] -= val * (y1 - 1);
      dat_quadratic[i][j] += val;
    }
    for (int i = y1; i < height; i += i & -i) for (int j = x2 + 1; j < width; j += j & -j) {
      dat_const[i][j] -= val * (y1 - 1) * x2;
      dat_linear[0][i][j] += val * x2;
      dat_linear[1][i][j] += val * (y1 - 1);
      dat_quadratic[i][j] -= val;
    }
    for (int i = y2 + 1; i < height; i += i & -i) for (int j = x1; j < width; j += j & -j) {
      dat_const[i][j] -= val * y2 * (x1 - 1);
      dat_linear[0][i][j] += val * (x1 - 1);
      dat_linear[1][i][j] += val * y2;
      dat_quadratic[i][j] -= val;
    }
    for (int i = y2 + 1; i < height; i += i & -i) for (int j = x2 + 1; j < width; j += j & -j) {
      dat_const[i][j] += val * y2 * x2;
      dat_linear[0][i][j] -= val * x2;
      dat_linear[1][i][j] -= val * y2;
      dat_quadratic[i][j] += val;
    }
  }

  Abelian sum(int y, int x) const {
    ++y; ++x;
    Abelian quad = ID, cons = ID, line[2] = {ID, ID};
    for (int i = y; i > 0; i -= i & -i) for (int j = x; j > 0; j -= j & -j) {
      quad += dat_quadratic[i][j];
      line[0] += dat_linear[0][i][j];
      line[1] += dat_linear[1][i][j];
      cons += dat_const[i][j];
    }
    return quad * y * x + line[0] * y + line[1] * x + cons;
  }

  Abelian sum(int y1, int x1, int y2, int x2) const {
    return y1 <= y2 && x1 <= x2 ? sum(y2, x2) - sum(y2, x1 - 1) - sum(y1 - 1, x2) + sum(y1 - 1, x1 - 1) : ID;
  }

private:
  int height, width;
  const Abelian ID;
  std::vector<std::vector<Abelian>> dat_const, dat_quadratic;
  std::vector<std::vector<Abelian>> dat_linear[2];
};

int main() {
  int h, w, n, m;
  std::cin >> h >> w >> n >> m;
  std::vector<int> t(n), u(n), l(n), r(n), a(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> t[i] >> u[i] >> l[i] >> r[i] >> a[i];
    --t[i]; --u[i];
    --l[i]; --r[i];
  }
  FenwickTree2DSupportingRangeAddQuery<long long> bit(h, w);
  while (m--) {
    int x, y, b, c;
    std::cin >> x >> y >> b >> c;
    --x; --y;
    bit.add(std::max(x - b, 0), std::max(y - b, 0), std::min(x + b, h - 1), std::min(y + b, w - 1), c);
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += bit.sum(t[i], l[i], u[i], r[i]) < a[i];
  }
  std::cout << ans << '\n';
  return 0;
}
0