結果

問題 No.911 ラッキーソート
ユーザー mamekinmamekin
提出日時 2019-11-09 20:34:32
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 1,731 bytes
コンパイル時間 1,334 ms
コンパイル使用メモリ 117,996 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-15 04:49:52
合計ジャッジ時間 9,794 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

long long solve(const vector<long long>& a, long long x)
{
    if(x == -1)
        return 0;

    int n = a.size();
    vector<long long> dp = {1, 0};
    for(int i=62; i>=0; --i){
        bool up = false;
        bool down = false;
        for(int j=0; j<n-1; ++j){
            if((a[j] >> (i + 1)) != (a[j+1] >> (i + 1)))
                continue;
            if((a[j] & (1LL << i)) < (a[j+1] & (1LL << i)))
                up = true;
            else if((a[j] & (1LL << i)) > (a[j+1] & (1LL << i)))
                down = true;
        }

        vector<long long> nextDp(2, 0);
        if(!up){
            if(x & (1LL << i))
                nextDp[0] += dp[0];
            nextDp[1] += dp[1];
        }
        if(!down){
            if(x & (1LL << i)){
                nextDp[1] += dp[0] + dp[1];
            }
            else{
                nextDp[0] += dp[0];
                nextDp[1] += dp[1];
            }
        }
        dp = move(nextDp);
    }
    return dp[0] + dp[1];
}

int main()
{
    int n;
    long long l, r;
    cin >> n >> l >> r;
    vector<long long> a(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];

    long long ans = solve(a, r) - solve(a, l-1);
    cout << ans << endl;

    return 0;
}
0