結果

問題 No.1296 OR or NOR
ユーザー LayCurseLayCurse
提出日時 2020-11-20 22:28:17
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 4,827 bytes
コンパイル時間 3,734 ms
コンパイル使用メモリ 211,872 KB
最終ジャッジ日時 2025-01-16 02:39:42
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
static char buf[1048576];
static int s = 1048576;
static int e = 1048576;
if(s == e && e == 1048576){
e = fread_unlocked(buf, 1, 1048576, stdin);
s = 0;
}
if(s == e){
return EOF;
}
return buf[s++];
}
inline void rd(int &x){
int k;
int m=0;
x=0;
for(;;){
k = my_getchar_unlocked();
if(k=='-'){
m=1;
break;
}
if('0'<=k&&k<='9'){
x=k-'0';
break;
}
}
for(;;){
k = my_getchar_unlocked();
if(k<'0'||k>'9'){
break;
}
x=x*10+k-'0';
}
if(m){
x=-x;
}
}
inline void rd(long long &x){
int k;
int m=0;
x=0;
for(;;){
k = my_getchar_unlocked();
if(k=='-'){
m=1;
break;
}
if('0'<=k&&k<='9'){
x=k-'0';
break;
}
}
for(;;){
k = my_getchar_unlocked();
if(k<'0'||k>'9'){
break;
}
x=x*10+k-'0';
}
if(m){
x=-x;
}
}
struct MY_WRITER{
char buf[1048576];
int s;
int e;
MY_WRITER(){
s = 0;
e = 1048576;
}
~MY_WRITER(){
if(s){
fwrite_unlocked(buf, 1, s, stdout);
}
}
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
MY_WRITER_VAR.s = 0;
}
MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
my_putchar_unlocked(a);
}
inline void wt_L(int x){
int s=0;
int m=0;
char f[10];
if(x<0){
m=1;
x=-x;
}
while(x){
f[s++]=x%10;
x/=10;
}
if(!s){
f[s++]=0;
}
if(m){
my_putchar_unlocked('-');
}
while(s--){
my_putchar_unlocked(f[s]+'0');
}
}
inline void wt_L(long long x){
int s=0;
int m=0;
char f[20];
if(x<0){
m=1;
x=-x;
}
while(x){
f[s++]=x%10;
x/=10;
}
if(!s){
f[s++]=0;
}
if(m){
my_putchar_unlocked('-');
}
while(s--){
my_putchar_unlocked(f[s]+'0');
}
}
template<class S, class T> inline S chmax(S &a, T b){
if(a<b){
a=b;
}
return a;
}
int N;
int Q;
long long A[200000];
long long B[200000];
int las[60];
int main(){
int i, j, tU__gIr_;
long long res;
long long can;
long long cur;
long long now;
long long nx;
int ok0;
int ok1;
rd(N);
{
int Lj4PdHRW;
for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
rd(A[Lj4PdHRW]);
}
}
rd(Q);
{
int e98WHCEY;
for(e98WHCEY=(0);e98WHCEY<(Q);e98WHCEY++){
rd(B[e98WHCEY]);
}
}
for(j=(0);j<(60);j++){
las[j] = -1;
}
for(i=(0);i<(Q);i++){
for(j=(0);j<(60);j++){
if(A[i] & (1LL<<j)){
las[j] = i;
}
}
}
for(tU__gIr_=(0);tU__gIr_<(Q);tU__gIr_++){
auto &now = B[tU__gIr_];
res = can = 0;
cur = N;
for(;;){
nx = -1;
for(i=(0);i<(60);i++){
if(las[i] < cur){
chmax(nx, las[i]);
}
}
if(nx == -1){
break;
}
ok0 = ok1 = 1;
for(i=(0);i<(60);i++){
if(las[i] == nx){
if(now & (1LL << i)){
ok1 = 0;
}
if(!(now & (1LL << i))){
ok0 = 0;
}
}
}
if(ok0==ok1 && ok1==0){
wt_L(-1);
wt_L('\n');
goto a2conNHc;
}
if(ok0==0){
res++;
now ^= (1LL << 60) - 1;
}
cur = nx;
}
ok0 = ok1 = 1;
for(i=(0);i<(60);i++){
if(las[i]==-1){
if(now & (1LL << i)){
ok0 = 0;
}
if(!(now & (1LL << i))){
ok1 = 0;
}
}
}
if(ok0==ok1 && ok1==0){
wt_L(-1);
wt_L('\n');
continue;
}
if(ok0==0){
res++;
}
wt_L(res);
wt_L('\n');
a2conNHc:;
}
return 0;
}
// cLay version 20201120-1 [beta]
// --- original code ---
// int N, Q; ll A[2d5], B[2d5];
// int las[60];
//
// {
// ll res, can, cur, now, nx;
// int ok0, ok1;
// rd(N,A(N),Q,B(Q));
//
// rep(j,60) las[j] = -1;
// rep(i,Q) rep(j,60) if(A[i] & (1LL<<j)) las[j] = i;
//
// rep[B](now,Q){
// res = can = 0;
// cur = N;
//
// for(;;){
// nx = -1;
// rep(i,60) if(las[i] < cur) nx >?= las[i];
// if(nx == -1) break;
//
// ok0 = ok1 = 1;
// rep(i,60) if(las[i] == nx){
// if(now & (1LL << i)) ok1 = 0;
// if(!(now & (1LL << i))) ok0 = 0;
// }
// if(ok0==ok1==0) wt(-1), break_continue;
// if(ok0==0){
// res++;
// now ^= (1LL << 60) - 1;
// }
//
// cur = nx;
// }
// ok0 = ok1 = 1;
// rep(i,60) if(las[i]==-1){
// if(now & (1LL << i)) ok0 = 0;
// if(!(now & (1LL << i))) ok1 = 0;
// }
// if(ok0==ok1==0) wt(-1), continue;
// if(ok0==0) res++;
// wt(res);
// }
// }
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0