Description
从左到右一共
n
个数,数字下标从
一共
数据量比较大。
输入请用挂
int read(){
int ans=0;
char last=' ',ch=getchar();
while(ch>='0' && ch<='9')ans=ans*10+ch-'0',ch=getchar();
return ans;
}
输出请用
Input
单组测试数据。
第一行一个整数
n(0<n≤500,000)
。
第二行
n
个整数,
第三行一个数
m
,表示询问次数
接下来
m
行每行三个数,
Output
M
行,每行为
Sample Input
5
1 1 2 4 6
3
1 2 1
2 4 8
3 5 7
Sample Output
YES
NO
NO
Solution
只要
K
可以被区间
Code
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
namespace fastIO
{
#define BUF_SIZE 100000
//fread -> read
bool IOerror=0;
inline char nc()
{
static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;
if(p1==pend)
{
p1=buf;
pend=buf+fread(buf,1,BUF_SIZE,stdin);
if(pend==p1)
{
IOerror=1;
return -1;
}
}
return *p1++;
}
inline bool blank(char ch)
{
return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';
}
inline void read(int &x)
{
char ch;
while(blank(ch=nc()));
if(IOerror)return;
for(x=ch-'0';(ch=nc())>='0'&&ch<='9';x=x*10+ch-'0');
}
#undef BUF_SIZE
};
using namespace fastIO;
typedef pair<int,int>P;
const int maxn=500005;
int n,m,a[maxn];
struct node
{
int val,pos;
node(){};
node(int _val,int _pos){val=_val;pos=_pos;}
}base[maxn][30];
int main()
{
read(n);
for(int i=1;i<=n;i++)read(a[i]);
for(int l=n;l>=1;l--)
{
for(int i=0;i<=29;i++)base[l][i]=base[l+1][i];
node temp=node(a[l],l);
for(int i=29;i>=0;i--)
if((temp.val>>i)&1)
{
if(!base[l][i].val)
{
base[l][i]=temp;
break;
}
else
{
if(temp.pos<base[l][i].pos)swap(base[l][i],temp);
temp.val^=base[l][i].val;
}
}
}
read(m);
while(m--)
{
int l,r,k;
read(l);read(r);read(k);
for(int i=29;i>=0;i--)
if((k>>i)&1)
{
if(base[l][i].val==0||base[l][i].pos>r)break;
k^=base[l][i].val;
}
if(k)puts("NO");
else puts("YES");
}
return 0;
}