QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#376795#6631. Maximum Bitwise ORzhulexuanWA 97ms9884kbC++144.0kb2024-04-04 16:44:292024-04-04 16:44:31

Judging History

你现在查看的是最新测评结果

  • [2024-04-04 16:44:31]
  • 评测
  • 测评结果:WA
  • 用时:97ms
  • 内存:9884kb
  • [2024-04-04 16:44:29]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf INT_MAX
#define fr(i,l,r) for (i=(l); i<=(r); i++)
#define rfr(i,l,r) for (i=(l); i>=(r); i--)
template<typename T>inline void read(T &n){
    T w=1; n=0; char ch=getchar();
    while (!isdigit(ch) && ch!=EOF){ if (ch=='-') w=-1; ch=getchar(); }
    while (isdigit(ch) && ch!=EOF){ n=(n<<3)+(n<<1)+(ch&15); ch=getchar(); }
    n*=w;
}
template<typename T>inline void write(T x){
    if (x==0){ putchar('0'); return ; }
    T tmp;
    if (x>0) tmp=x;
    else tmp=-x;
    if (x<0) putchar('-');
    char F[105];
    long long cnt=0;
    while (tmp){
        F[++cnt]=tmp%10+48;
        tmp/=10;
    }
    while (cnt) putchar(F[cnt--]);
}
#define Min(x,y) x = min(x,y)
#define Max(x,y) x = max(x,y)
//基础配置=================================================================================
const ll N = 100005 , A = 35;
ll n,m,q,ans=0,x,y,l,r,s,z;
ll a[N];
ll sum[N][A];
struct infor{
    ll f[A];
    void clear(){
        memset(f,0,sizeof(f));
    }
    void insert(ll x){
        ll i;
        fr(i,0,30)
            Max(f[i],x^(x-(1ll<<i)));
    }
};
infor operator + (infor x,const infor y){
    ll i;
    fr(i,0,30)
        Max(x.f[i],y.f[i]);
    return x;
}
struct ST{
    ll lg[N];
    infor f[N][21];
    void init(){
        ll i,j;
        lg[1] = 0;
        fr(i,2,n) lg[i] = lg[i>>1]+1;
        fr(i,1,n){
            f[i][0].clear();
            f[i][0].insert(a[i]);
        }
        for (i=1; (1ll<<i)<=n; i++)
            fr(j,1,n-(1ll<<i)+1)
                f[i][j] = f[i-1][j] + f[i-1][j+(1<<i-1)];
    }
    infor qry(ll l,ll r){
        ll k = lg[r-l+1];
        return f[l][k] + f[r-(1<<k)+1][k];
    }
};
ST t;
void init(){
    ll i,j;
    fr(i,0,n+1)
        memset(sum[i],0,sizeof(sum[i]));
    fr(i,1,n){
        fr(j,0,30) sum[i][j] = sum[i-1][j];
        fr(j,0,30)
            if (a[i]&(1ll<<j)) sum[i][j]++;
    }
    t.init();
}
void work(ll l,ll r){
    ll i,j;
    ll cnt=0,pos[A];
    ll ans = 0;
    fr(i,0,30)
        if (sum[r][i]!=sum[l-1][i]) ans = (1ll<<i+1)-1;
    write(ans); putchar(' ');
    bool flag = true;
    fr(i,0,30)
        if ((1ll<<i)<=ans && sum[r][i]==sum[l-1][i]) flag = false;
    if (flag){ printf("0\n"); return ; }
    fr(i,0,30){
        if (sum[r][i]-sum[l-1][i]!=1) continue;
        ll lf,rh,mid;
        lf = l; rh = r;
        while (lf<rh){
            mid = (lf+rh)>>1;
            if (sum[mid][i]-sum[l-1][i]==1) rh = mid;
            else lf = mid+1;
        }
        pos[++cnt] = lf;
    }
    sort(pos+1,pos+1+cnt);
    ll len = 1;
    fr(i,2,cnt)
        if (pos[i]!=pos[len]) pos[++len] = pos[i];
    cnt = len;
    infor f; f.clear();
    ll ls = l;
    fr(i,1,cnt){
        if (pos[i]<=ls) continue;
        if (ls<pos[i]) f = f + t.qry(ls,pos[i]-1);
        Max( ls , pos[i]+1 );
    }
    if (ls<=r) f = f + t.qry(ls,r);
    ll v[A];
    fr(i,1,cnt) v[i] = a[pos[i]];
    // f + v
    ll b1[A],b2[A];
    b1[0] = b2[cnt+1] = 0;
    fr(i,1,cnt) b1[i] = b1[i-1] | v[i];
    rfr(i,cnt,1) b2[i] = b2[i+1] | v[i];
    ll dlt = 0;
    fr(i,0,30)
        if (sum[r][i]-sum[l-1][i]<=1) dlt |= 1ll<<i;
    fr(i,0,30){
        if (f.f[i]==dlt){
            printf("1\n");
            return ;
        }
    }
    fr(i,1,cnt){
        ll dv = b1[i-1] | b2[i+1];
        fr(j,0,30){
            ll vv = v[i] ^ (v[i]-(1ll<<j));
            vv |= dv;
            if (vv==dlt){
                printf("1\n");
                return ;
            }
        }
    }
    printf("2\n");
    return ;
}
void solve(){
    ll i,j;
    read(n); read(q);
    fr(i,1,n) read(a[i]);
    init();
    while (q--){
        read(l); read(r);
        work(l,r);
        // ll ans = calc(l,r);
        // write(ans); putchar('\n');
    }
}
int main(){
	// freopen("a.in","r",stdin);
//	freopen(".out","w",stdout);
    ll qt;
    read(qt);
    while (qt--) solve();
    return 0;
}
//g++ a.cpp -o a -Wall -Wl,--stack=5120000000

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9884kb

