結果

問題 No.911 ラッキーソート
ユーザー beetbeet
提出日時 2019-10-18 21:54:13
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 655 ms / 2,000 ms
コード長 1,814 bytes
コンパイル時間 2,905 ms
コンパイル使用メモリ 216,308 KB
実行使用メモリ 65,824 KB
最終ジャッジ日時 2023-09-07 22:06:45
合計ジャッジ時間 14,862 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 649 ms
65,824 KB
testcase_14 AC 655 ms
64,964 KB
testcase_15 AC 611 ms
61,712 KB
testcase_16 AC 614 ms
61,464 KB
testcase_17 AC 648 ms
63,572 KB
testcase_18 AC 606 ms
61,180 KB
testcase_19 AC 618 ms
61,720 KB
testcase_20 AC 553 ms
55,752 KB
testcase_21 AC 471 ms
47,488 KB
testcase_22 AC 416 ms
41,332 KB
testcase_23 AC 401 ms
39,388 KB
testcase_24 AC 355 ms
35,848 KB
testcase_25 AC 188 ms
20,164 KB
testcase_26 AC 182 ms
19,924 KB
testcase_27 AC 62 ms
8,836 KB
testcase_28 AC 31 ms
5,852 KB
testcase_29 AC 14 ms
4,604 KB
testcase_30 AC 3 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 629 ms
63,836 KB
testcase_39 AC 413 ms
40,992 KB
testcase_40 AC 13 ms
4,516 KB
testcase_41 AC 561 ms
56,612 KB
testcase_42 AC 300 ms
30,776 KB
testcase_43 AC 635 ms
65,288 KB
testcase_44 AC 45 ms
8,152 KB
testcase_45 AC 47 ms
8,228 KB
testcase_46 AC 47 ms
8,116 KB
testcase_47 AC 46 ms
8,108 KB
testcase_48 AC 44 ms
7,860 KB
権限があれば一括ダウンロードができます

ソースコード

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