結果

問題 No.973 余興
ユーザー fumofumofunifumofumofuni
提出日時 2022-08-19 18:09:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,982 bytes
コンパイル時間 2,664 ms
コンパイル使用メモリ 208,548 KB
実行使用メモリ 112,636 KB
最終ジャッジ日時 2024-04-16 21:45:47
合計ジャッジ時間 13,291 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

#pragma GCC optimize("Ofast")

#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={0,1,0,-1,1,1,-1,-1,0};
const ll dx[9]={1,0,-1,0,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
struct BIT{
  int n;
  T def;
  vector<T> data;
  function<T(T,T)> fx;
  BIT(int _n,T _def,function<T(T,T)> _fx){
    n=_n;def=_def;fx=_fx;
    data.resize(n,def);
  }
  void update(int a,T val){
    for(int x=a;x<n;x|=x+1){
      data[x]=fx(data[x],val);
    }
  }
  T fold(int a){
    T ret=def;
    for(int x=a-1;x>=0;x=(x&(x+1))-1){
      ret=fx(ret,data[x]);
    }
    return ret;
  }
};

int main(){
    ll n,x;cin >> n >> x;
    vl a(n);rep(i,n)cin >> a[i];
    vl cum(n+1);rep(i,n)cum[i+1]=cum[i]+a[i];
    vector<BIT<int16_t>> stl,str;
    BIT<int16_t> tmp(n,0,[](int16_t a,int16_t b){return a+b;});
    rep(i,n){
        stl.emplace_back(tmp);
        str.emplace_back(tmp);
    }
    rep(i,n)stl[i].update(i,1);
    rep(i,n)str[i].update(i,1);
    for(ll len=2;len<=n;len++){
        for(ll l=0;l<n-len+1;l++){
            ll r=l+len;
            ll nl,nr;
            {
                ll ok=l,ng=r+1;
                while(ng-ok>1){
                    ll mid=(ok+ng)>>1;
                    if(cum[mid]-cum[l]<=x)ok=mid;
                    else ng=mid;
                }
                nl=ok;
            }
            {
                ll ok=r,ng=l-1;
                while(ok-ng>1){
                    ll mid=(ok+ng)>>1;
                    if(cum[r]-cum[mid]<=x)ok=mid;
                    else ng=mid;
                }
                nr=ok;
            }
            //cout << l <<" " << r <<" " << nl <<" " << nr << endl;
            auto f=stl[l].fold(r)-stl[l].fold(nr-1)+str[r-1].fold(nl+1)-str[r-1].fold(l);
            //auto f=stl[l].query(nr-1,r)+str[r-1].query(l,nl+1);
            if(!f)stl[l].update(r-1,1);
            if(!f)str[r-1].update(l,1);
        }
    }
    /*rep(i,n){
        rep(j,n)cout << stl[i][j] <<" ";cout << endl;
    }*/
    if(stl[0].fold(n)-stl[0].fold(n-1)==1)cout << "B" << endl;
    else cout << "A" << endl;
}
0