zoukankan      html  css  js  c++  java
  • 小清新人渣的本愿

    #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
    ";
            else        cout<<"bi
    ";
        }
        return 0;
    }
  • 相关阅读:
    js 提示框的实现---组件开发之(一)
    js 原型链
    js 哈希路由原理实现
    js 弹窗的实现
    js 滑动门的实现
    Delphi IDFtp用法,包含断点续传
    memortstream Base64编码和filestream base64编码不同
    Delphi另一个多线程函数:BeginThread用法
    delphi 讲的比较详细的多线程(推荐)
    多线程简单实用
  • 原文地址:https://www.cnblogs.com/PdrEam/p/14686480.html
Copyright © 2011-2022 走看看