zoukankan      html  css  js  c++  java
  • Codeforces Round #466 (Div. 2) F. Machine Learning 莫队+分块 带修莫队的模板题

    #include <bits/stdc++.h>
    #define N 300005
    #define ll long long
    using namespace std;
    int n,m,tot,opcnt,qcnt,B,now;
    int a[N],A[N],output[N],cnt[N],mex[N];
    struct query
    {
        int l,r,id,t;
        bool operator<(query b) const
        {
            return l/B==b.l/B?(r/B==b.r/B?t<b.t:r<b.r):l<b.l;
        }
    } q[N];
    struct change
    {
        int p,x;
    } c[N];
    void add(int num)
    {
        --mex[cnt[num]];
        ++mex[++cnt[num]];
    }
    void del(int num)
    {
        --mex[cnt[num]];
        ++mex[--cnt[num]];
    }
    void update(int id,int t)
    {
        if(c[t].p>=q[id].l&&c[t].p<=q[id].r)
        {
            del(a[c[t].p]);
            add(c[t].x);
        }
        swap(c[t].x, a[c[t].p]);
    }
    int getans()
    {
        int i;
        for(i=1; mex[i]>0; ++i);
        return i;
    }
    int main()
    {
        int l=2,r=1;
        scanf("%d%d",&n,&m);
        B=pow(n,0.6666);
        for(int i=1; i<=n; ++i)
        {
            scanf("%d",&a[i]);
            A[++tot]=a[i];
        }
        for(int i=1; i<=m; ++i)
        {
            int op,a,b;
            scanf("%d%d%d",&op,&a,&b);
            if(op==1)
            {
                ++qcnt;
                q[qcnt]={a,b};
                q[qcnt].id=qcnt;
                q[qcnt].t=opcnt;
            }
            else
            {
                ++opcnt;
                c[opcnt]={a,b};
                A[++tot]=b;
            }
        }
        sort(A+1,A+1+tot);
        for(int i=1; i<=n; ++i) 
            a[i]=lower_bound(A+1,A+1+tot,a[i])-A;
        for(int i=1; i<=opcnt; ++i) 
            c[i].x=lower_bound(A+1,A+1+tot,c[i].x)-A;
        sort(q+1,q+1+qcnt);
        for(int i=1; i<=qcnt; ++i)
        {
            while(l>q[i].l) add(a[--l]);
            while(r<q[i].r) add(a[++r]);
            while(l<q[i].l) del(a[l++]);
            while(r>q[i].r) del(a[r--]);
            while(now<q[i].t) update(i, ++now);
            while(now>q[i].t) update(i, now--);
            output[q[i].id]=getans();
        }
        for(int i=1; i<=qcnt; ++i) 
            printf("%d
    ",output[i]);
        return 0;
    }
  • 相关阅读:
    写代码的方法与思考
    改变文件上传input file类型的外观
    关于HTML Button点击自动刷新页面的问题解决
    使用 git push 出现error setting certificate verify locations问题记录
    flex使用学习
    jQuery.fn.extend()
    jQuery extend()
    作用域
    私有变量
    模仿块级作用域
  • 原文地址:https://www.cnblogs.com/QingyuYYYYY/p/12929991.html
Copyright © 2011-2022 走看看