結果

問題 No.1219 Mancala Combo
ユーザー umezoumezo
提出日時 2024-01-23 04:40:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,882 bytes
コンパイル時間 3,214 ms
コンパイル使用メモリ 216,756 KB
実行使用メモリ 19,872 KB
最終ジャッジ日時 2024-01-23 04:40:58
合計ジャッジ時間 8,600 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,480 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 10 ms
6,676 KB
testcase_05 AC 8 ms
6,676 KB
testcase_06 AC 3 ms
6,676 KB
testcase_07 AC 8 ms
6,676 KB
testcase_08 AC 5 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 5 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 3 ms
6,676 KB
testcase_14 AC 1 ms
6,676 KB
testcase_15 AC 1 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 18 ms
13,408 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

template <typename X,typename M>
struct SegTreeLazy {
  using FX=function<X(X,X)>;
  using FA=function<X(X,M)>;
  using FM=function<M(M,M)>;
  int n;
  FX fx;
  FA fa;
  FM fm;
  const X ex;
  const M em;
  vector<X> dat;
  vector<M> lazy;
  SegTreeLazy(int n_,FX fx_,FA fa_,FM fm_,X ex_,M em_)
    : n(),fx(fx_),fa(fa_),fm(fm_),ex(ex_),em(em_),dat(n_*4,ex),lazy(n_*4,em) {
    int x=1;
    while (n_ > x) x*=2;
    n=x;
  }
  void set(int i,X x){dat[i+n-1]=x;}
  void build(){
    for(int k=n-2;k>=0;k--) dat[k]=fx(dat[2*k+1],dat[2*k+2]);
  }

  void eval(int k){
    if(lazy[k]==em) return; 
    if(k<n-1){           
      lazy[k*2+1]=fm(lazy[k*2+1],lazy[k]);
      lazy[k*2+2]=fm(lazy[k*2+2],lazy[k]);
    }
    dat[k]=fa(dat[k],lazy[k]);
    lazy[k]=em;
  }
  void update(int a,int b,M x,int k,int l,int r){
    eval(k);
    if(a<=l && r<=b){ 
      lazy[k]=fm(lazy[k],x);
      eval(k);
    }else if(a<r && l<b){
      update(a,b,x,k*2+1,l,(l+r)/2);
      update(a,b,x,k*2+2,(l+r)/2,r);
      dat[k]=fx(dat[k*2+1],dat[k*2+2]);
    }
  }
  void update(int a,int b,M x){update(a,b,x,0,0,n);}
  X query_sub(int a,int b,int k,int l,int r){
    eval(k);
    if(r<=a || b<=l) return ex;
    else if(a<=l && r<=b) return dat[k];
    else{ 
      X vl=query_sub(a,b,k*2+1,l,(l+r)/2);
      X vr=query_sub(a,b,k*2+2,(l+r)/2,r);
      return fx(vl,vr);
    }
  }
  X query(int a,int b){return query_sub(a,b,0,0,n);}
  
  int find_leftest(int a,int b,M x){return find_leftest_sub(a,b,x,0,0,n);}
  int find_leftest_sub(int a,int b,M x,int k,int l,int r){
    eval(k);
    if(dat[k]>x || r<=a || b<=l) return b;
    else if(k>=n-1) return (k-(n-1));
    else{
      int vl=find_leftest_sub(a,b,x,2*k+1,l,(l+r)/2);
      if(vl != b) return vl;
      else return find_leftest_sub(a,b,x,2*k+2,(l+r)/2,r);
    }
  }
};

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int n;
  cin>>n;
  ll sum=0;
  vector<ll> A(n+1);
  rep(i,n){
    cin>>A[i+1];
    sum+=A[i+1];
  }
    
  using X=ll;
  using M=ll;
  auto fx=[](X x1,X x2) -> X { return min(x1,x2);};
  auto fa=[](X x,M m) -> X { return x+m;};
  auto fm=[](M m1,M m2) -> M { return m1+m2;};
  X ex=1e18;
  M em=0;
  SegTreeLazy<X,M> seg(n+1,fx,fa,fm,ex,em);
  
  seg.set(0,sum);
  for(int i=1;i<=n;i++) seg.set(i,0);
  seg.build();

  
  int now=0;
  rep(i,sum){
    auto r=seg.find_leftest(1,now+1,0);
    if(r<now){
      seg.update(r,r+1,r);
      seg.update(0,r,-1);
    }
    else if(now==n){
      cout<<"No\n";
      return 0;
    }
    else{
      now++;
      seg.update(now,now+1,now);
      seg.update(0,now,-1);
    }
  }
  for(int i=1;i<=n;i++){
    if(seg.query(i,i+1)!=A[i]){
      cout<<"No\n";
      return 0;
    }
  }
  cout<<"Yes\n";
  
  return 0;
}
0