結果

問題 No.911 ラッキーソート
ユーザー pionepione
提出日時 2020-06-03 21:45:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 2,650 bytes
コンパイル時間 1,676 ms
コンパイル使用メモリ 171,668 KB
実行使用メモリ 4,744 KB
最終ジャッジ日時 2023-08-17 06:14:28
合計ジャッジ時間 7,997 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 53 ms
4,644 KB
testcase_14 AC 53 ms
4,572 KB
testcase_15 AC 54 ms
4,692 KB
testcase_16 AC 56 ms
4,588 KB
testcase_17 AC 54 ms
4,572 KB
testcase_18 AC 56 ms
4,696 KB
testcase_19 AC 55 ms
4,676 KB
testcase_20 AC 54 ms
4,572 KB
testcase_21 AC 58 ms
4,636 KB
testcase_22 AC 58 ms
4,704 KB
testcase_23 AC 53 ms
4,432 KB
testcase_24 AC 49 ms
4,428 KB
testcase_25 AC 32 ms
4,384 KB
testcase_26 AC 24 ms
4,376 KB
testcase_27 AC 13 ms
4,376 KB
testcase_28 AC 7 ms
4,380 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 54 ms
4,568 KB
testcase_39 AC 56 ms
4,624 KB
testcase_40 AC 3 ms
4,380 KB
testcase_41 AC 55 ms
4,568 KB
testcase_42 AC 37 ms
4,376 KB
testcase_43 AC 54 ms
4,704 KB
testcase_44 AC 52 ms
4,672 KB
testcase_45 AC 54 ms
4,572 KB
testcase_46 AC 54 ms
4,680 KB
testcase_47 AC 53 ms
4,684 KB
testcase_48 AC 55 ms
4,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

// 参考: https://yukicoder.me/submissions/465103

ll n;
vll a;

vvll can;

ll f(ll x){
  vvll dp(63, vll(2));
  dp[62][1]=1;
  for(ll bit=61; bit>=0; bit--){
    ll t=(x>>bit)&1;
    if(t==1){
      dp[bit][1]+=dp[bit+1][1]*can[bit][1];
      dp[bit][0]+=dp[bit+1][1]*can[bit][0];
    }else{
      dp[bit][1]+=dp[bit+1][1]*can[bit][0];
    }
    dp[bit][0]+=dp[bit+1][0]*(can[bit][0]+can[bit][1]);
  }
  
  return dp[0][0]+dp[0][1];
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll l,r; cin>>n>>l>>r;
  a.resize(n);
  rep(i,n) cin>>a[i];
  
  can = vvll(63, vll(2,1)); // i桁目において、xor0, xor1をそれぞれとれるか
  rep(i,n-1){
    rrep(j,62){
      ll s = a[i]>>j&1;
      ll t = a[i+1]>>j&1;
      if(s==1&&t==0){
        can[j][0]=0; // 今見ている桁において、a_0=1, a_1=0 なら、xor0は取れない
        break;
      }
      if(s==0&&t==1){
        can[j][1]=0; // 今見ている桁において、a_0=0, a_1=1 なら、xor1は取れない
        break;
      }
    }
  }
  
  ll ans=f(r);
  if(l) ans-=f(l-1);
  cout<<ans<<endl;
  
}
0