結果
| 問題 | No.60 魔法少女 |
| コンテスト | |
| ユーザー |
ninoinui
|
| 提出日時 | 2021-04-05 23:51:32 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 854 ms / 5,000 ms |
| コード長 | 5,533 bytes |
| 記録 | |
| コンパイル時間 | 3,631 ms |
| コンパイル使用メモリ | 210,756 KB |
| 最終ジャッジ日時 | 2025-01-20 12:08:11 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 10 |
ソースコード
#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
ninoinui