結果

問題 No.911 ラッキーソート
ユーザー snukesnuke
提出日時 2019-10-18 22:14:46
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 3,453 bytes
コンパイル時間 1,903 ms
コンパイル使用メモリ 202,356 KB
実行使用メモリ 4,908 KB
最終ジャッジ日時 2023-09-07 23:53:58
合計ジャッジ時間 7,556 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 135 ms
4,660 KB
testcase_14 AC 138 ms
4,564 KB
testcase_15 AC 135 ms
4,616 KB
testcase_16 AC 140 ms
4,624 KB
testcase_17 AC 145 ms
4,860 KB
testcase_18 AC 145 ms
4,640 KB
testcase_19 AC 144 ms
4,704 KB
testcase_20 AC 141 ms
4,736 KB
testcase_21 AC 143 ms
4,708 KB
testcase_22 AC 141 ms
4,704 KB
testcase_23 AC 131 ms
4,424 KB
testcase_24 AC 120 ms
4,436 KB
testcase_25 AC 77 ms
4,376 KB
testcase_26 AC 58 ms
4,380 KB
testcase_27 AC 29 ms
4,380 KB
testcase_28 AC 14 ms
4,380 KB
testcase_29 AC 5 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,384 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 136 ms
4,908 KB
testcase_39 AC 133 ms
4,380 KB
testcase_40 AC 5 ms
4,376 KB
testcase_41 AC 136 ms
4,600 KB
testcase_42 AC 88 ms
4,376 KB
testcase_43 AC 133 ms
4,736 KB
testcase_44 AC 124 ms
4,600 KB
testcase_45 AC 128 ms
4,728 KB
testcase_46 AC 127 ms
4,732 KB
testcase_47 AC 120 ms
4,604 KB
testcase_48 AC 120 ms
4,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

int n;
vl a;

P dfs(int l, int r, int k) {
  if (r-l <= 1) return P(0,0);
  if (k < 0) return P(0,0);
  int pre = a[l]>>k&1;
  int p = -1;
  srep(i,l,r) {
    int now = a[i]>>k&1;
    if (now != pre) {
      if (p != -1) return P(-1,-1);
      p = i;
    }
    pre = now;
  }
  if (p == -1) {
    return dfs(l,r,k-1);
  }
  P pl = dfs(l,p,k-1);
  P pr = dfs(p,r,k-1);
  if (pl.fi == -1) return P(-1,-1);
  if (pr.fi == -1) return P(-1,-1);
  {
    ll s = pl.se&pr.se;
    if ((pl.fi&s) != (pr.fi&s)) return P(-1,-1);
  }
  P res = pl;
  res.fi |= pr.fi;
  res.se |= pr.se;
  res.fi |= ll(!pre)<<k;
  res.se |= 1ll<<k;
  return res;
}

ll dp[65][2][2];

int main() {
  ll L,R;
  scanf("%d%lld%lld",&n,&L,&R);
  a = vl(n);
  cin>>a;
  P res = dfs(0,n,62);
  if (res.fi == -1) {
    cout<<0<<endl;
    return 0;
  }
  dp[62][1][1] = 1;
  drep(i,62) {
    int s = res.fi>>i&1;
    int t = res.se>>i&1;
    int l = L>>i&1;
    int r = R>>i&1;
    rep(j,2)rep(k,2) {
      rep(x,2) {
        if (t && s != x) continue;
        int nj = j, nk = k;
        if (j && !x && l) continue;
        if (k && x && !r) continue;
        if (x && !l) nj = 0;
        if (!x && r) nk = 0;
        dp[i][nj][nk] += dp[i+1][j][k];
      }
    }
  }
  ll ans = 0;
  rep(i,2)rep(j,2) ans += dp[0][i][j];
  cout<<ans<<endl;
  return 0;
}




















0