結果

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

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;

int main() {
    cin.tie(nullptr) -> sync_with_stdio(false);
    
    int n; ll l, r;
    cin >> n >> l >> r;

    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    for (auto &x : a) cin >> x;

    vector<int> need(61, -1);
    rep(i, n-1) {
        ll d = a[i]^a[i+1];
        int k = 63 - __builtin_clzll(d);
        int b = a[i]>>k&1;
        
        if (need[k] != -1 and need[k] != b) {
            cout << 0 << '\n';
            return 0;
        }
        need[k] = b;
    }

    vector<ll> ways(62, 1);
    rep(k, 61) ways[k+1] = ways[k]*(need[k] == -1 ? 2 : 1);

    auto calc = [&](ll x) -> ll {
        if (x < 0) return 0;

        ll res = 0;
        for (int k = 60; k >= 0; --k) {
            int b = x>>k&1;
            if (b and need[k] != 1) res += ways[k];
            if (need[k] != -1 and need[k] != b) return res;
        }
        return res+1;
    };

    cout << calc(r) - calc(l-1) << '\n';
    
    return 0;
}
0