結果

問題 No.1014 competitive fighting
ユーザー 👑 kmjpkmjp
提出日時 2020-03-20 22:45:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 317 ms / 2,000 ms
コード長 1,964 bytes
コンパイル時間 1,826 ms
コンパイル使用メモリ 174,240 KB
実行使用メモリ 89,280 KB
最終ジャッジ日時 2023-09-21 19:19:42
合計ジャッジ時間 14,430 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
64,772 KB
testcase_01 AC 65 ms
64,928 KB
testcase_02 AC 66 ms
64,820 KB
testcase_03 AC 66 ms
64,840 KB
testcase_04 AC 66 ms
65,116 KB
testcase_05 AC 315 ms
72,804 KB
testcase_06 AC 316 ms
72,828 KB
testcase_07 AC 315 ms
72,796 KB
testcase_08 AC 312 ms
73,140 KB
testcase_09 AC 310 ms
72,960 KB
testcase_10 AC 317 ms
89,280 KB
testcase_11 AC 237 ms
65,980 KB
testcase_12 AC 308 ms
72,812 KB
testcase_13 AC 178 ms
68,824 KB
testcase_14 AC 168 ms
68,392 KB
testcase_15 AC 188 ms
69,080 KB
testcase_16 AC 70 ms
65,060 KB
testcase_17 AC 107 ms
66,116 KB
testcase_18 AC 263 ms
71,336 KB
testcase_19 AC 304 ms
72,600 KB
testcase_20 AC 146 ms
67,584 KB
testcase_21 AC 244 ms
70,732 KB
testcase_22 AC 212 ms
69,596 KB
testcase_23 AC 123 ms
66,700 KB
testcase_24 AC 124 ms
66,624 KB
testcase_25 AC 80 ms
65,216 KB
testcase_26 AC 239 ms
70,744 KB
testcase_27 AC 108 ms
66,256 KB
testcase_28 AC 113 ms
66,332 KB
testcase_29 AC 68 ms
64,940 KB
testcase_30 AC 299 ms
72,588 KB
testcase_31 AC 253 ms
70,952 KB
testcase_32 AC 68 ms
64,840 KB
testcase_33 AC 77 ms
64,824 KB
testcase_34 AC 198 ms
65,672 KB
testcase_35 AC 239 ms
65,884 KB
testcase_36 AC 184 ms
65,592 KB
testcase_37 AC 69 ms
64,812 KB
testcase_38 AC 173 ms
65,512 KB
testcase_39 AC 121 ms
65,120 KB
testcase_40 AC 173 ms
65,448 KB
testcase_41 AC 140 ms
65,304 KB
testcase_42 AC 236 ms
66,076 KB
testcase_43 AC 74 ms
64,860 KB
testcase_44 AC 220 ms
65,912 KB
testcase_45 AC 156 ms
65,320 KB
testcase_46 AC 81 ms
64,852 KB
testcase_47 AC 118 ms
65,252 KB
testcase_48 AC 193 ms
65,612 KB
testcase_49 AC 72 ms
64,820 KB
testcase_50 AC 228 ms
65,912 KB
testcase_51 AC 159 ms
65,460 KB
testcase_52 AC 72 ms
64,876 KB
testcase_53 AC 312 ms
72,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#undef _P
#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 ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int A[101010],B[101010],C[101010];
pair<int,int> P[201010];
int id[101010];


int RL[1<<20],RR[1<<20];
vector<int> E[1<<20];
ll dp[1<<20];
ll X[1<<20];

void add_edge(int cur,int L,int R,int from) {
	if(RR[cur]<=L) return;
	if(R<=RL[cur]) return;
	
	if(L<=RL[cur]&&RR[cur]<=R) {
		E[from].push_back(cur);
	}
	else {
		add_edge(cur*2,L,R,from);
		add_edge(cur*2+1,L,R,from);
	}
}

ll dfs(int cur) {
	if(dp[cur]>=0) return dp[cur];
	if(dp[cur]==-2) return dp[cur]=1LL<<60;
	dp[cur]=-2;
	ll ret=0;
	FORR(e,E[cur]) ret=max(ret,dfs(e));
	return dp[cur]=ret+X[cur];
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>A[i]>>B[i]>>C[i];
		P[i]={A[i],i};
	}
	sort(P,P+N);
	FOR(i,1<<19) {
		RL[(1<<19)+i]=i;
		RR[(1<<19)+i]=i+1;
	}
	for(i=(1<<19)-1;i>=1;i--) {
		E[i].push_back(2*i);
		E[i].push_back(2*i+1);
		RL[i]=RL[2*i];
		RR[i]=RR[2*i+1];
	}
	FOR(i,N) {
		id[P[i].second]=i;
	}
	FOR(i,N) {
		y=id[i];
		X[y+(1<<19)]=B[i];
		x=lower_bound(P,P+N,make_pair(B[i]-C[i]+1,0))-P;
		if(x<=y) {
			if(x) add_edge(1,0,x,y+(1<<19));
		}
		else {
			if(y) add_edge(1,0,y,y+(1<<19));
			if(y+1<x) add_edge(1,y+1,x,y+(1<<19));
		}
	}
	
	MINUS(dp);
	FOR(i,N) {
		ll ret=dfs((1<<19)+id[i]);
		if(ret>=1LL<<60) {
			cout<<"BAN"<<endl;
		}
		else {
			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