結果
問題 |
No.911 ラッキーソート
|
ユーザー |
|
提出日時 | 2021-03-19 17:13:11 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 78 ms / 2,000 ms |
コード長 | 2,613 bytes |
コンパイル時間 | 1,643 ms |
コンパイル使用メモリ | 135,384 KB |
最終ジャッジ日時 | 2025-01-19 18:11:02 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 46 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <queue> #include <string> #include <map> #include <set> #include <stack> #include <tuple> #include <deque> #include <array> #include <numeric> #include <bitset> #include <iomanip> #include <cassert> #include <chrono> #include <random> #include <limits> #include <iterator> #include <functional> #include <sstream> #include <fstream> #include <complex> #include <cstring> #include <unordered_map> #include <unordered_set> using namespace std; using ll = long long; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; template<class T> inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template<class T> inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } ll func(vector<int>& t, ll x){ int msb = -1; for(int k = 60; k >= 0; --k){ if(x >> k & 1){ msb = k; break; } if(t[k] == 2) return 0LL; } vector<vector<ll>> dp(msb + 2, vector<ll>(2)); dp[msb + 1][0] = 1; for(int i = msb; i >= 0; --i){ if(t[i] == 0){ dp[i][0] += dp[i + 1][0]; dp[i][1] += dp[i + 1][1] * 2; if(x >> i & 1){ dp[i][1] += dp[i + 1][0]; } } else if(t[i] == 1){ dp[i][1] += dp[i + 1][1]; if(x >> i & 1){ dp[i][1] += dp[i + 1][0]; } else{ dp[i][0] += dp[i + 1][0]; } } else{ dp[i][1] += dp[i + 1][1]; if(x >> i & 1){ dp[i][0] += dp[i + 1][0]; } } } return dp[0][0] + dp[0][1]; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; ll L, R; cin >> N >> L >> R; vector<ll> A(N); for(int i = 0; i < N; ++i) cin >> A[i]; vector<int> T(61); for(int i = 0; i + 1 < N; ++i){ for(int k = 60; k >= 0; --k){ if((A[i] >> k & 1) == 0 && (A[i + 1] >> k & 1) == 1){ T[k] |= 1; break; } if((A[i] >> k & 1) == 1 && (A[i + 1] >> k & 1) == 0){ T[k] |= 2; break; } } } for(int k = 60; k >= 0; --k){ if(T[k] == 3){ cout << 0 << endl; return 0; } } ll ans = func(T, R); if(L > 0) ans -= func(T, L - 1); cout << ans << endl; return 0; }