結果
| 問題 |
No.911 ラッキーソート
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-02-15 19:37:18 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 113 ms / 2,000 ms |
| コード長 | 2,147 bytes |
| コンパイル時間 | 1,239 ms |
| コンパイル使用メモリ | 115,752 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-06 14:02:02 |
| 合計ジャッジ時間 | 7,037 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 46 |
ソースコード
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ll N, L, R;
ll a[200500];
ll dfs(ll X) {
ll dp[63][2]; for (ll i = 0; i < 63; i++) for (ll j = 0; j < 2; j++) dp[i][j] = 0;
dp[62][1] = 1;
vector<bool> used(N, false);
for (ll i = 61; i >= 0; i--) {
ll tmp = -1;
for (ll j = 0; j < N - 1; j++) {
if (used[j]) continue;
ll lf = (a[j] >> i & 1);
ll rg = (a[j + 1] >> i & 1);
if (lf == rg) continue;
if (lf == 1) {
if (tmp == -1) tmp = 1;
else if (tmp == 0) {
return 0;
}
}
else {
if (tmp == -1) tmp = 0;
else if (tmp == 1) {
return 0;
}
}
used[j] = true;
}
if (tmp == -1) {
dp[i][1] += dp[i + 1][1];
if(X >> i & 1) dp[i][0] += dp[i + 1][1];
dp[i][0] += dp[i + 1][0] * 2;
}
else if (tmp == 1) {
if (X >> i & 1) {
dp[i][1] += dp[i + 1][1];
}
dp[i][0] += dp[i + 1][0];
}
else {
//cout << i << endl;
if (!(X >> i & 1)) {
dp[i][1] += dp[i + 1][1];
}
else {
dp[i][0] += dp[i + 1][1];
}
dp[i][0] += dp[i + 1][0];
}
}
return dp[0][0] + dp[0][1];
}
int main()
{
/*
cin.tie(nullptr);
ios::sync_with_stdio(false);
*/
scanf("%lld %lld %lld", &N, &L, &R);
for (ll i = 0; i < N; i++) scanf("%lld", &a[i]);
ll res = dfs(R);
//cout << res << endl;
if (L) res -= dfs(L - 1);
cout << res << endl;
return 0;
}