結果

問題 No.60 魔法少女
ユーザー ninoinuininoinui
提出日時 2021-04-05 23:51:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 433 ms / 5,000 ms
コード長 5,533 bytes
コンパイル時間 2,591 ms
コンパイル使用メモリ 220,624 KB
実行使用メモリ 77,056 KB
最終ジャッジ日時 2024-06-10 11:52:40
合計ジャッジ時間 6,896 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
73,984 KB
testcase_01 AC 56 ms
73,984 KB
testcase_02 AC 55 ms
73,984 KB
testcase_03 AC 56 ms
73,984 KB
testcase_04 AC 280 ms
75,648 KB
testcase_05 AC 262 ms
75,776 KB
testcase_06 AC 432 ms
77,056 KB
testcase_07 AC 335 ms
76,160 KB
testcase_08 AC 229 ms
75,264 KB
testcase_09 AC 125 ms
74,624 KB
testcase_10 AC 391 ms
76,672 KB
testcase_11 AC 83 ms
74,240 KB
testcase_12 AC 190 ms
75,264 KB
testcase_13 AC 433 ms
76,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifndef _DEBUG
#define _DEBUG
#include __FILE__

signed main() {
  int N, K;
  cin >> N >> K;
  vector<tuple<int, int, int>> V(N);
  for (int i = 0; i < N; i++) {
    int a, b, c;
    cin >> a >> b >> c, a += 500, b += 500;
    V.at(i) = {a, b, c};
  }
  vector<tuple<int, int, int, int, int>> V2(K);
  for (int i = 0; i < K; i++) {
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e, a += 500, b += 500;
    V2.at(i) = {a, b, c, d, e};
  }

  int MX = 1501;
  BIT_2D<long> B2(MX, MX);
  for (const auto& [a, b, c, d, e] : V2) {
    B2.add(a, b, a + c + 1, b + d + 1, e);
  }
  
  long ans = 0;
  for (const auto& [a, b, c] : V) {
    auto d = B2.sum(a, b, a + 1, b + 1);
    ans += max(0L, c - d);
  }
  cout << ans << "\n";
}

#else
// #undef _DEBUG
#pragma GCC diagnostic warning "-Wextra"
#pragma GCC diagnostic warning "-Wshadow"
#include <bits/stdc++.h>
using namespace std;

template <typename T> class BIT_2D {
private:
  const int n, m;
  vector<vector<T>> bitxy, bitx, bity, bitc;

  void add(const int i, const int j, const T valxy, const T valx, const T valy, const T valc) {
    for (int i_ = i + 1; i_ < n; i_ += i_ & -i_)
      for (int j_ = j + 1; j_ < m; j_ += j_ & -j_) bitxy[i_][j_] += valxy, bitx[i_][j_] += valx, bity[i_][j_] += valy, bitc[i_][j_] += valc;
  }

  T sum(const int i, const int j) {
    T s = 0;
    for (int i_ = i + 1; i_ > 0; i_ -= i_ & -i_)
      for (int j_ = j + 1; j_ > 0; j_ -= j_ & -j_) s += bitxy[i_][j_] * i * j + bitx[i_][j_] * i + bity[i_][j_] * j + bitc[i_][j_];
    return s;
  }

public:
  BIT_2D(const int sz1, const int sz2) : n(sz1 + 1), m(sz2 + 1), bitxy(n, vector<T>(m, 0)), bitx(n, vector<T>(m, 0)), bity(n, vector<T>(m, 0)), bitc(n, vector<T>(m, 0)) {}

  void add(const int lx, const int ly, const int rx, const int ry, const T val) {
    add(lx, ly, val, -val * (ly - 1), -val * (lx - 1), val * (lx - 1) * (ly - 1));
    add(rx, ly, -val, val * (ly - 1), val * (rx - 1), -val * (rx - 1) * (ly - 1));
    add(lx, ry, -val, val * (ry - 1), val * (lx - 1), -val * (lx - 1) * (ry - 1));
    add(rx, ry, val, -val * (ry - 1), -val * (rx - 1), val * (rx - 1) * (ry - 1));
  }

  T sum(const int lx, const int ly, const int rx, const int ry) { return sum(rx - 1, ry - 1) - sum(lx - 1, ry - 1) - sum(rx - 1, ly - 1) + sum(lx - 1, ly - 1); }
  void print() {
    for (int i = 0; i < n - 1; ++i) {
      for (int j = 0; j < m - 1; ++j) {
        cout << sum(i, j, i + 1, j + 1) << " ";
      }
      cout << endl;
    }
  }
};

