結果

問題 No.1014 competitive fighting
ユーザー kotatsugamekotatsugame
提出日時 2020-03-25 03:14:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 303 ms / 2,000 ms
コード長 2,228 bytes
コンパイル時間 1,271 ms
コンパイル使用メモリ 95,664 KB
実行使用メモリ 12,268 KB
最終ジャッジ日時 2023-09-21 19:29:51
合計ジャッジ時間 12,106 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 301 ms
11,672 KB
testcase_06 AC 302 ms
11,672 KB
testcase_07 AC 300 ms
12,004 KB
testcase_08 AC 301 ms
11,672 KB
testcase_09 AC 302 ms
12,028 KB
testcase_10 AC 245 ms
12,268 KB
testcase_11 AC 285 ms
11,336 KB
testcase_12 AC 303 ms
11,856 KB
testcase_13 AC 142 ms
7,300 KB
testcase_14 AC 130 ms
7,188 KB
testcase_15 AC 156 ms
7,488 KB
testcase_16 AC 7 ms
4,380 KB
testcase_17 AC 55 ms
4,768 KB
testcase_18 AC 246 ms
10,900 KB
testcase_19 AC 294 ms
11,664 KB
testcase_20 AC 104 ms
6,668 KB
testcase_21 AC 223 ms
10,628 KB
testcase_22 AC 188 ms
8,004 KB
testcase_23 AC 73 ms
5,028 KB
testcase_24 AC 75 ms
5,020 KB
testcase_25 AC 19 ms
4,376 KB
testcase_26 AC 222 ms
10,464 KB
testcase_27 AC 55 ms
4,832 KB
testcase_28 AC 62 ms
4,780 KB
testcase_29 AC 4 ms
4,376 KB
testcase_30 AC 292 ms
11,648 KB
testcase_31 AC 232 ms
10,660 KB
testcase_32 AC 4 ms
4,380 KB
testcase_33 AC 18 ms
4,376 KB
testcase_34 AC 206 ms
10,356 KB
testcase_35 AC 272 ms
11,224 KB
testcase_36 AC 186 ms
10,096 KB
testcase_37 AC 8 ms
4,380 KB
testcase_38 AC 170 ms
7,808 KB
testcase_39 AC 88 ms
5,340 KB
testcase_40 AC 167 ms
7,744 KB
testcase_41 AC 118 ms
6,960 KB
testcase_42 AC 264 ms
10,996 KB
testcase_43 AC 16 ms
4,376 KB
testcase_44 AC 239 ms
10,924 KB
testcase_45 AC 142 ms
7,156 KB
testcase_46 AC 26 ms
4,376 KB
testcase_47 AC 81 ms
5,400 KB
testcase_48 AC 195 ms
9,964 KB
testcase_49 AC 10 ms
4,380 KB
testcase_50 AC 250 ms
10,964 KB
testcase_51 AC 146 ms
7,160 KB
testcase_52 AC 10 ms
4,380 KB
testcase_53 AC 303 ms
11,856 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:57:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   57 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;
#include<vector>
#include<functional>
#include<limits>
template<typename T>
struct segtree{
	using F=function<T(T,T)>;
	const F calcfn,updatefn;
	int n;
	T defvalue;
	vector<T>dat;
	segtree(int n_=0,T defvalue_=numeric_limits<T>::max(),
		const F calcfn_=[](T a,T b){return a<b?a:b;},
		const F updatefn_=[](T a,T b){return b;}
	):defvalue(defvalue_),calcfn(calcfn_),updatefn(updatefn_)
	{
		n=1;
		while(n<n_)n<<=1;
		dat.assign(2*n-1,defvalue);
	}
	void copy(const vector<T>&v)
	{
		for(int i=0;i<v.size();i++)dat[i+n-1]=v[i];
		for(int i=n-2;i>=0;i--)dat[i]=calcfn(dat[i*2+1],dat[i*2+2]);
	}
	void update(int i,T a)
	{
		i+=n-1;
		dat[i]=updatefn(dat[i],a);
		while(i>0)
		{
			i=(i-1)/2;
			dat[i]=calcfn(dat[2*i+1],dat[2*i+2]);
		}
	}
	T query(int a,int b)//[a,b)
	{
		int L=(a<0?0:a>n?n:a)+n-1;
		int R=(b<0?0:b>n?n:b)+n-1;
		T lret=defvalue,rret=defvalue;
		for(;L<R;L>>=1,R>>=1)
		{
			if(!(L&1))lret=calcfn(lret,dat[L]);
			if(!(R&1))rret=calcfn(dat[--R],rret);
		}
		return calcfn(lret,rret);
	}
};
int N;
int A[1<<17],B[1<<17],C[1<<17];
bool usd[1<<17];
long ans[1<<17];
main()
{
	cin>>N;
	vector<pair<int,int> >ai(N);
	for(int i=0;i<N;i++)
	{
		cin>>A[i]>>B[i]>>C[i];
		ai[i]=make_pair(A[i],i);
	}
	sort(ai.begin(),ai.end());
	segtree<pair<long,int> >P(N,make_pair(0,N),[](pair<long,int>a,pair<long,int>b){return a<b?b:a;});
	vector<pair<long,int> >Pin(N);
	for(int i=0;i<N;i++)Pin[i]=make_pair(1e18,i);
	P.copy(Pin);
	priority_queue<pair<int,int> >Q;
	for(int i=0;i<=N;i++)
	{
		while(!Q.empty()&&(i==N||-Q.top().first<ai[i].first))
		{
			int V=-Q.top().first;
			int id=-Q.top().second;
			Q.pop();
			if(!usd[id])
			{
				int R=upper_bound(ai.begin(),ai.end(),make_pair(V,N))-ai.begin();
				pair<long,int>q=P.query(0,R);
				if(q.second==id)
				{
					q=max(P.query(0,id),P.query(id+1,R));
				}
				usd[q.second]=true;
				P.update(id,make_pair(B[ai[id].second]+q.first,id));
			}
		}
		if(i<N)Q.push(make_pair(C[ai[i].second]-B[ai[i].second],-i));
	}
	for(int i=0;i<N;i++)
	{
		ans[ai[i].second]=P.query(i,i+1).first;
	}
	for(int i=0;i<N;i++)
	{
		if(ans[i]<1e18)cout<<ans[i]<<endl;
		else cout<<"BAN"<<endl;
	}
}
0