結果
問題 |
No.911 ラッキーソート
|
ユーザー |
|
提出日時 | 2019-11-28 22:42:35 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,423 bytes |
コンパイル時間 | 2,574 ms |
コンパイル使用メモリ | 209,156 KB |
最終ジャッジ日時 | 2025-01-08 05:42:03 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 TLE * 19 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int N; int64_t L, R; cin >> N >> L >> R; vector<int64_t> A(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } auto calc = [&](int64_t ub, bool inc) -> int64_t { vector<vector<int64_t>> dp(62, vector<int64_t>(2)); dp[0][0] = 1; for (int i = 0; i < 61; ++i) { map<int64_t, vector<int>> pfx2pos; for (int x = 0; x < N; ++x) { pfx2pos[A[x] >> 61 - i].push_back(x); } int must = -1; for (auto it : pfx2pos) { vector<int> vec; for (int x : it.second) { int v = A[x] >> 60 - i & 1; if (vec.empty() || vec.back() != v) { vec.push_back(v); } } if (2 < vec.size()) return 0; if (1 < vec.size()) { if (must == -1) must = vec[1] < vec[0]; if (must != (vec[1] < vec[0])) return 0; } } vector<int> choices; if (must == -1) choices = { 0, 1 }; else choices = { must }; for (int l = 0; l < 2; ++l) { int v = ub >> 60 - i & 1; for (int d : choices) { if (!l && v < d) continue; dp[i + 1][l | d < v] += dp[i][l]; } } } int64_t res = dp[61][1]; if (inc) res += dp[61][0]; return res; }; int64_t ans = calc(R, true) - calc(L, false); cout << ans << endl; return 0; }