結果
| 問題 |
No.1826 Fruits Collecting
|
| コンテスト | |
| ユーザー |
IKyopro
|
| 提出日時 | 2020-11-01 16:43:29 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 170 ms / 2,000 ms |
| コード長 | 2,807 bytes |
| コンパイル時間 | 2,801 ms |
| コンパイル使用メモリ | 209,704 KB |
| 最終ジャッジ日時 | 2025-01-15 18:44:51 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 43 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;}
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << " = " << (x) << endl;
template<typename Monoid,typename F>
class SegmentTree{
private:
int sz;
vector<Monoid> seg;
const F op;
const Monoid e;
public:
SegmentTree(int n,const F op,const Monoid &e):op(op),e(e){
sz = 1;
while(sz<=n) sz <<= 1;
seg.assign(2*sz,e);
}
void set(int k, const Monoid &x){
seg[k+sz] = x;
}
void build(){
for(int i=sz-1;i>0;i--){
seg[i] = op(seg[2*i],seg[2*i+1]);
}
}
void update(int k,const Monoid &x){
k += sz;
seg[k] = x;
while(k>>=1){
seg[k] = op(seg[2*k],seg[2*k+1]);
}
}
Monoid query(int l,int r){
Monoid L = e,R = e;
for(l+=sz,r+=sz;l<r;l>>=1,r>>=1){
if(l&1) L = op(L,seg[l++]);
if(r&1) R = op(seg[--r],R);
}
return op(L,R);
}
Monoid operator[](const int &k)const{
return seg[k+sz];
}
};
template<class T>
class Compress {
int N;
map<int,T> value;
vec<T> v;
vec<T> cmp;
public:
Compress(){}
void add(T x){v.push_back(x);}
void build(){
for(auto &x:v) cmp.push_back(x);
sort(cmp.begin(),cmp.end());
cmp.erase(unique(cmp.begin(),cmp.end()),cmp.end());
N = cmp.size();
}
int id(T val) {return lower_bound(cmp.begin(),cmp.end(),val)-cmp.begin();}
T val(int id) {return cmp[id];}
int size(){return N;}
};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vec<int> X,Y,V;
Compress<int> cx,cy;
for(int i=0;i<N;i++){
int t,x,v;
cin >> t >> x >> v;
if(t+x>=0 && t-x>=0){
X.push_back(t+x);
Y.push_back(t-x);
V.push_back(v);
cx.add(t+x);
cy.add(t-x);
}
}
N = X.size();
cx.add(0),cy.add(0);
cx.build(); cy.build();
int A = cx.size(),B = cy.size();
vvec<int> list(A);
for(int i=0;i<N;i++){
list[cx.id(X[i])].push_back(i);
}
ll inf = 1e18;
SegmentTree seg(B,[](ll a,ll b){return max(a,b);},-inf);
seg.set(cy.id(0),0);
seg.build();
for(int x=0;x<A;x++){
sort(all(list[x]),[&](int i,int j){return Y[i]<Y[j];});
for(auto& id:list[x]){
int y = cy.id(Y[id]);
seg.update(y,seg.query(0,y+1)+V[id]);
}
}
cout << seg.query(0,B) << "\n";
}
IKyopro