小清新人渣的本愿
#include<bits/stdc++.h> #define ll long long using namespace std; const ll mod = 1e9+7; const ll maxn = 1e5+10; ll n,m,k; ll ans[maxn],cnt[maxn],res=0,a[maxn]; bitset<maxn> now1,now2; struct node{ ll l,r,op,x,qid,blo; ll len(){ return r-l+1; } bool operator<(const node&rhs)const{ if(blo^rhs.blo) return l<rhs.l; return blo & 1 ? r<rhs.r : rhs.r<r; } }q[maxn]; void add(int x){ x=a[x]; if(cnt[x]==0){ now1[x]=1;now2[maxn-x]=1; } cnt[x]++; } void del(int x){ x=a[x]; cnt[x]--; if(cnt[x]==0){ now1[x]=0;now2[maxn-x]=0; } } int main(){ ios::sync_with_stdio(false); cin>>n>>m; for(int i=1;i<=n;++i){ cin>>a[i]; } int block=(int)(sqrt(n>=3?n*(2.0/3):n)); for(int i=1;i<=m;++i){ cin>>q[i].op>>q[i].l>>q[i].r>>q[i].x; q[i].qid=i; q[i].blo=q[i].l/block; } sort(q+1,q+1+m); int l=0,r=0; for(int i =1;i<=m;++i){ while(l < q[i].l)del(l++); while(l > q[i].l)add(--l); while(r < q[i].r)add(++r); while(r > q[i].r)del(r--); if(q[i].op==1){ if((now1&(now1<<q[i].x)).any()) ans[q[i].qid ] = 1; //a a-x a==(a-x)+x } else if(q[i].op==2){ if((now1&(now2>>(maxn-q[i].x))).any()) ans[q[i].qid ] = 1; //a+b==x b==x-a //对于b 我们记录 maxn-b //若存在对应b 则maxn-b -(maxn-x) = x-b =a //这样就能得到验证了 } else{ for(int j=1;j*j<=q[i].x;++j){ if(q[i].x%j) continue; if(now1[j]&&now1[q[i].x/j]){ ans[q[i].qid]=1;break; } } } } for(int i=1;i<=m;++i){ if(ans[i]) cout<<"hana\n"; else cout<<"bi\n"; } return 0; }