結果

問題 No.1826 Fruits Collecting
ユーザー 沙耶花沙耶花
提出日時 2022-01-28 23:31:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 4,392 bytes
コンパイル時間 5,136 ms
コンパイル使用メモリ 286,936 KB
実行使用メモリ 235,680 KB
最終ジャッジ日時 2023-08-28 22:08:26
合計ジャッジ時間 45,982 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,356 KB
testcase_01 AC 7 ms
4,376 KB
testcase_02 AC 8 ms
4,412 KB
testcase_03 AC 11 ms
4,688 KB
testcase_04 AC 4 ms
4,356 KB
testcase_05 AC 785 ms
94,828 KB
testcase_06 AC 1,495 ms
173,928 KB
testcase_07 AC 928 ms
105,368 KB
testcase_08 AC 75 ms
13,780 KB
testcase_09 AC 1,279 ms
135,780 KB
testcase_10 AC 875 ms
102,612 KB
testcase_11 AC 838 ms
100,064 KB
testcase_12 AC 306 ms
45,268 KB
testcase_13 AC 137 ms
22,824 KB
testcase_14 AC 220 ms
30,668 KB
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 AC 2 ms
4,356 KB
testcase_26 AC 2 ms
4,352 KB
testcase_27 AC 1 ms
4,352 KB
testcase_28 AC 2 ms
4,352 KB
testcase_29 AC 2 ms
4,352 KB
testcase_30 AC 394 ms
51,664 KB
testcase_31 AC 869 ms
102,844 KB
testcase_32 AC 379 ms
50,148 KB
testcase_33 AC 1,550 ms
183,216 KB
testcase_34 AC 1,167 ms
126,012 KB
testcase_35 AC 226 ms
29,984 KB
testcase_36 AC 1,537 ms
184,008 KB
testcase_37 AC 655 ms
115,504 KB
testcase_38 AC 475 ms
92,188 KB
testcase_39 AC 707 ms
105,452 KB
testcase_40 AC 890 ms
126,076 KB
testcase_41 AC 177 ms
28,972 KB
testcase_42 AC 22 ms
6,228 KB
testcase_43 AC 2 ms
4,356 KB
testcase_44 AC 1 ms
4,352 KB
testcase_45 AC 2 ms
4,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0