struct io_setup {
  io_setup() { cin.tie(nullptr)->sync_with_stdio(false); }
} io_setup;

template <class A, class B> bool cmin(A& a, const B& b) {
  if (a > b) return a = b, true;
  return false;
}

template <class A, class B> bool cmax(A& a, const B& b) {
  if (a < b) return a = b, true;
  return false;
}

template <class A, class B> ostream& operator<<(ostream& os, const pair<A, B>& p);

template <class A, class B, class C> ostream& operator<<(ostream& os, const tuple<A, B, C>& t);

template <class A, class B, class C, class D> ostream& operator<<(ostream& os, const tuple<A, B, C, D>& t);

#define foreach(it, a) for (auto it = a.begin(); it != a.end(); it++)

ostream& operator<<(ostream& os, const vector<char>& vec) {
  os << "{";
  foreach (it, vec) { os << (it == vec.begin() ? "" : " ") << *it; }
  return os << "}";
}

template <class A> ostream& operator<<(ostream& os, const vector<A>& vec) {
  os << "{";
  foreach (it, vec) { os << (it == vec.begin() ? "" : ", ") << *it; }
  return os << "}";
}

template <class A> ostream& operator<<(ostream& os, const vector<vector<A> >& vec) {
  os << "{\n";
  foreach (it, vec) { os << (it == vec.begin() ? " " : "\n ") << *it; }
  return os << "\n}";
}

template <class A> ostream& operator<<(ostream& os, const vector<vector<vector<A> > >& vec) {
  os << "{\n";
  foreach (it, vec) { os << (it == vec.begin() ? "" : "\n") << it - vec.begin() << ": " << *it; }
  return os << "\n}";
}

template <class A> ostream& operator<<(ostream& os, const set<A>& se) {
  os << "{";
  foreach (it, se) { os << (it == se.begin() ? "" : ", ") << *it; }
  return os << "}";
}

template <class A> ostream& operator<<(ostream& os, const multiset<A>& ms) {
  os << "{";
  foreach (it, ms) { os << (it == ms.begin() ? "" : ", ") << *it; }
  return os << "}";
}

template <class A, class B> ostream& operator<<(ostream& os, const map<A, B>& ma) {
  os << "{";
  foreach (it, ma) { os << (it == ma.begin() ? "" : ", ") << *it; }
  return os << "}";
}

template <class A> ostream& operator<<(ostream& os, priority_queue<A> pq) {
  os << "{";
  while (!pq.empty()) {
    os << pq.top(), pq.pop();
    if (!pq.empty()) os << ", ";
  }
  return os << "}";
}

template <class A, class B> ostream& operator<<(ostream& os, const pair<A, B>& p) {
  const auto& [a, b] = p;
  return os << "(" << a << ", " << b << ")";
}

template <class A, class B, class C> ostream& operator<<(ostream& os, const tuple<A, B, C>& t) {
  const auto& [a, b, c] = t;
  return os << "(" << a << ", " << b << ", " << c << ")";
}

template <class A, class B, class C, class D> ostream& operator<<(ostream& os, const tuple<A, B, C, D>& t) {
  const auto& [a, b, c, d] = t;
  return os << "(" << a << ", " << b << ", " << c << ", " << d << ")";
}

void dump_func() {}
template <class A, class... B> void dump_func(const A& a, const B&... b) {
  cout << a << (sizeof...(b) ? ", " : "\n");
  dump_func(b...);
}

#ifdef _DEBUG
#define dump(...) cout << "[" << (#__VA_ARGS__) << "]: ", dump_func(__VA_ARGS__)
#else
#define dump(...)
#endif
#endif
0