zoukankan      html  css  js  c++  java
  • P3901 数列找不同

    Miku

    还是莫队板子

    啥叫互不相同?区间内不同的元素的数量==区间元素数

    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<cstdio>
    #include<cmath>
    using namespace std;
    int l=1,r;
    int cnt;
    int now[100005];
    struct q{
    	int l;
    	int r;
    	int id;
    }qo[100005];
    int n,m;
    int block[100005];
    int b;
    int f[100005];
    int ans[100005];
    bool cmp(q x, q y){
    	return block[x.l]==block[y.l] ? x.r<y.r : block[x.l]<block[y.l];
    }
    void add(int x){
    	if(now[f[x]]==0)
    	cnt++;
    	now[f[x]]++;
    }
    void del(int x){
    	now[f[x]]--;
    	if(now[f[x]]==0)
    	cnt--;
    }
    int main(){
    	scanf("%d%d",&n,&m);
    	b=ceil(sqrt(n));
    	for(int i=1;i<=b;++i){
    		for(int j=(i-1)*b;j<=i*b;++j)
    			block[j]=i;
    	}
    	for(int i=1;i<=n;++i){
    		scanf("%d",&f[i]);
    	}
    	for(int i=1;i<=m;++i){
    		scanf("%d%d",&qo[i].l,&qo[i].r);
    		qo[i].id=i;
    	}
    	sort(qo+1,qo+1+m,cmp);
    	for(int i=1;i<=m;++i){
    
    		while(l<qo[i].l){
    			del(l++);
    		}
    		while(l>qo[i].l){
    			add(--l);
    		}
    		while(r<qo[i].r){
    			add(++r);
    		}
    		while(r>qo[i].r){
    			del(r--);
    		}
    		if(qo[i].r-qo[i].l+1==cnt){
    			ans[qo[i].id]=1;
    		}else{
    			ans[qo[i].id]=0;
    		}
    	}	
    	for(int i=1;i<=m;++i){
    		if(ans[i])
    		printf("Yes
    ");
    		else
    		printf("No
    ");
    	}
    	return 0;
    } 
    
  • 相关阅读:
    N++ 道ASP.NET面试题
    Console-算法:fun1(do while)
    软件业:印度比中国强在哪
    印度软件业崛起的奥妙
    算法目录
    scala目录
    scala命令
    Spark目录
    Ubuntu目录
    Java核心技术卷二部分笔记
  • 原文地址:https://www.cnblogs.com/For-Miku/p/13435003.html
Copyright © 2011-2022 走看看