結果
| 問題 |
No.911 ラッキーソート
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2020-10-27 02:02:24 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 92 ms / 2,000 ms |
| コード長 | 1,901 bytes |
| コンパイル時間 | 834 ms |
| コンパイル使用メモリ | 85,184 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-21 21:48:59 |
| 合計ジャッジ時間 | 5,852 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 46 |
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int n;
ll l, r;
ll a[200000];
bool ok0[61];
bool ok1[61];
void input(){
cin >> n >> l >> r;
for(int i = 0; i < n; i++) cin >> a[i];
}
bool change[200000];
ll dp[64][2];
ll calc(ll x){
if(x < 0) return 0;
for(int j = 60; j >= 0; j--){
dp[j][0] = 0;
dp[j][1] = 0;
}
dp[61][1] = 1;
for(int j = 60; j >= 0; j--){
ll m = (ll)1<<j;
if(x&m){
if(ok0[j]) {
dp[j][0] += dp[j+1][0]+dp[j+1][1];
}
if(ok1[j]){
dp[j][0] += dp[j+1][0];
dp[j][1] += dp[j+1][1];
}
}else{
if(ok0[j]) {
dp[j][0] += dp[j+1][0];
dp[j][1] += dp[j+1][1];
}
if(ok1[j]){
dp[j][0] += dp[j+1][0];
}
}
// cout << dp[j][0]+dp[j][1] << endl;
}
return dp[0][0]+dp[0][1];
}
void solve(){
for(int j = 60; j >= 0; j--){
vector<bool> ok(2, true);
ll m = (ll)1<<j;
for(int i = 1; i < n; i++){
if((m&a[i]) != (m&a[i-1])){
// cout << j << ' ' << i << endl;
if(change[i]) {
continue;
}
change[i] = true;
if(!(m&a[i])) ok[0] = false;
else ok[1] = false;
}
}
if(!(ok[0] || ok[1])){
cout << 0 << endl;
return;
}
ok0[j] = ok[0];
ok1[j] = ok[1];
// cout << ok[0] << ' ' << ok[1] << endl;
}
cout << calc(r)-calc(l-1) << endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
input();
solve();
}
milanis48663220