input:

1
3 2
10 10 5
1 2
1 3

output:

15 2
15 0

result:

ok 4 number(s): "15 2 15 0"

Test #2:

score: 0
Accepted
time: 76ms
memory: 7832kb

input:

100000
1 1
924704060
1 1
1 1
149840457
1 1
1 1
515267304
1 1
1 1
635378394
1 1
1 1
416239424
1 1
1 1
960156404
1 1
1 1
431278082
1 1
1 1
629009153
1 1
1 1
140374311
1 1
1 1
245014761
1 1
1 1
445512399
1 1
1 1
43894730
1 1
1 1
129731646
1 1
1 1
711065534
1 1
1 1
322643984
1 1
1 1
482420443
1 1
1 1
20...

output:

1073741823 2
268435455 2
536870911 2
1073741823 2
536870911 2
1073741823 2
536870911 2
1073741823 2
268435455 2
268435455 2
536870911 2
67108863 2
134217727 2
1073741823 2
536870911 2
536870911 2
268435455 2
536870911 2
536870911 2
536870911 2
268435455 2
268435455 2
1073741823 2
16777215 2
10737418...

result:

ok 200000 numbers

Test #3:

score: 0
Accepted
time: 96ms
memory: 7908kb

input:

50000
2 2
924896435 917026400
1 2
1 2
2 2
322948517 499114106
1 2
2 2
2 2
152908571 242548777
1 1
1 2
2 2
636974385 763173214
1 2
1 1
2 2
164965132 862298613
1 1
1 2
2 2
315078033 401694789
1 2
1 2
2 2
961358343 969300127
2 2
1 2
2 2
500628228 28065329
1 2
1 2
2 2
862229381 863649944
1 2
2 2
2 2
541...

output:

1073741823 2
1073741823 2
536870911 2
536870911 2
268435455 2
268435455 2
1073741823 2
1073741823 2
268435455 2
1073741823 2
536870911 2
536870911 2
1073741823 2
1073741823 2
536870911 2
536870911 2
1073741823 2
1073741823 2
1073741823 2
268435455 2
536870911 2
536870911 2
1073741823 2
1073741823 2
...

result:

ok 200000 numbers

Test #4:

score: -100
Wrong Answer
time: 97ms
memory: 5796kb

input:

33333
3 3
925088809 339284112 289540728
3 3
1 3
1 1
3 3
422399522 892365243 216341776
3 3
3 3
1 2
3 3
668932010 837523227 840095874
1 3
1 3
3 3
3 3
731584574 357877180 359063739
1 1
1 1
3 3
3 3
463358343 833924976 847087403
2 3
3 3
1 2
3 3
377154649 772000701 656357011
2 3
1 2
2 3
3 3
977492169 5540...

output:

536870911 2
1073741823 2
1073741823 2
268435455 2
268435455 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
536870911 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
67108863 2
1073741823 2
1073741...

result:

wrong answer 5770th numbers differ - expected: '1', found: '2'