結果
問題 |
No.1014 competitive fighting
|
ユーザー |
![]() |
提出日時 | 2020-03-22 22:59:48 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 286 ms / 2,000 ms |
コード長 | 2,441 bytes |
コンパイル時間 | 6,252 ms |
コンパイル使用メモリ | 213,176 KB |
最終ジャッジ日時 | 2025-01-09 09:41:03 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 51 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T, class U> using Pa = pair<T, U>; template <class T> using vec = vector<T>; template <class T> using vvec = vector<vec<T>>; template<typename Monoid,typename F> class SegmentTree{ private: int sz; vector<Monoid> seg; const F op;//演算 const Monoid e;//単位元 public: SegmentTree(int n,const F op,const Monoid &e):op(op),e(e){ sz = 1; while(sz<=n) sz <<= 1; seg.assign(2*sz,e); } void set(int k, const Monoid &x){ seg[k+sz] = x; } void build(){ for(int i=sz-1;i>0;i--){ seg[i] = op(seg[2*i],seg[2*i+1]); } } void update(int k,const Monoid &x){ k += sz; seg[k] = x; while(k>>=1){ seg[k] = op(seg[2*k],seg[2*k+1]); } } Monoid query(int l,int r){ Monoid L = e,R = e; for(l+=sz,r+=sz;l<r;l>>=1,r>>=1){ if(l&1) L = op(L,seg[l++]); if(r&1) R = op(seg[--r],R); } return op(L,R); } Monoid operator[](const int &k)const{ return seg[k+sz]; } }; constexpr ll inf = 1e18; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vec<ll> A(N),B(N),C(N); map<ll,ll> cnt; for(int i=0;i<N;i++){ cin >> A[i] >> B[i] >> C[i]; cnt[A[i]]++; } vec<int> id(N); iota(id.begin(),id.end(),0); sort(id.begin(),id.end(),[&](int i,int j){ if(A[i]!=A[j]) return A[i]<A[j]; else return B[i]-C[i]<B[j]-C[j]; }); vec<ll> dp(N,-1); auto mymax = [](ll a,ll b){return max(a,b);}; SegmentTree<ll,decltype(mymax)> seg(N,mymax,0); for(int i=0;i<N;i++) seg.set(i,inf); seg.build(); priority_queue<Pa<ll,ll>,vec<Pa<ll,ll>>,greater<Pa<ll,ll>>> Q; for(int i=0;i<N;i++){ Q.push({B[id[i]]-C[id[i]],i}); ll ne = (i==N-1? inf:A[id[i+1]]); while(!Q.empty()){ auto p = Q.top(); if(p.first>=ne) break; Q.pop(); int r = partition_point(id.begin(),id.end(),[&](int x){return p.first>=A[x];})-id.begin(); seg.update(p.second,0); dp[id[p.second]] = min(inf,B[id[p.second]]+seg.query(0,r)); seg.update(p.second,dp[id[p.second]]); } } for(auto& x:dp){ if(x==inf) cout << "BAN\n"; else cout << x << "\n"; } }