码迷,mamicode.com
首页 > 其他好文 > 详细

【codeforces85D】

时间:2017-07-24 23:35:00      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:log   style   getchar   type   ++   inline   pre   pen   push   

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

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

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

技术分享
#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\n",modv[1][3]);
    }
}
View Code

 

【codeforces85D】

标签:log   style   getchar   type   ++   inline   pre   pen   push   

原文地址:http://www.cnblogs.com/zcysky/p/7231617.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!