結果

問題 No.911 ラッキーソート
ユーザー beetbeet
提出日時 2019-10-18 21:53:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,812 bytes
コンパイル時間 2,397 ms
コンパイル使用メモリ 217,088 KB
実行使用メモリ 65,872 KB
最終ジャッジ日時 2023-09-07 22:00:08
合計ジャッジ時間 14,977 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed main(){
  Int n,l,r;
  cin>>n>>l>>r;
  vector<Int> as(n);
  for(Int i=0;i<n;i++) cin>>as[i];

  const Int MAX = 62;
  vector< vector<Int> > S(MAX+1);
  S[MAX].emplace_back(0);
  S[MAX].emplace_back(n);

  vector< set<Int> > C(MAX+1);
  for(Int i=MAX-1;i>=0;i--){
    C[i].emplace(0);
    C[i].emplace(1);

    for(Int j=0;j+1<(Int)S[i+1].size();j++){
      Int p=S[i+1][j],q=S[i+1][j+1];
      S[i].emplace_back(p);

      vector<Int> vs(q-p);
      for(Int k=p;k<q;k++) vs[k-p]=(as[k]>>i)&1;

      if(vs==vector<Int>(q-p,0)) continue;
      if(vs==vector<Int>(q-p,1)) continue;

      auto us(vs);
      us.erase(unique(us.begin(),us.end()),us.end());
      if(us.size()>2) drop(0);

      for(Int k=p;k+1<q;k++)
        if(vs[k-p]!=vs[k+1-p]) S[i].emplace_back(k+1);

      if(vs[0]==0) C[i].erase(1);
      if(vs[0]==1) C[i].erase(0);
    }
    S[i].emplace_back(n);

    //for(Int s:S[i]) cout<<s<<" ";
    cout<<endl;
  }

  auto calc=
    [&](Int k)->Int{
      vector<Int> dp(2,0);
      dp[1]=1;
      for(Int i=MAX-1;i>=0;i--){
        Int b=(k>>i)&1;
        vector<Int> nx(2,0);
        for(Int c:C[i]){
          for(Int t=0;t<2;t++){
            if(t&&c>b) continue;
            Int nt=t&&(b==c);
            nx[nt]+=dp[t];
          }
        }
        swap(dp,nx);
      }
      return dp[0]+dp[1];
    };

  Int ans=calc(r);
  if(l) ans-=calc(l-1);
  cout<<ans<<endl;
  return 0;
}
0