結果
| 問題 |
No.1826 Fruits Collecting
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2022-01-28 23:31:02 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 4,392 bytes |
| コンパイル時間 | 5,751 ms |
| コンパイル使用メモリ | 277,332 KB |
| 最終ジャッジ日時 | 2025-01-27 17:28:26 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 33 TLE * 10 |
ソースコード
#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define Inf 1000000000000000001;
template <class S, S (*op)(S, S), S (*e)()> struct compressed_segtree {
segtree<S,op,e> seg;
compressed_segtree() : compressed_segtree(vector<long long>(0)) {
}
compressed_segtree(vector<long long> tx, vector<S> v){
_tx = tx;
seg = segtree<S,op,e>(v);
}
compressed_segtree(vector<long long> tx){
_tx = tx;
seg = segtree<S,op,e>(tx.size());
}
int lower_ind(long long p){
return distance(_tx.begin(),lower_bound(_tx.begin(),_tx.end(),p));
}
void set(long long p, S x) {
seg.set(lower_ind(p), x);
}
S get(long long p) {
int idx = lower_ind(p);
if(idx!=_tx.size()&&_tx[idx]==p)return seg.get(idx);
return e();
}
S prod(long long l,long long r) {
return seg.prod(lower_ind(l),lower_ind(r));
}
S all_prod() { return seg.all_prod(); }
vector<long long> _tx;
};
template <class S, S (*op)(S, S), S (*e)()> struct compressed_2d_segtree {
vector<compressed_segtree<S,op,e>> seg;
compressed_2d_segtree() : compressed_2d_segtree(vector<long long>(0)) {
}
/*
compressed_2d_segtree(vector<long long> tx, vector<S> v){
_tx = tx;
seg = segtree<S,op,e>(v);
}
*/
compressed_2d_segtree(vector<pair<long long,long long>> tp){
_tp = tp;
rep(i,tp.size()){
_tx.push_back(tp[i].first);
_ty.push_back(tp[i].second);
}
sort(_tx.begin(),_tx.end());
_tx.erase(unique(_tx.begin(),_tx.end()),_tx.end());
sort(_ty.begin(),_ty.end());
_ty.erase(unique(_ty.begin(),_ty.end()),_ty.end());
int n = _tx.size();
log = 0;
while((1LL<<log) < n){
log++;
}
size = 1<<log;
seg.resize(size*2);
vector<vector<long long>> ys(size*2);
rep(i,tp.size()){
ys[size + lower_indx(tp[i].first)].push_back(tp[i].second);
}
for(int i=size;i<size*2;i++){
sort(ys[i].begin(),ys[i].end());
ys[i].erase(unique(ys[i].begin(),ys[i].end()),ys[i].end());
seg[i] = compressed_segtree<S,op,e>(ys[i]);
}
for(int i=size-1;i>=1;i--){
vector<long long> a(ys[i*2].rbegin(),ys[i*2].rend()), b(ys[i*2+1].rbegin(),ys[i*2+1].rend());
while(a.size()>0||b.size()>0){
if(a.size()==0){
swap(a,b);
}
else if(b.size()>0){
if(a.back()>b.back())swap(a,b);
}
if(ys[i].size()==0||ys[i].back()!=a.back())ys[i].push_back(a.back());
a.pop_back();
}
seg[i] = compressed_segtree<S,op,e>(ys[i]);
ys[i*2].clear();
ys[i*2+1].clear();
}
}
int lower_indx(long long p){
return distance(_tx.begin(),lower_bound(_tx.begin(),_tx.end(),p));
}
int lower_indy(long long p){
return distance(_ty.begin(),lower_bound(_ty.begin(),_ty.end(),p));
}
void set(long long px, long long py, S x) {
px = lower_indx(px) + size;
seg[px].set(py,x);
for (int i = 1; i <= log; i++) update(px >> i, py);
}
S get(long long px, long long py) {
int idx = lower_indx(px);
if(idx!=_tx.size()&&_tx[idx]==px)return seg[idx+size].get(py);
return e();
}
S prod(long long lx,long long rx, long long ly, long long ry) {
S sml = e(), smr = e();
lx = lower_indx(lx)+size;
rx = lower_indx(rx)+size;
while (lx < rx) {
if (lx & 1) sml = op(sml, seg[lx++].prod(ly,ry));
if (rx & 1) smr = op(seg[--rx].prod(ly,ry), smr);
lx >>= 1;
rx >>= 1;
}
return op(sml, smr);
}
S all_prod() { return seg[1].all_prod(); }
int size, log;
vector<pair<long long,long long>> _tp;
vector<long long> _tx,_ty;
void update(int k, long long py) {
seg[k].set(py, op(seg[2*k].get(py), seg[2*k+1].get(py)));
}
};
long long op(long long a,long long b){
return max(a,b);
}
long long e(){
return -Inf;
}
int main(){
int n;
cin>>n;
vector<array<long long,3>> a(n);
vector<pair<long long,long long>> xx;
rep(i,n){
long long t,x,v;
cin>>t>>x>>v;
a[i][0] = t+x;
a[i][1] = t-x;
a[i][2] = v;
xx.emplace_back(t+x,t-x);
}
xx.emplace_back(0,0);
compressed_2d_segtree<long long,op,e> seg(xx);
seg.set(0,0,0);
sort(a.begin(),a.end());
rep(i,n){
long long v = seg.prod(-3000000000,a[i][0]+1,-3000000000,a[i][1]+1);
v += a[i][2];
seg.set(a[i][0],a[i][1],max(v,seg.get(a[i][0],a[i][1])));
}
cout<<seg.all_prod()<<endl;
return 0;
}
沙耶花