zoukankan      html  css  js  c++  java
  • luogu P4137 Rmq Problem / mex

    传送门w

    一道莫队

    完全不会

    yfl dalao表示我太菜了这道题贼简单

    qaqqq

    orz我对不起讲过莫队的yfl dalao

    真的是纯纯纯莫队emmm

    #include<cstdio>
    #include<cmath>
    #include<algorithm>
    #define sev en
    using namespace std;
    #define N 200010
    
    int n,m,a[N],s,num[N],ans[N],L = 1,R;
    struct EDGE{
        int l,r,blo,id;
        bool operator < (const EDGE &x) const{
        return blo < x.blo || (blo == x.blo && r < x.r);
        }
    }e[N];
    
    void add(int x){
        num[a[x]]++;
        int i = s;
        while(num[i])
        i++;
        s = i;
    }
    
    void del(int x){
        num[a[x]]--;
        if(num[a[x]] == 0)
        s = min(s,a[x]);
    }
    
    void Mo(){
        for(int i = 1;i <= m;i++){
        int l = e[i].l,r = e[i].r;
        while(L > l)
            add(--L);
        while(R < r)
            add(++R);
        while(L < l)
            del(L++);
        while(R > r)
            del(R--);
        ans[e[i].id] = s;
        }
    }
    
    int main(){
        scanf("%d%d",&n,&m);
        int sq = sqrt(n);
        for(int i = 1;i <= n;i++)
        scanf("%d",&a[i]);
        for(int i = 1;i <= m;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        e[i].l = x;
        e[i].r = y;
        e[i].id = i;
        e[i].blo = (x - 1) / sq + 1;
        }
        sort(e + 1,e + m + 1);
        Mo();
        for(int i = 1;i <= m;i++)
        printf("%d
    ",ans[i]);
        return 0;
    }
    像是板子一样的莫队

    qaqqq

    我现在博客怎么都这么水了

     

  • 相关阅读:
    MSP430程序库<十四>DMA程序库
    MSP430程序库<十三>硬件乘法器使用
    MSP430程序库<十五>Flash控制器
    MSP430程序库<九>数码管显示
    [debug] 调试小结
    SourceInsight Shortcuts
    git commands
    Linux常用命令
    [转] 宏点滴
    Linux 开发
  • 原文地址:https://www.cnblogs.com/sevenyuanluo/p/10765288.html
Copyright © 2011-2022 走看看