結果
| 問題 |
No.3214 small square
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-07-25 22:42:07 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,304 bytes |
| コンパイル時間 | 2,554 ms |
| コンパイル使用メモリ | 212,212 KB |
| 実行使用メモリ | 25,860 KB |
| 最終ジャッジ日時 | 2025-07-25 22:42:19 |
| 合計ジャッジ時間 | 11,398 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 WA * 4 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const int N = 200005;
const ll INF = 0x3f3f3f3f3f3f3f3f;
#define int long long
struct Event {
ll x;
int y1, y2;
ll d;
bool operator<(Event const& o) const {
if (x != o.x) return x < o.x;
return d > o.d;
}
};
struct SegTree {
struct Node {
ll val, tag;
};
int n;
vector<Node> st;
SegTree(int _n) : n(_n), st(4 * n + 4, {0, 0}) {}
void gx(int u, ll v) {
st[u].val += v;
st[u].tag += v;
}
void pushdown(int u) {
if (st[u].tag != 0) {
gx(u << 1, st[u].tag);
gx(u << 1 | 1, st[u].tag);
st[u].tag = 0;
}
}
void pushup(int u) {
st[u].val = max(st[u << 1].val, st[u << 1 | 1].val);
}
void update(int u, int l, int r, int x, int y, ll v) {
if (y <= l || r <= x) return;
if (x <= l && r <= y) {
gx(u, v);
return;
}
pushdown(u);
int mid = l + r >> 1;
update(u << 1, l, mid, x, y, v);
update(u << 1 | 1, mid, r, x, y, v);
pushup(u);
}
ll query_max() const {
return st[1].val;
}
};
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
ll A;
cin >> n >> A;
vector<ll> X(n), Y(n), V(n);
for (int i = 0; i < n; i++) cin >> X[i] >> Y[i] >> V[i];
vector<ll> ys;
ys.reserve(2 * n);
for (int i = 0; i < n; i++) {
ys.push_back(Y[i]);
ys.push_back(Y[i] + A);
}
sort(ys.begin(), ys.end());
ys.erase(unique(ys.begin(), ys.end()), ys.end());
auto cal = [&](ll y) {
return lower_bound(ys.begin(), ys.end(), y) - ys.begin();
};
vector<Event> ev;
ev.reserve(2 * n);
for (int i = 0; i < n; i++) {
ll xs = X[i] - A;
ll xe = X[i];
int y1 = cal(Y[i]), y2 = cal(Y[i] + A) + 1;
ev.push_back({xs, y1, y2, V[i]});
ev.push_back({xe, y1, y2, -V[i]});
}
sort(ev.begin(), ev.end());
SegTree st((int)ys.size() + 2);
ll ans = -INF;
for (auto& e : ev) {
st.update(1, 0, st.n, e.y1, e.y2, e.d);
ans = max(ans, st.query_max());
}
cout << max(ans, 0LL) << "\n";
return 0;
}