結果
| 問題 |
No.3214 small square
|
| コンテスト | |
| ユーザー |
nonon
|
| 提出日時 | 2025-09-17 22:39:33 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 5,003 bytes |
| コンパイル時間 | 4,144 ms |
| コンパイル使用メモリ | 313,572 KB |
| 実行使用メモリ | 46,732 KB |
| 最終ジャッジ日時 | 2025-09-17 22:40:05 |
| 合計ジャッジ時間 | 29,559 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 1 WA * 39 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool chmin(auto &a, auto b) { return a > b ? a = b, true : false; }
bool chmax(auto &a, auto b) { return a < b ? a = b, true : false; }
#include <ranges>
template<typename T, typename... Ts>
vector<T> merge_and_unique(const vector<T> &a, const Ts &...z) {
vector<T> res = a;
(res.insert(res.end(), z.begin(), z.end()), ...);
sort(res.begin(), res.end());
res.erase(unique(res.begin(), res.end()), res.end());
return res;
}
template<typename Abelian_Group>
struct fenwick_tree {
using M = Abelian_Group;
using S = typename M::S;
fenwick_tree() = default;
fenwick_tree(int _n) : fenwick_tree(vector<S>(_n, M::e())) {}
fenwick_tree(const vector<S> &_v) : n(_v.size()) {
d = vector<S>(n, M::e());
v = vector<S>(n, M::e());
for (int i = 1; i <= n; i++) {
v[i - 1] = _v[i - 1];
d[i - 1] += v[i - 1];
int j = i + (i & -i);
if (j <= n) d[j - 1] += d[i - 1];
}
}
void add(int p, S x) {
assert(0 <= p && p < n);
v[p] = M::op(v[p], x);
for (p++; p <= n; p += p & -p) {
d[p - 1] = M::op(d[p - 1], x);
}
}
void set(int p, S x) {
assert(0 <= p && p < n);
add(p, M::op(x, M::inv(v[p])));
}
S prod(int l, int r) const {
assert(0 <= l && l <= r && r <= n);
return prod(r) - prod(l);
}
private:
int n;
vector<S> d, v;
S prod(int p) const {
S res = M::e();
for (; p > 0; p -= p & -p) {
res = M::op(res, d[p - 1]);
}
return res;
}
};
template<typename Abelian_Group, typename T = int>
struct static_point_add_rectangle_sum {
using M = Abelian_Group;
using S = typename M::S;
static_point_add_rectangle_sum() = default;
static_point_add_rectangle_sum(int n, int q) {
xs.reserve(n);
ys.reserve(n);
ws.reserve(n);
xls.reserve(q);
yls.reserve(q);
xrs.reserve(q);
yrs.reserve(q);
}
void add_point(T x, T y, S w) {
xs.emplace_back(x);
ys.emplace_back(y);
ws.emplace_back(w);
}
void add_query(T xl, T yl, T xr, T yr) {
xls.emplace_back(xl);
yls.emplace_back(yl);
xrs.emplace_back(xr);
yrs.emplace_back(yr);
}
vector<S> solve() {
int n = xs.size(), q = xls.size();
if (n == 0 || q == 0) return vector<S>(q, M::e());
auto yb = merge_and_unique(ys);
for (T &y : ys) {
y = lower_bound(yb.begin(), yb.end(), y) - yb.begin();
}
vector<int> ord_pts(n), ord_query(2 * q);
iota(ord_pts.begin(), ord_pts.end(), 0);
iota(ord_query.begin(), ord_query.end(), 0);
ranges::sort(ord_pts, {}, [&](int i) { return xs[i]; });
ranges::sort(ord_query, {}, [&](int i) { return i < q ? xls[i] : xrs[i - q]; });
fenwick_tree<M> fw(yb.size());
vector<S> res(q);
int j = 0;
for (int i : ord_query) {
T x = (i < q ? xls[i] : xrs[i - q]);
while (j < n && xs[ord_pts[j]] < x) {
fw.add(ys[ord_pts[j]], ws[ord_pts[j]]);
j++;
}
if (i < q) {
int yl = lower_bound(yb.begin(), yb.end(), yls[i]) - yb.begin();
int yr = lower_bound(yb.begin(), yb.end(), yrs[i]) - yb.begin();
res[i] = M::op(res[i], M::inv(fw.prod(yl, yr)));
} else {
i -= q;
int yl = lower_bound(yb.begin(), yb.end(), yls[i]) - yb.begin();
int yr = lower_bound(yb.begin(), yb.end(), yrs[i]) - yb.begin();
res[i] = M::op(res[i], fw.prod(yl, yr));
}
}
return res;
}
private:
vector<T> xs, ys, xls, yls, xrs, yrs;
vector<S> ws;
};
template <typename T>
struct add_monoid {
using S = T;
static S op(const S &a, const S &b) {
return a + b;
}
static S e() { return 0; }
static S inv(const S &x) {
return -x;
}
static S pow(const S &x, long long k) {
return x * k;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, L;
cin >> N >> L;
L = 2 * L + 1;
static_point_add_rectangle_sum<add_monoid<ll>, ll> RS(N, 4 * N);
for (ll X, Y, V; N--; ) {
cin >> X >> Y >> V;
X = 2 * X, Y = 2 * X;
RS.add_point(X, Y, V);
RS.add_query(X, Y, X + L, Y + L);
RS.add_query(X, Y - L + 1, X + L, Y + 1);
RS.add_query(X - L + 1, Y, X + 1, Y + L);
RS.add_query(X - L + 1, Y - L + 1, X + 1, Y + 1);
RS.add_query(X + 1, Y + 1, X + L + 1, Y + L + 1);
RS.add_query(X + 1, Y - L, X + L + 1, Y);
RS.add_query(X - L, Y + 1, X, Y + L + 1);
RS.add_query(X - L, Y - L, X, Y);
}
ll ans = 0;
for (auto v : RS.solve()) chmax(ans, v);
cout << ans << endl;
}
nonon