結果

問題 No.911 ラッキーソート
ユーザー Mayimg
提出日時 2019-10-20 15:20:07
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,326 bytes
コンパイル時間 1,801 ms
コンパイル使用メモリ 194,248 KB
最終ジャッジ日時 2025-01-08 00:05:40
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
const int N = 62;
int mark[N];
long long calc (long long lim, int cur, int f) {
  if (cur < 0) return 1;
  long long res = 0;
  if (mark[cur] == 0) {
    if (lim & (1LL << cur)) {
      res += 1LL << (cur - f);
    }
    res += calc (lim, cur - 1, f);
  }
  if (mark[cur] == 1) {
    f--;
    if (lim & (1LL << cur)) {
      res += 1LL << (cur - f);
    } else {
      res += calc (lim, cur - 1, f);
    }
  }
  if (mark[cur] == 2) {
    f--;
    if (lim & (1LL << cur)) {
      res += calc (lim, cur - 1, f);
    }
  }
  return res;
}
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  long long n, l, r;
  cin >> n >> l >> r;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i + 1 < n; i++) {
    for (int j = N - 1; j >= 0; j--) {
      if ((a[i] & (1LL << j)) == 0 && (a[i + 1] & (1LL << j))) {
        mark[j] |= 1;
        break;
      }
      if ((a[i] & (1LL << j)) && ((a[i + 1] & (1LL << j)) == 0)) {
        mark[j] |= 2;
        break;
      }
    }
  }
  int fx = 0;
  for (int i = 0; i < N; i++) {
    if (mark[i] == 3) {
      cout << 0 << '\n';
      return 0;
    }
    if (mark[i]) fx++;
  }
  cout << calc(r, N - 1, fx) - (l ? calc(l - 1, N - 1, fx) : 0) << '\n';
  return 0;
}
0