#ifndef _DEBUG #define _DEBUG #include __FILE__ signed main() { int N, K; cin >> N >> K; vector> 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> 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 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 using namespace std; template class BIT_2D { private: const int n, m; vector> 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(m, 0)), bitx(n, vector(m, 0)), bity(n, vector(m, 0)), bitc(n, vector(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 bool cmin(A& a, const B& b) { if (a > b) return a = b, true; return false; } template bool cmax(A& a, const B& b) { if (a < b) return a = b, true; return false; } template ostream& operator<<(ostream& os, const pair& p); template ostream& operator<<(ostream& os, const tuple& t); template ostream& operator<<(ostream& os, const tuple& t); #define foreach(it, a) for (auto it = a.begin(); it != a.end(); it++) ostream& operator<<(ostream& os, const vector& vec) { os << "{"; foreach (it, vec) { os << (it == vec.begin() ? "" : " ") << *it; } return os << "}"; } template ostream& operator<<(ostream& os, const vector& vec) { os << "{"; foreach (it, vec) { os << (it == vec.begin() ? "" : ", ") << *it; } return os << "}"; } template ostream& operator<<(ostream& os, const vector >& vec) { os << "{\n"; foreach (it, vec) { os << (it == vec.begin() ? " " : "\n ") << *it; } return os << "\n}"; } template ostream& operator<<(ostream& os, const vector > >& vec) { os << "{\n"; foreach (it, vec) { os << (it == vec.begin() ? "" : "\n") << it - vec.begin() << ": " << *it; } return os << "\n}"; } template ostream& operator<<(ostream& os, const set& se) { os << "{"; foreach (it, se) { os << (it == se.begin() ? "" : ", ") << *it; } return os << "}"; } template ostream& operator<<(ostream& os, const multiset& ms) { os << "{"; foreach (it, ms) { os << (it == ms.begin() ? "" : ", ") << *it; } return os << "}"; } template ostream& operator<<(ostream& os, const map& ma) { os << "{"; foreach (it, ma) { os << (it == ma.begin() ? "" : ", ") << *it; } return os << "}"; } template ostream& operator<<(ostream& os, priority_queue pq) { os << "{"; while (!pq.empty()) { os << pq.top(), pq.pop(); if (!pq.empty()) os << ", "; } return os << "}"; } template ostream& operator<<(ostream& os, const pair& p) { const auto& [a, b] = p; return os << "(" << a << ", " << b << ")"; } template ostream& operator<<(ostream& os, const tuple& t) { const auto& [a, b, c] = t; return os << "(" << a << ", " << b << ", " << c << ")"; } template ostream& operator<<(ostream& os, const tuple& t) { const auto& [a, b, c, d] = t; return os << "(" << a << ", " << b << ", " << c << ", " << d << ")"; } void dump_func() {} template 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