結果

問題 No.1014 competitive fighting
ユーザー ChanyuhChanyuh
提出日時 2020-05-05 20:42:46
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,837 bytes
コンパイル時間 1,436 ms
コンパイル使用メモリ 117,484 KB
実行使用メモリ 9,316 KB
最終ジャッジ日時 2023-09-09 10:18:45
合計ジャッジ時間 14,268 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 224 ms
9,044 KB
testcase_11 AC 195 ms
9,036 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

template <typename T>
struct SegmentTree{
  using F = function<T(T,T)>;
  int n;
  F f;//二項演算
  T ti;//単位元
  vector<T> dat;

  SegmentTree(){}
  SegmentTree(F f,T ti):f(f),ti(ti){}

  void init(int n_){//sizeがn_のsegtreeを作る
    n=1;
    while(n<n_) n<<=1;
    dat.assign(n<<1,ti);
  }

  void build(const vector<T> &v){//vによってsegtreeをbuildする
    int n_=v.size();
    init(n_);
    for(int i=0;i<n_;i++) dat[n+i]=v[i];
    for(int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }

  void set_val(int k,T x){//k番目をxにする
    dat[k+=n]=x;
    while(k>>=1)
      dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);
  }

  T query(int a,int b){//区間[a,b)に対しFを適応した値を返す
    if(a>=b) return ti;
    T vl=ti,vr=ti;
    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,dat[l++]);
      if(r&1) vr=f(dat[--r],vr);
    }
    return f(vl,vr);
  }

  template<typename C>
  int find(int st,C &check,T &acc,int k,int l,int r){//
    if(l+1==r){
      acc=f(acc,dat[k]);
      return check(acc)?k-n:-1;
    }
    int m=(l+r)>>1;
    if(m<=st) return find(st,check,acc,(k<<1)|1,m,r);
    if(st<=l&&!check(f(acc,dat[k]))){
      acc=f(acc,dat[k]);
      return -1;
    }
    int vl=find(st,check,acc,(k<<1)|0,l,m);
    if(~vl) return vl;
    return find(st,check,acc,(k<<1)|1,m,r);
  }

  template<typename C>
  int find(int st,C &check){
    T acc=ti;
    return find(st,check,acc,1,0,n);
  }

  T &operator [] (int i) {return dat[i+n];};
};


int n;
vector<P> as;
int b[100010],c[100010];
int s[100010],inv[100010];
int down[100010];

void solve(){
  cin >> n;
  rep(i,n){
    int a;cin >> a;
    as.emplace_back(a,i);
    cin >> b[i] >> c[i];
  }
  sort(as.begin(),as.end());
  rep(i,n){
    inv[i]=as[i].second;
  }
  rep(i,n){
    s[i]=lower_bound(as.begin(),as.end(),P(b[inv[i]]-c[inv[i]],mod))-as.begin()-1;
    down[i]=min(i-1,s[i]);
    //cout << as[i].second << " " << s[i] << endl;
  }
  auto f1=[](int a,int b){return max(a,b);};
  auto f2=[](ll a,ll b){return max(a,b);};
  SegmentTree<int> up(f1,-1);
  up.init(n);
  per(i,n){
    up.set_val(i,max(up.query(i+1,s[i]+1),i));
    //cout << up[i] << endl;
  }
  SegmentTree<ll> ans(f2,0);
  ans.init(n);
  //ans.build(vector<ll>(n,INF));
  int max_up=0;
  rep(i,n){
    ans.set_val(i,b[inv[i]]+ans.query(0,down[i]+1));
    Rep(j,max_up+1,up[i]+1){
      if(s[j]<i){
        ans.set_val(j,b[inv[j]]+ans.query(0,down[j]+1));
      }
      else{
        ans.set_val(j,INF);
        ans.set_val(i,INF);
      }
    }
    max_up=max(max_up,max(i+1,up[i]));
    ans.set_val(i,max(ans[i],b[inv[i]]+ans.query(i+1,s[i]+1)));
  }
  rep(i,n){
    if(ans[inv[i]]>=INF) cout << "BAN" << endl;
    else cout << ans[inv[i]] << endl;
  }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}
0