結果
問題 | No.911 ラッキーソート |
ユーザー |
![]() |
提出日時 | 2019-10-18 21:37:55 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 52 ms / 2,000 ms |
コード長 | 2,826 bytes |
コンパイル時間 | 2,107 ms |
コンパイル使用メモリ | 204,152 KB |
最終ジャッジ日時 | 2025-01-07 22:43:51 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 46 |
ソースコード
//#pragma GCC optimize("Ofast")//#pragma GCC target("avx")//#undef LOCAL#include <bits/stdc++.h>using namespace std;using uint = unsigned int;using ll = long long;using ull = unsigned long long;constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }template <class T> using V = vector<T>;template <class T> using VV = V<V<T>>;#ifdef LOCALstruct PrettyOS {ostream& os;bool first;template <class T> auto operator<<(T&& x) {if (!first) os << ", ";first = false;os << x;return *this;}};template <class... T> void dbg0(T&&... t) {(PrettyOS{cerr, true} << ... << t);}#define dbg(...) \do { \cerr << __LINE__ << " : " << #__VA_ARGS__ << " = "; \dbg0(__VA_ARGS__); \cerr << endl; \} while (false);#else#define dbg(...)#endiftemplate <class T, class U>ostream& operator<<(ostream& os, const pair<T, U>& p) {return os << "P(" << p.first << ", " << p.second << ")";}template <class T> ostream& operator<<(ostream& os, const V<T>& v) {os << "[";for (auto d : v) os << d << ", ";return os << "]";}ll up;V<int> fix(62, -1);using S = pair<int, bool>;map<S, ll> dp;ll solve(int he, bool same) {if (he == -1) return 1;auto key = S(he, same);if (dp.count(key)) return dp[key];ll ans = 0;ll nw = (up >> he) & 1;if (fix[he] != 1) {ans += solve(he - 1, (same) && nw == 0);}if (fix[he] != 0 && !(same && nw == 0)) {ans += solve(he - 1, (same) && nw == 1);}return dp[key] = ans;}ll solve(ll x) {up = x;dp.clear();return solve(61, true);}int main() {cin.tie(nullptr);ios::sync_with_stdio(false);cout << fixed << setprecision(20);int n;ll l, r;cin >> n >> l >> r;V<ll> a(n);for (int i = 0; i < n; i++) {cin >> a[i];}for (int i = 0; i < n - 1; i++) {ll x = a[i], y = a[i + 1];for (int he = 61; he >= 0; he--) {ll u = (x >> he) & 1;ll v = (y >> he) & 1;if (u == v) continue;dbg(x, y, u, v, he);if (u < v) {if (fix[he] == 1) {cout << 0 << endl;return 0;}fix[he] = 0;} else {if (fix[he] == 0) {cout << 0 << endl;return 0;}fix[he] = 1;}break;}}dbg(fix);ll ans = solve(r);if (l) ans -= solve(l - 1);cout << ans << endl;return 0;}