結果

問題 No.911 ラッキーソート
ユーザー Mayimg
提出日時 2019-10-20 15:19:40
言語 C++17(1z)
(gcc 8.3.0)
結果
WA   .
実行時間 -
コード長 1,320 Byte
コンパイル時間 2,227 ms
使用メモリ 2,884 KB
最終ジャッジ日時 2019-12-15 17:37:07

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
01_sample_01 AC 4 ms
1,524 KB
01_sample_02 AC 3 ms
1,524 KB
01_sample_03 AC 4 ms
1,528 KB
02_small_01 WA -
02_small_02 WA -
02_small_03 WA -
02_small_04 AC 4 ms
1,528 KB
02_small_05 AC 3 ms
1,524 KB
02_small_06 WA -
02_small_07 WA -
02_small_08 WA -
02_small_09 WA -
02_small_10 WA -
03_large_01 WA -
03_large_02 WA -
03_large_03 AC 66 ms
2,884 KB
03_large_04 WA -
03_large_05 AC 66 ms
2,880 KB
03_large_06 WA -
03_large_07 AC 68 ms
2,884 KB
03_large_08 WA -
03_large_09 WA -
03_large_10 WA -
03_large_11 AC 66 ms
2,884 KB
03_large_12 WA -
03_large_13 AC 41 ms
2,088 KB
03_large_14 WA -
03_large_15 WA -
03_large_16 WA -
03_large_17 WA -
03_large_18 AC 3 ms
1,540 KB
03_large_19 WA -
03_large_20 WA -
04_corner_01 AC 3 ms
1,528 KB
04_corner_02 WA -
04_corner_03 AC 3 ms
1,528 KB
04_corner_04 WA -
04_corner_05 WA -
05_corner_01 WA -
05_corner_02 WA -
05_corner_03 AC 6 ms
1,568 KB
05_corner_04 AC 66 ms
2,880 KB
05_corner_05 WA -
05_corner_06 WA -
06_large_01 AC 65 ms
2,884 KB
06_large_02 AC 66 ms
2,884 KB
06_large_03 AC 66 ms
2,884 KB
06_large_04 AC 66 ms
2,884 KB
06_large_05 AC 66 ms
2,884 KB
テストケース一括ダウンロード

ソースコード

diff #
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
const int N = 62;
int mark[N];
long long calc (int 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