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("Yesn");
        else
        printf("Non");
    }
    return 0;
} 
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