zoukankan      html  css  js  c++  java
  • 【codeforces85D】

    去实验培训回来了……写个题先玩玩

    这题给人一种平衡树的感觉

    但是呢,实际上操作离线+离散化+线段树一样能做

    #include<bits/stdc++.h>
    #define lson (o<<1)
    #define rson (o<<1|1)
    const int N=2e5+5;
    typedef long long ll;
    using namespace std;
    struct Opt{int tp,num;}op[N];
    int n,a[N],cnt=0,tot=0;
    ll sumv[N<<2],modv[N<<2][5];
    inline void pushup(int o){
        sumv[o]=sumv[lson]+sumv[rson];
        for(int i=0;i<=4;i++){
            int x=(sumv[lson]+i)%5;
            modv[o][x]=modv[lson][x]+modv[rson][i];
        }
    }
    inline void change(int o,int l,int r,int q,int v){
        if(l==r){
            sumv[o]+=v;modv[o][1]=v>0?a[q]:0;
            return;
        }
        int mid=(l+r)>>1;
        if(q<mid)change(lson,l,mid,q,v);
        else change(rson,mid+1,r,q,v);
        pushup(o);
    }
    inline int read(){
        int f=1,x=0;char ch;
        do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
        do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
        return f*x;
    }
    int main(){
        n=read();char s[20];
        for(int i=1;i<=n;i++){
            scanf("%s",s);
            if(s[0]=='a'){op[i].tp=1;op[i].num=read();a[tot++]=op[i].num;}
            else if(s[0]=='d'){op[i].tp=2;a[tot++]=op[i].num=read();}
            else op[i].tp=3;
        }
        sort(a,a+tot);int len=unique(a,a+tot)-a;
        for(int i=1;i<=n;i++){
            if(op[i].tp==1){
                int p=lower_bound(a,a+len,op[i].num)-a;
                change(1,1,len+1,p,1);
            }
            else if(op[i].tp==2){
                int p=lower_bound(a,a+len,op[i].num)-a;
                change(1,1,len+1,p,-1);
            }
            else printf("%I64d
    ",modv[1][3]);
        }
    }
    View Code
  • 相关阅读:
    点击按钮倒计时
    js实现-小框框全选
    CSS文字,文本,背景,盒模型等记录
    xps9560黑苹果展示
    面试——谈谈你对抽象和接口的理解(小知识大考点)
    谈谈你对Java 面向对象思想的理解
    谈谈你对Java 平台的理解
    HashMap1.7 问题总结
    2.3.2 InnoDB内存
    2.3 InnoDB 体系架构
  • 原文地址:https://www.cnblogs.com/zcysky/p/7231617.html
Copyright © 2011-2022 走看看