結果
| 問題 |
No.911 ラッキーソート
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-17 05:14:48 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 55 ms / 2,000 ms |
| コード長 | 1,939 bytes |
| コンパイル時間 | 1,306 ms |
| コンパイル使用メモリ | 123,128 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-03 10:06:05 |
| 合計ジャッジ時間 | 6,456 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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; }
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
//constexpr long long mod = 1000000007LL;
constexpr long long mod = 998244353LL;
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ll N, L, R;
vector<ll> a;
vector<vector<int>> can;
ll solve(ll x) {
vector<vector<ll>> dp(63, vector<ll>(2));
dp[62][1] = 1;
for (int bit = 61; bit >= 0; bit--) {
int t = (x >> bit) & 1;
if (t == 1) {
dp[bit][1] += dp[bit + 1][1] * can[bit][1];
dp[bit][0] += dp[bit + 1][1] * can[bit][0];
}
else {
dp[bit][1] += dp[bit + 1][1] * can[bit][0];
}
dp[bit][0] += dp[bit + 1][0] * (can[bit][0] + can[bit][1]);
}
return dp[0][0] + dp[0][1];
}
int main()
{
/*
cin.tie(nullptr);
ios::sync_with_stdio(false);
*/
scanf("%lld %lld %lld", &N, &L, &R);
a.resize(N); for (int i = 0; i < N; i++) scanf("%lld", &a[i]);
can = vector<vector<int>>(63, vector<int>(2, 1));
for (int i = 0; i < N - 1; i++) {
for (int j = 62; j >= 0; j--) {
int s = a[i] >> j & 1;
int t = a[i + 1] >> j & 1;
if (s == 1 and t == 0) {
can[j][0] = 0;
break;
}
if (s == 0 and t == 1) {
can[j][1] = 0;
break;
}
}
}
ll res = solve(R);
if (L) res -= solve(L - 1);
cout << res << endl;
return 0;
}