結果

問題 No.911 ラッキーソート
ユーザー treeonetreeone
提出日時 2019-10-17 15:05:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 411 ms / 2,000 ms
コード長 1,751 bytes
コンパイル時間 3,008 ms
コンパイル使用メモリ 211,428 KB
実行使用メモリ 19,028 KB
最終ジャッジ日時 2023-09-06 18:08:59
合計ジャッジ時間 15,959 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 411 ms
18,744 KB
testcase_14 AC 397 ms
18,648 KB
testcase_15 AC 373 ms
18,844 KB
testcase_16 AC 370 ms
19,028 KB
testcase_17 AC 363 ms
18,508 KB
testcase_18 AC 343 ms
18,004 KB
testcase_19 AC 367 ms
17,840 KB
testcase_20 AC 333 ms
17,052 KB
testcase_21 AC 290 ms
16,816 KB
testcase_22 AC 260 ms
16,440 KB
testcase_23 AC 244 ms
15,416 KB
testcase_24 AC 224 ms
14,416 KB
testcase_25 AC 123 ms
9,808 KB
testcase_26 AC 102 ms
8,472 KB
testcase_27 AC 48 ms
5,788 KB
testcase_28 AC 23 ms
4,588 KB
testcase_29 AC 7 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 397 ms
18,692 KB
testcase_39 AC 267 ms
15,816 KB
testcase_40 AC 6 ms
4,376 KB
testcase_41 AC 324 ms
16,964 KB
testcase_42 AC 167 ms
11,776 KB
testcase_43 AC 374 ms
18,564 KB
testcase_44 AC 396 ms
18,632 KB
testcase_45 AC 386 ms
18,028 KB
testcase_46 AC 363 ms
17,104 KB
testcase_47 AC 332 ms
17,136 KB
testcase_48 AC 318 ms
17,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int use[61][2];

long long calc(long long M){
    long long dp[2] = {}, nxt[2] = {};
    dp[1] = 1;
    for(int i = 60; i >= 0; i--){
        nxt[0] = nxt[1] = 0;
        nxt[0] += dp[0] * use[i][0];
        nxt[0] += dp[0] * use[i][1];
        if(M & (1LL << i)){
            nxt[0] += dp[1] * use[i][0];
            nxt[1] += dp[1] * use[i][1];
        }else{
            nxt[1] += dp[1] * use[i][0];
        }
        swap(dp, nxt);
    }
    return dp[0] + dp[1];
}

int main(){
    int N;
    long long L, R;
    cin >> N >> L >> R;
    assert(1 <= N && N <= 200000);
    assert(0 <= L && L <= R && R < (1LL << 61));
    vector<long long> A(N); 
    set<long long> st;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        assert(st.count(A[i]) == 0);
        st.insert(A[i]);
        assert(0 <= A[i] && A[i] < (1LL << 61));
    }
    vector<int> v;
    v.push_back(0);
    v.push_back(N);
    for(int i = 60; i >= 0; i--){
        use[i][0] = use[i][1] = 1;
        vector<int> tmp = v;
        for(int j = 0; j < v.size() - 1; j++){
            int cnt = 0;
            for(int k = v[j] + 1; k < v[j + 1]; k++){
                if(!!(A[k - 1] & (1LL << i)) != !!(A[k] & (1LL << i))){
                    cnt++;
                    tmp.push_back(k);
                }
            }
            // cout << i << ' ' << j << " " << v[j] << ' ' << cnt << endl;
            if(cnt >= 2) use[i][0] = use[i][1] = 0;
            if(cnt == 1) use[i][!(A[v[j]] & (1LL << i))] = 0;
        }
        sort(tmp.begin(), tmp.end());
        v = tmp;
        // cout << use[i][0] << ' ' << use[i][1] << endl;
    }
    long long ans = calc(R);
    if(L != 0) ans -= calc(L - 1);
    cout << ans << endl;
}
0