結果

問題 No.1826 Fruits Collecting
ユーザー 👑 kmjpkmjp
提出日時 2022-01-28 23:07:46
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 176 ms / 2,000 ms
コード長 2,010 bytes
コンパイル時間 2,827 ms
コンパイル使用メモリ 217,148 KB
実行使用メモリ 34,836 KB
最終ジャッジ日時 2023-08-28 21:44:17
合計ジャッジ時間 9,110 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
19,244 KB
testcase_01 AC 8 ms
19,204 KB
testcase_02 AC 8 ms
19,312 KB
testcase_03 AC 8 ms
19,360 KB
testcase_04 AC 8 ms
19,380 KB
testcase_05 AC 63 ms
23,696 KB
testcase_06 AC 105 ms
27,424 KB
testcase_07 AC 74 ms
24,124 KB
testcase_08 AC 14 ms
20,044 KB
testcase_09 AC 103 ms
25,684 KB
testcase_10 AC 70 ms
23,916 KB
testcase_11 AC 68 ms
23,840 KB
testcase_12 AC 31 ms
21,524 KB
testcase_13 AC 19 ms
20,472 KB
testcase_14 AC 26 ms
21,028 KB
testcase_15 AC 161 ms
29,296 KB
testcase_16 AC 159 ms
29,212 KB
testcase_17 AC 162 ms
29,352 KB
testcase_18 AC 162 ms
29,360 KB
testcase_19 AC 160 ms
29,508 KB
testcase_20 AC 161 ms
29,236 KB
testcase_21 AC 159 ms
30,336 KB
testcase_22 AC 159 ms
29,784 KB
testcase_23 AC 164 ms
29,540 KB
testcase_24 AC 160 ms
29,444 KB
testcase_25 AC 7 ms
19,428 KB
testcase_26 AC 7 ms
19,296 KB
testcase_27 AC 7 ms
19,404 KB
testcase_28 AC 7 ms
19,428 KB
testcase_29 AC 7 ms
19,372 KB
testcase_30 AC 31 ms
21,212 KB
testcase_31 AC 55 ms
22,804 KB
testcase_32 AC 51 ms
23,100 KB
testcase_33 AC 176 ms
33,648 KB
testcase_34 AC 146 ms
28,488 KB
testcase_35 AC 35 ms
21,644 KB
testcase_36 AC 170 ms
33,544 KB
testcase_37 AC 109 ms
27,876 KB
testcase_38 AC 76 ms
26,292 KB
testcase_39 AC 106 ms
33,288 KB
testcase_40 AC 135 ms
34,836 KB
testcase_41 AC 34 ms
22,896 KB
testcase_42 AC 11 ms
20,024 KB
testcase_43 AC 7 ms
19,356 KB
testcase_44 AC 7 ms
19,360 KB
testcase_45 AC 7 ms
19,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

template<class V,int NV> class SegTree_1 {
public:
	vector<V> val;
	static V const def=-(1LL<<60);
	V comp(V l,V r){ return max(l,r);};
	
	SegTree_1(){val=vector<V>(NV*2,def);};
	V getval(int x,int y,int l=0,int r=NV,int k=1) { // x<=i<y
		if(r<=x || y<=l) return def;
		if(x<=l && r<=y) return val[k];
		return comp(getval(x,y,l,(l+r)/2,k*2),getval(x,y,(l+r)/2,r,k*2+1));
	}
	void update(int entry, V v) {
		entry += NV;
		val[entry]=comp(v,val[entry]); //上書きかチェック
		while(entry>1) entry>>=1, val[entry]=comp(val[entry*2],val[entry*2+1]);
	}
};
SegTree_1<ll,1<<20> st;
int N;
int T[202020],X[202020],V[202020];
int A[202020],B[202020];
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	vector<int> Ys;
	FOR(i,N) {
		cin>>T[i]>>X[i]>>V[i];
		A[i]=T[i]+X[i];
		B[i]=T[i]-X[i];
		if(A[i]<0||B[i]<0) continue;
		Ys.push_back(B[i]);
	}
	Ys.push_back(0);
	sort(ALL(Ys));
	vector<vector<int>> cand;
	FOR(i,N) {
		if(A[i]<0||B[i]<0) continue;
		B[i]=lower_bound(ALL(Ys),B[i])-Ys.begin();
		cand.push_back({A[i],B[i],V[i]});
	}
	sort(ALL(cand));
	st.update(0,0);
	ll ret=0;
	FORR(a,cand) {
		y=a[1];
		ll ma=st.getval(0,y+1)+a[2];
		ret=max(ret,ma);
		st.update(y,ma);
	}
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0