結果

問題 No.911 ラッキーソート
コンテスト
ユーザー WutongDeath
提出日時 2026-11-25 02:23:08
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc16.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 27 ms / 2,000 ms
+ 661µs
コード長 1,345 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,929 ms
コンパイル使用メモリ 161,280 KB
実行使用メモリ 9,924 KB
最終ジャッジ日時 2026-11-25 02:23:18
合計ジャッジ時間 10,141 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge6_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

typedef long long LL;

const int N = 200010, B = 62;

int n, tgt[B], d[B];
LL l, r, a[N], f[B], ans;

LL DFS(int pos, bool tight) {
    if (pos == 0) return 1;
    if (!tight && ~f[pos]) return f[pos];
    LL ret = 0LL;
    for (int i = 0; i <= (tight ? d[pos] : 1); ++i) {
        if (tgt[pos] == -1 || tgt[pos] == i) {
            ret += DFS(pos - 1, tight && i == d[pos]);
        }
    }
    // tight = true 的情况不用缓存
    if (!tight) f[pos] = ret;
    return ret;
}

LL Calc(LL x) {
    if (x < 0) return 0;
    for (int i = 1; i <= 61; ++i) d[i] = x >> (i - 1) & 1;
    memset(f, -1, sizeof(f));
    return DFS(61, true);
}

int main() {
    scanf("%d%lld%lld", &n, &l, &r);
    for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);

    memset(tgt, -1, sizeof(tgt));
    for (int i = 1; i < n; ++i) {
        for (int j = 61; j >= 1; --j) {
            if ((a[i] >> (j - 1) & 1) != (a[i + 1] >> (j - 1) & 1)) {
                int v = a[i] >> (j - 1) & 1;
                if (tgt[j] != -1 && tgt[j] != v) {
                    printf("0\n");

                    return 0;
                }
                tgt[j] = v;
                break;
            }
        }
    }

    ans = Calc(r) - Calc(l - 1);
    printf("%lld\n", ans);

    return 0;
}
0