結果
| 問題 |
No.911 ラッキーソート
|
| コンテスト | |
| ユーザー |
ats5515
|
| 提出日時 | 2019-10-18 23:04:13 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 62 ms / 2,000 ms |
| コード長 | 1,643 bytes |
| コンパイル時間 | 1,074 ms |
| コンパイル使用メモリ | 83,316 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-25 18:48:44 |
| 合計ジャッジ時間 | 4,810 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 46 |
ソースコード
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
int B = 61;
int solve(int m0, int m1, int X) {
if (X < 0)return 0;
vector<int> C(B, 0);
for (int i = 0; i < B; i++) {
int bit = ((int)1 << i);
if (!(bit & (m0 | m1))) {
C[i]++;
}
if (i > 0)C[i] += C[i - 1];
}
int res = 0;
int t = 1;
for (int i = B - 1; i >= 0; i--) {
int bit = ((int)1 << i);
if ((m0 & bit)) {
if (X & bit) {
if (i > 0) {
res += ((int)1 << (C[i - 1]));
}
else {
res++;
}
t = 0;
break;
}
}
else if ((m1 & bit)) {
if (!(X & bit)) {
t = 0;
break;
}
}
else {
if (X & bit) {
if (i > 0) {
res += ((int)1 << (C[i - 1]));
}
else {
res++;
}
}
}
}
res += t;
return res;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, L, R;
cin >> N >> L >> R;
vector<int> A(N);
int res = 0;
for (int i = 0; i < N; i++) {
cin >> A[i];
}
int m1 = 0;
int m0 = 0;
for (int i = 1; i < N; i++){
for (int j = B - 1; j >= 0; j--) {
int bit = ((int)1 << j);
if (!(A[i - 1] & bit) && (A[i] & bit)) {
m0 |= bit;
//cerr << 0 << " " << j << endl;
break;
}
else if ((A[i - 1] & bit) && !(A[i] & bit)) {
m1 |= bit;
//cerr << 1 << " " << j << endl;
break;
}
if (j == 0) {
m0 |= 1;
m1 |= 1;
}
}
}
if (m0 & m1) {
res = 0;
}
else {
res = solve(m0, m1, R) - solve(m0, m1, L - 1);
}
cout << res << endl;
}
ats5515