結果
| 問題 |
No.1826 Fruits Collecting
|
| コンテスト | |
| ユーザー |
pockyny
|
| 提出日時 | 2022-01-28 22:50:10 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 6,105 bytes |
| コンパイル時間 | 3,039 ms |
| コンパイル使用メモリ | 225,992 KB |
| 最終ジャッジ日時 | 2025-01-27 17:15:07 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 WA * 16 |
ソースコード
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
typedef long long ll;
#define def 0
using V = ll;
V comp(V& l, V& r) { return max(l,r); };
struct SegTree { //[l,r)
int NV;
vector<V> val;
void init(int n) {
NV = 1;
while (NV < n) NV *= 2;
val = vector<V>(NV * 2, def);
}
V get(int x, int y, int l, int r, int k) {
if (r <= x || y <= l) return def; if (x <= l&&r <= y)return val[k];
auto a = get(x, y, l, (l + r) / 2, k * 2); auto b = get(x, y, (l + r) / 2, r, k * 2 + 1); return comp(a, b);
}
V get(int x, int y) { return get(x, y, 0, NV, 1); }
void update(int i, V v) { i += NV; val[i] = v; while (i>1)i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]); }
void add(int i, V v) { update(i, val[i + NV] + v); }
V operator[](int x) { return get(x, x + 1); }
};
struct Healthy2DSegTree {
int NV;
vector<SegTree> st;
vector<vector<int>> index;
void init(vector<vector<int>> &v) {
int n = v.size();
NV = 1; while (NV < n) NV *= 2;
index.resize(2 * NV);
rep(i, 0, n) fore(j, v[i]) index[i + NV].push_back(j);
rrep(i, NV * 2 - 1, 1) {
sort(index[i].begin(), index[i].end());
index[i].erase(unique(index[i].begin(), index[i].end()), index[i].end());
fore(j, index[i]) index[i / 2].push_back(j);
}
st.resize(2 * NV);
rep(i, 1, NV * 2) st[i].init(index[i].size());
}
void update(int x, int y, V v) {
assert(x < NV);
x += NV;
while (x) {
int yy = lower_bound(index[x].begin(), index[x].end(), y) - index[x].begin();
assert(yy != index[x].size());
assert(y == index[x][yy]);
st[x].update(yy, v);
x >>= 1;
}
}
void add(int x, int y, V v) {
assert(x < NV);
x += NV;
while (x) {
int yy = lower_bound(index[x].begin(), index[x].end(), y) - index[x].begin();
assert(yy != index[x].size());
assert(y == index[x][yy]);
st[x].add(yy, v);
x >>= 1;
}
}
V get(int sx, int tx, int sy, int ty, int k, int l, int r) {
assert(k < NV * 2);
assert(l < r);
if (r <= sx or tx <= l) return def;
if (sx <= l and r <= tx) {
int syy = lower_bound(index[k].begin(), index[k].end(), sy) - index[k].begin();
int tyy = lower_bound(index[k].begin(), index[k].end(), ty) - index[k].begin();
return st[k].get(syy, tyy);
}
int md = (l + r) / 2;
V le = get(sx, tx, sy, ty, k * 2, l, md);
V ri = get(sx, tx, sy, ty, k * 2 + 1, md, r);
return comp(le, ri);
}
V get(int sx, int tx, int sy, int ty) {
return get(sx, tx, sy, ty, 1, 0, NV);
}
};
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
//int H, W, Q;
//vector<vector<int>> query;
//---------------------------------------------------------------------------------------------------
ll t[200010],x[200010],v[200010];
void _main(){
int i,n; cin >> n;
for(i=0;i<n;i++) cin >> t[i] >> x[i] >> v[i];
vector<ll> a(n),b(n);
for(i=0;i<n;i++){
a[i] = t[i] + x[i]; b[i] = t[i] - x[i];
}
sort(a.begin(),a.end()); sort(b.begin(),b.end());
vector<pair<ll,pair<ll,ll>>> w(n);
vector<vector<int>> index(n);
for(i=0;i<n;i++){
w[i] = {t[i],{x[i],v[i]}};
int xx = lower_bound(a.begin(),a.end(),t[i] + x[i]) - a.begin();
int yy = lower_bound(b.begin(),b.end(),t[i] - x[i]) - b.begin();
index[xx].push_back(yy);
}
sort(w.begin(),w.end());
Healthy2DSegTree st;
st.init(index);
for(i=0;i<n;i++){
if(w[i].first<abs(w[i].second.first)) continue;
ll aa = w[i].first + w[i].second.first,bb = w[i].first - w[i].second.first;
ll xx = lower_bound(a.begin(),a.end(),aa) - a.begin();
ll yy = lower_bound(b.begin(),b.end(),bb) - b.begin();
ll mx = st.get(0,xx + 1,0,yy + 1) + w[i].second.second;
ll mx2 = st.get(xx,xx + 1,yy,yy + 1);
if(mx2<=mx){
st.add(xx,yy,-mx2);
st.add(xx,yy,mx);
}
}
cout << st.get(0,n,0,n) << endl;
}
/*void _main() {
cin >> H >> W >> Q;
rep(i, 0, Q) {
int t; cin >> t;
if (t == 1) {
int x, y, v; cin >> x >> y >> v;
query.push_back({ t, x, y, v });
}
else {
int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;
query.push_back({ t, sx, sy, tx, ty });
}
}
Healthy2DSegTree st;
vector<vector<int>> index(W);
rep(i, 0, Q) {
if (query[i][0] == 1) {
int x = query[i][1];
int y = query[i][2];
index[x].push_back(y);
}
}
st.init(index);
rep(i, 0, Q) {
if (query[i][0] == 1) {
int x = query[i][1];
int y = query[i][2];
int v = query[i][3];
st.add(x, y, v);
} else {
int sx = query[i][1];
int sy = query[i][2];
int tx = query[i][3];
int ty = query[i][4];
ll ans = st.get(sx, tx + 1, sy, ty + 1);
printf("%lld\n", ans);
}
}
}*/
pockyny