为何超时?0pts
查看原帖
为何超时?0pts
1235962
chen_1111楼主2024/12/13 19:10
#include<bits/stdc++.h>
using namespace std;
int f[100005][35],n,m,x,l,r,s[100005];
bool ch(int a,int b,int c,int d)
{
    if(a||b)
        return true;
    if(c>d)
        swap(c,d);
    for(int i=c;i<d;i++)
        for(int j=i+1;j<=d;j++)
            if((s[i]^s[j])==x)
                return true;
    return false;
}
int main()
{
    scanf("%d%d%d",&n,&m,&x);
    for(int i=1;i<=n;i++)
        scanf("%d",&s[i]);
    for(int i=1;i<=30;i++)
        for(int j=1;j<=n;j++)
            f[j][i]=ch(f[j][i-1],f[j+1<<(i-1)][i-1],j,j+1<<(i-1));
    while(m--)
    {
        cin>>l>>r;
        int k=log2(r-l+1);
        if(ch(f[l][k],f[r-(1<<k)+1][k],l,r-1<<k+1))
            printf("yes\n");
        else
            printf("no\n");
    }
}
2024/12/13 19:10
加载中...