#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int bl[N],n,m,a[N],t[N],ans[N],mx,cnt,ct;
struct node{
int type,l,r,id,x;
}q[N],tmp[N];
bool cmp(node a,node b){
return bl[a.l]==bl[b.l]?(bl[a.l]&1?a.r<b.r:a.r>b.r):a.l<b.l;
}
bool cp(node a,node b){
return a.x<b.x;
}
bitset<N> S,s;
bool cal(int type,int x){
if (type==1){
return (s&(s<<x)).any();
}
else if (type==2){
return (S&(s<<(N-x))).any();
}
else if (type==3){
for (int i=1;i*i<=x;i++){
if (x%i==0&&s[i]&&s[x/i]) return 1;
}
return 0;
}
else {
for (int i=0;i*x<=mx;i++){
if (s[i]&&s[i*x]) return 1;
}
return 0;
}
}
void add(int x){
x=a[x];S[N-x]=s[x]=++t[x];
}
void del(int x){
x=a[x];S[N-x]=s[x]=--t[x];
}
int pre[N],dp[N];
void calc(int x){
memset(pre,0,sizeof(pre));
memset(dp,0,sizeof(dp));
for (int i=1;i<=n;i++){
pre[a[i]]=i;
dp[i]=max(dp[i-1],max(a[i]%x==0?pre[a[i]/x]:0,a[i]*x<=mx?pre[a[i]*x]:0));
}
}
signed main(){
ios::sync_with_stdio(0);
cin>>n>>m;
int len=sqrt(n);
for (int i=1;i<=n;i++){
bl[i]=(i-1)/len+1;
cin>>a[i];
mx=max(mx,a[i]);
}
for (int i=1;i<=m;i++){
cin>>q[++cnt].type>>q[cnt].l>>q[cnt].r>>q[cnt].x;
q[cnt].id=i;
if (q[cnt].type==4&&q[cnt].x<=len){
tmp[++ct]=q[cnt];
cnt--;
}
}
sort(q+1,q+1+cnt,cmp);
int l=1,r=0;
for (int i=1;i<=cnt;i++){
int L=q[i].l,R=q[i].r;
while (l<L) del(l++);
while (l>L) add(--l);
while (r<R) add(++r);
while (r>R) del(r--);
ans[q[i].id]=cal(q[i].type,q[i].x);
}
sort(tmp+1,tmp+1+ct,cp);
for (int i=1;i<=ct;i++){
if (tmp[i].x!=tmp[i-1].x){
calc(tmp[i].x);
}
ans[tmp[i].id]=dp[tmp[i].r]>=tmp[i].l;
}
for (int i=1;i<=m;i++){
if (ans[i]) cout<<"yuno\n";
else cout<<"yumi\n";
}
return 0;
}
这份代码在本地测样例输出为:
yuno
yumi
yuno
yuno
yuno
但是在洛谷 ide 上输出为:
yuno
yumi
yuno
yuno
yumi
并且可以通过此题。
这是为什么呢?