結果

問題 No.1014 competitive fighting
ユーザー kotatsugamekotatsugame
提出日時 2020-03-25 03:10:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 307 ms / 2,000 ms
コード長 2,289 bytes
コンパイル時間 1,563 ms
コンパイル使用メモリ 96,440 KB
実行使用メモリ 12,460 KB
最終ジャッジ日時 2023-09-21 19:28:38
合計ジャッジ時間 12,695 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 307 ms
12,064 KB
testcase_06 AC 304 ms
11,732 KB
testcase_07 AC 307 ms
11,784 KB
testcase_08 AC 305 ms
11,808 KB
testcase_09 AC 303 ms
11,668 KB
testcase_10 AC 244 ms
12,460 KB
testcase_11 AC 284 ms
11,268 KB
testcase_12 AC 305 ms
11,800 KB
testcase_13 AC 142 ms
7,428 KB
testcase_14 AC 130 ms
7,200 KB
testcase_15 AC 155 ms
7,684 KB
testcase_16 AC 8 ms
4,380 KB
testcase_17 AC 56 ms
4,816 KB
testcase_18 AC 250 ms
10,928 KB
testcase_19 AC 295 ms
11,608 KB
testcase_20 AC 104 ms
6,912 KB
testcase_21 AC 228 ms
10,680 KB
testcase_22 AC 184 ms
8,004 KB
testcase_23 AC 72 ms
5,184 KB
testcase_24 AC 74 ms
5,072 KB
testcase_25 AC 19 ms
4,376 KB
testcase_26 AC 220 ms
10,848 KB
testcase_27 AC 56 ms
4,888 KB
testcase_28 AC 62 ms
4,780 KB
testcase_29 AC 4 ms
4,500 KB
testcase_30 AC 295 ms
11,516 KB
testcase_31 AC 234 ms
10,612 KB
testcase_32 AC 4 ms
4,380 KB
testcase_33 AC 18 ms
4,380 KB
testcase_34 AC 207 ms
10,316 KB
testcase_35 AC 274 ms
11,364 KB
testcase_36 AC 188 ms
9,788 KB
testcase_37 AC 8 ms
4,380 KB
testcase_38 AC 170 ms
7,632 KB
testcase_39 AC 87 ms
5,400 KB
testcase_40 AC 167 ms
7,680 KB
testcase_41 AC 117 ms
6,856 KB
testcase_42 AC 262 ms
11,016 KB
testcase_43 AC 16 ms
4,384 KB
testcase_44 AC 237 ms
10,708 KB
testcase_45 AC 142 ms
7,160 KB
testcase_46 AC 26 ms
4,380 KB
testcase_47 AC 80 ms
5,280 KB
testcase_48 AC 195 ms
10,024 KB
testcase_49 AC 9 ms
4,376 KB
testcase_50 AC 250 ms
11,340 KB
testcase_51 AC 146 ms
7,176 KB
testcase_52 AC 10 ms
4,380 KB
testcase_53 AC 303 ms
11,784 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++)
	{
		for(int _=0;_<2;_++)
		{
			while(!Q.empty()&&(i+1==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(_==1)break;
			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