結果
| 問題 |
No.911 ラッキーソート
|
| コンテスト | |
| ユーザー |
ゆきのん
|
| 提出日時 | 2020-03-10 21:05:09 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 240 ms / 2,000 ms |
| コード長 | 2,391 bytes |
| コンパイル時間 | 1,748 ms |
| コンパイル使用メモリ | 173,336 KB |
| 実行使用メモリ | 28,124 KB |
| 最終ジャッジ日時 | 2024-11-15 23:37:52 |
| 合計ジャッジ時間 | 8,501 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 46 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};
vector<int> v(64,0);
void rec(int k,vector<LL> a){
if(k < 0) return;
int n = a.size();
if(n == 1) return;
int cnt = 0;
for (int i = 0; i < n - 1; i++) {
int t = a[i] >> k & 1, nt = a[i+1] >> k & 1;
if(t != nt) cnt++;
}
if(cnt == 0){
rec(k-1, a);
}
else if(cnt == 1){
vector<LL> L,R;
for (int i = 0; i < n; i++) {
int t = a[i] >> k & 1;
if(t == 0) L.pb(a[i]);
else R.pb(a[i]);
}
if(a[0] >> k & 1) v[k] |= 2;
else v[k] |= 1;
rec(k-1, L);
rec(k-1, R);
}
else{
v[k] |= 3;
}
return ;
}
LL dp[64][2];
LL rec2(int k,LL s,bool f){
if(k < 0) return 1;
if(~dp[k][f]) return dp[k][f];
int x = f ? s >> k & 1 : 1;
LL ret = 0;
if(v[k] == 0){
for (int i = 0; i <= x; i++) {
ret += rec2(k-1,s,f&(x == i));
}
}
else if(v[k] == 1){
ret += rec2(k-1,s,f&(x == 0));
}
else if(v[k] == 2){
if(x == 0) return dp[k][f] = 0;
ret += rec2(k-1,s,f&(x == 1));
}
else{
return dp[k][f] = 0;
}
return dp[k][f] = ret;
}
int f(LL n){
int ret = 0;
while(n){
n >>= 1;
ret++;
}
return ret - 1;
}
int main(){
LL n,l,r;cin >> n >> l >> r;
l--;
vector<LL> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
rec(63,a);
LL ans = 0;
auto solve = [](LL r){
for (int i = f(r)+1; i <= 63; i++) {
if(v[i] > 1) return 0LL;
}
memset(dp,-1,sizeof(dp));
return rec2(f(r), r, 1);
};
ans += solve(r);
if(l >= 0){
ans -= solve(l);
}
cout << ans << endl;
return 0;
}
ゆきのん