zoukankan      html  css  js  c++  java
  • CodeForces 705C Thor

    开30W个vector将数字归类,每一类数字开一个指针P,记录已经阅读到哪一个了,还可以开一个优先队列维护这些指针P。

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<vector>
    #include<map>
    #include<set>
    #include<queue>
    #include<stack>
    #include<iostream>
    using namespace std;
    typedef long long LL;
    const double pi=acos(-1.0),eps=1e-8;
    void File()
    {
        freopen("D:\in.txt","r",stdin);
        freopen("D:\out.txt","w",stdout);
    }
    inline int read()
    {
        char c = getchar();  while(!isdigit(c)) c = getchar();
        int x = 0;
        while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); }
        return x;
    }
    
    const int maxn=300000+10;
    vector<int>g[maxn];
    int n,q,sz,p[maxn],ans;
    
    struct X
    {
        int num,now,pos,idx;
        bool operator < (const X &a) const {
            return idx>a.idx;
        }
        X(int Num,int Now,int Pos,int Idx) {num=Num; now=Now; pos=Pos,idx=Idx;}
    };
    priority_queue<X>Q;
    
    int main()
    {
        scanf("%d%d",&n,&q);
        sz=0; ans=0; memset(p,-1,sizeof p);
        for(int i=1;i<=q;i++)
        {
            int t,d; scanf("%d%d",&t,&d);
            if(t==1)
            {
                ++sz;
                if(p[d]==g[d].size()-1)
                {
                    Q.push(X(d,p[d],p[d]+1,sz));
                }g[d].push_back(sz); ans++;
            }
            else if(t==2)
            {
                ans=ans-(g[d].size()-1-p[d]);
                p[d]=g[d].size()-1;
            }
            else
            {
                while(!Q.empty()&&Q.top().idx<=d)
                {
                    X h=Q.top(); Q.pop();
                    if(h.now<p[h.num]) continue;
                    ans=ans-(h.pos-p[h.num]);
                    p[h.num]=h.pos;
                    if(p[h.num]+1<g[h.num].size())
                        Q.push(X(h.num,p[h.num],p[h.num]+1,g[h.num][p[h.num]+1]));
                }
            }
            printf("%d
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    网页中添加下划线的方法汇总及优缺点
    git备注
    微信小程序封装年月日时分组件
    微信小程序底部弹窗动画
    微信小程序返回上一页的方法并传参
    微信小程序组件封装
    taro中子父传值
    taro初识一
    reactjs中使用高德地图计算两个经纬度之间的距离
    vue中使用scss
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5767473.html
Copyright © 2011-2022 走看看