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

    传送门

    Solution

    莫队,用bitset来存储出现的数

    如果是和或者差,直接通过左移右移就可以实现判断

    对于积的询问,暴力判就行了,因数只要枚举(sqrt n)

    总复杂度是(O(n^2/32)),反正(3s)是可以过的咯


    Code 

    #include<bits/stdc++.h>
    #define ll long long
    #define max(a,b) ((a)>(b)?(a):(b))
    #define min(a,b) ((a)<(b)?(a):(b))
    inline int read()
    {
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
        return x*f;
    }
    #define MN 100005
    #define N MN
    int n,m,a[MN],T;
    bool Ans[MN];
    std::bitset<N> now,fnow;
    struct ques{
        int l,r,opt,x,id,pl;
        bool operator <(const ques&o)const{return (pl^o.pl)?(pl<o.pl):(r<o.r);}
    }q[MN];
    int num[MN];
    int main()
    {
        //freopen("testdata.in","r",stdin);
        //freopen("testdata.out","w",stdout);
        n=read();m=read();
        register int i;T=ceil(sqrt((double)n));
        for(i=1;i<=n;++i) a[i]=read();
        now.reset();fnow.reset();
        for(i=1;i<=m;++i)
        {
            q[i].opt=read(),q[i].l=read(),q[i].r=read();
            q[i].x=read(),q[i].pl=(q[i].l-1)/T+1;q[i].id=i;
        }
        std::sort(q+1,q+m+1);
        register int l=1,r=0,j;
        for(i=1;i<=m;++i)
        {
            //printf("l=%d r=%d
    ",q[i].l,q[i].r);
            for(;r<q[i].r;++r) if(!num[a[r+1]]++) now[a[r+1]]=1,fnow[N-a[r+1]]=1;
            for(;l>q[i].l;--l) if(!num[a[l-1]]++) now[a[l-1]]=1,fnow[N-a[l-1]]=1;
            for(;r>q[i].r;--r) if(!(--num[a[r]])) now[a[r]]=0,fnow[N-a[r]]=0;
            for(;l<q[i].l;++l) if(!(--num[a[l]])) now[a[l]]=0,fnow[N-a[l]]=0;
            //std::cout<<now<<std::endl<<fnow<<std::endl;
            if(q[i].opt==1) Ans[q[i].id]=(now&(now<<q[i].x)).any();
            else if(q[i].opt==2) Ans[q[i].id]=((now<<(N-q[i].x))&fnow).any();
            else
            {
                for(j=1;j*j<=q[i].x;j++)
                    if(q[i].x%j==0) if(now[j]&&now[q[i].x/j]){Ans[q[i].id]=1;break;}
            }
        }
        for(i=1;i<=m;++i) puts(Ans[i]?"hana":"bi");
        return 0;
    }
    


    Blog来自PaperCloud,未经允许,请勿转载,TKS!

  • 相关阅读:
    从客户端(&)中检测到有潜在危险的 Request.Path 值。
    对访问修饰关键字public, protected, internal and private的说明
    C#综合揭秘——细说多线程(下)
    iis下配置:php+mysql
    工厂模式(Factory Patter)
    HDU 1040 As Easy As A+B [补]
    HDU 1020 Encoding
    HDU 1076 An Easy Task
    UVA 100 The 3n + 1 problem
    民大OJ 1668 追杀系列第二发
  • 原文地址:https://www.cnblogs.com/PaperCloud/p/10174020.html
Copyright © 2011-2022 走看看