結果
問題 | No.911 ラッキーソート |
ユーザー |
![]() |
提出日時 | 2019-10-18 22:07:32 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 136 ms / 2,000 ms |
コード長 | 1,173 bytes |
コンパイル時間 | 632 ms |
コンパイル使用メモリ | 74,492 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-25 17:01:51 |
合計ジャッジ時間 | 5,425 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 46 |
ソースコード
#include <string> #include <vector> #include <iostream> #include <functional> using namespace std; int main() { int N; long long L, R; cin >> N >> L >> R; vector<long long> A(N); string cond(62, '?'); for (int i = 0; i < N; ++i) { cin >> A[i]; } bool ok = true; for (int i = 0; i < N - 1; ++i) { if (A[i] == A[i + 1]) { ok = false; break; } int d = 61; while (!(((A[i] ^ A[i + 1]) >> d) & 1)) --d; if (A[i] < A[i + 1]) { if (cond[d] == '1') { ok = false; break; } cond[d] = '0'; } else { if (cond[d] == '0') { ok = false; break; } cond[d] = '1'; } } function<long long(long long)> calc = [&](long long x) { long long cur = 0, ans = 0; for (int i = 61; i >= 0; --i) { if (cur + (1LL << i) <= x) { cur += 1LL << i; if (cond[i] == '1') continue; int cnt = 0; for (int j = 0; j < i; ++j) { if (cond[j] == '?') ++cnt; } ans += 1LL << cnt; if (cond[i] == '0') break; } else if (cond[i] == '1') break; } return ans; }; if (!ok) { cout << 0 << endl; } else { long long cl = calc(L); long long cr = calc(R + 1); cout << cr - cl << endl; } return 0; }