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;
    } 
    
  • 相关阅读:
    类别的三个作用
    require()
    commonJS
    ng-app&data-ng-app
    《css网站布局实录》(李超)——读书札记
    高性能JS(读书札记)
    两个同级div重叠的情况
    前端性能优化
    正则表达式
    ajax
  • 原文地址:https://www.cnblogs.com/For-Miku/p/13435003.html
Copyright © 2011-2022 走看看