結果
| 問題 |
No.911 ラッキーソート
|
| コンテスト | |
| ユーザー |
latte0119
|
| 提出日時 | 2019-10-18 22:11:59 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 131 ms / 2,000 ms |
| コード長 | 1,635 bytes |
| コンパイル時間 | 1,224 ms |
| コンパイル使用メモリ | 159,164 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-25 17:06:40 |
| 合計ジャッジ時間 | 5,994 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 46 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
ost<<"{"<<p.first<<","<<p.second<<"}";
return ost;
}
template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
ost<<"{";
for(int i=0;i<v.size();i++){
if(i)ost<<",";
ost<<v[i];
}
ost<<"}";
return ost;
}
int uku[66];
int calc(int X){
int la=1,ma=0;
for(int i=60;i>=0;i--){
int lala=0,mama=0;
for(int b=0;b<2;b++){
if(uku[i]!=-1&&uku[i]!=b)continue;
mama+=ma;
if((X>>i&1)==b)lala+=la;
else if((X>>i&1)>b)mama+=la;
}
la=lala;
ma=mama;
}
return la+ma;
}
int N,L,R;
int A[222222];
signed main(){
cin>>N>>L>>R;
rep(i,N)cin>>A[i];
memset(uku,-1,sizeof(uku));
bool ok=true;
rep(i,N-1){
for(int k=60;k>=0;k--){
if((A[i]>>k&1)==(A[i+1]>>k&1))continue;
int b;
if(A[i]>>k&1)b=1;
else b=0;
if(uku[k]!=-1&&uku[k]!=b)ok=false;
uku[k]=b;
break;
}
}
if(!ok){
cout<<0<<endl;
return 0;
}
int ans=calc(R);
if(L)ans-=calc(L-1);
cout<<ans<<endl;
return 0;
}
latte0119