又一题线段树哦,要进行离散化处理

题目有三种操作
把位置x填上
把位置x的数去掉
询问当前序列中存在的数,位置按照顺序%5之后余3的数的和。。。
哇。。。感觉我没说清楚题意

不过看代码吧,给代码加了个小宠物,23333~

/*********************
welcome to view my codes
┏┛┻━━━┛┻┓
┃|||||||┃
┃   ━   ┃
┃ ┳┛  ┗┳ ┃
┃       ┃
┃   ┻   ┃
┃       ┃
┗━┓   ┏━┛┃ 史 ┃  ┃ 诗 ┃  ┃ 之 ┃  ┃ 宠 ┃┃   ┗━━━┓┃AC 与我同在 ┣┓┃做题专用宠物 ┃┗┓┓┏━┳┓┏┛┃┫┫ ┃┫┫┗┻┛ ┗┻┛
**********************/#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <bitset>
#include <map>#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define mem(i,a) memset(i,a,sizeof(i))
#define rson mid+1,r,rt<<1|1
#define lson l,mid,rt<<1#define mp make_pair
#define pb push_back
#define ll long long
#define LL long long
using namespace std;
template <typename T>inline void read(T &_x_){_x_=0;bool f=false;char ch=getchar();while (ch<'0'||ch>'9') {if (ch=='-') f=!f;ch=getchar();}while ('0'<=ch&&ch<='9') {_x_=_x_*10+ch-'0';ch=getchar();}if(f) _x_=-_x_;
}
const double eps = 0.0000001;
const int maxn = 2e5+7;
const int mod = 1e9+7;struct op{char ch[5];int num;
}v[maxn];
int n,d[maxn],cnt=0,tot=0;
ll sum[maxn<<2],mo[maxn<<2][5];void pushup(int rt){sum[rt] = sum[rt<<1]+sum[rt<<1|1];for(int i=0;i<5;i++){int k = (sum[rt<<1]+i)%5;mo[rt][k] = mo[rt<<1][k] + mo[rt<<1|1][i];}
}void update(int l,int r,int rt,int p,int val){if(l==r){sum[rt]+=val;if(val>0) mo[rt][1]=d[p];else mo[rt][1]=0;return;}int mid=(l+r)/2;if(mid>p) update(lson,p,val);else update(rson,p,val);pushup(rt);
}int main(){read(n);FOR(i,1,n){scanf("%s",v[i].ch);if(v[i].ch[0]=='a'){scanf("%d",&v[i].num);d[tot++]=v[i].num;}else if(v[i].ch[0]=='d'){scanf("%d",&v[i].num);d[tot++]=v[i].num;}else{v[i].num=cnt++;}}sort(d,d+tot);int pos = unique(d,d+tot)-d;FOR(i,1,n){if(v[i].ch[0]=='a'){int p = lower_bound(d,d+pos,v[i].num)-d;update(1,pos+1,1,p,1);}else if(v[i].ch[0]=='d'){int p = lower_bound(d,d+pos,v[i].num)-d;update(1,pos+1,1,p,-1);}else{printf("%I64d\n",mo[1][3]);}}return 0;
}

85D - Sum of Medians相关推荐

  1. codeforces 85D. Sum of Medians

    二次联通门 : codeforces 85D. Sum of Medians /*codeforces 85D. Sum of Medians正解线段树或是平衡树结果用vector暴力卡过去了 */ ...

  2. codeforces 85D. Sum of Medians(线段树or分块)

    题目链接:codeforces 85D. Sum of Medians 题意: add x 表示向集合中添加x(添加x的时候保证x是第一次被添加入集合) del x 表示从集合中删除x (删除x的时候 ...

  3. Codeforces 85D Sum of Medians(线段树)

    题目链接:Codeforces 85D - Sum of Medians 题目大意:N个操作,add x:向集合中添加x:del x:删除集合中的x:sum:将集合排序后,将集合中所有下标i % 5 ...

  4. Codeforces 85D Sum of Medians

    传送门 D. Sum of Medians time limit per test 3 seconds memory limit per test 256 megabytes input standa ...

  5. CodeForces 85D Sum of Medians Splay | 线段树

    Sum of Medians 题解: 对于这个题目,先想到是建立5棵Splay,然后每次更新把后面一段区间的树切下来,然后再转圈圈把切下来的树和别的树合并. 但是感觉写起来太麻烦就放弃了. 建立5棵线 ...

  6. hdoj 4288coder cf 85d Sum of Medians

    题目链接 这两个题目是一样的,大概题意是有3个操作 add x, 在集合中加入x, del x 是删除x, sum 是求出由小到大排序后所有下标mod5等于3的数的和. 这个在hdoj上面,这个题给的 ...

  7. Codeforces 85D Sum of Medians[线段树]

    题意:给了一个set,有n个操作,有三种操作 1. add  x 把 x 放入set中: 2. del  x 把 x 从set中删去: 3. sum 求set中,第n大的数,n%5==3,的总和. 分 ...

  8. Sum of Medians CodeForces - 85D(线段树+离散化)

    Sum of Medians 题目链接:CodeForces - 85D 题意:对于一个集合set(有序的)有三个操作(集合是有序的,下标由1开始): 一:add x:在集合中加入x; 二:del  ...

  9. 「一题多解」【CodeForces 85D】Sum of Medians(线段树 / 分块)

    题目链接 [CodeForces 85D]Sum of Medians 题目大意 实现一个setsetset,支持插入,删除,求∑a5k+3∑a5k+3\sum a_{5k+3}.注意,setsets ...

最新文章

  1. Apache Thrift - java开发详解
  2. boost::math::barycentric_rational用法的测试程序
  3. Valgrind简单用法
  4. 汇编语言学习笔记(五)
  5. 数据结构java语言描述朱战立_数据结构——树(Java语言描述)
  6. IDEA工作笔记-自动生成POJO或JPA的实体类
  7. java.sql.SQLException: 关闭的连接 解决办法
  8. 牛客寒假算法集训营(4)
  9. 软考高项——计算专题
  10. 第三十一章 SQL命令 DROP DATABASE
  11. HTML5系列代码:注册商标reg_和版权商标copy
  12. 【UE4 C++】实现发出伤害与接收伤害
  13. Python初识对象
  14. 运用python编写凯撒密码并实现_凯撒密码实现英文短句的加解密
  15. android手机屏AMOLED如何驱动?
  16. matlab 线性系统响应,MATLAB线性系统时域响应分析实验
  17. irst-missing-positive
  18. 微光图像增强的零参考深度曲线估计
  19. php框架体验demo,JFinal框架demo运行示例教程
  20. s110 raid linux,dell s110阵列卡驱动下载

热门文章

  1. Java画布:直线三角形,矩形,椭圆等
  2. recyclerview的条目添加点击事件
  3. 甘特图制定项目计划,提高项目管理效率
  4. Strategy (策略)模式
  5. jquery--拖拽效果
  6. day03_《谷粒商城》的完整流程(详细版二)
  7. 摩斯密码(Morse)——python解密
  8. Data Analysis
  9. Beautiful Soup:4 kinds of objects
  10. PADS9.5如何导出的光绘文件(Gerber),应该检查什么?