hdoj 4288coder cf 85d Sum of Medians
题目链接
这两个题目是一样的,大概题意是有3个操作 add x, 在集合中加入x, del x 是删除x, sum 是求出由小到大排序后所有下标mod5等于3的数的和。
这个在hdoj上面,这个题给的时间比较多10s,我用了stl 里的vector和 lower_bound, lower_bound 它的作用是返回不小于x的第一个数的位置,这样我们每次插入后就能保证他有序。 最终耗时6234MS,而这种方法在codeforces上超时了,cf只给了3000ms,这道题的标准做法是用线段树。
先给出stl的做法
//2013-05-18-20.17
// hdoj 4288 cf 85d
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;char op[5];
vector<int> v;int main()
{int n, x;while (scanf("%d", &n) != EOF){v.clear();while (n--){scanf("%s", op);if (op[0] == 's'){__int64 ans = 0;for (int i = 2; i < v.size(); i += 5)ans += v[i];printf("%I64d\n", ans);}else{scanf("%d", &x);if (op[0] == 'a')v.insert(lower_bound(v.begin(), v.end(), x), x);elsev.erase(lower_bound(v.begin(), v.end(), x));}}}return 0;
}
转载于:https://www.cnblogs.com/xindoo/archive/2013/05/18/3595096.html
hdoj 4288coder cf 85d Sum of Medians相关推荐
- codeforces 85D. Sum of Medians
二次联通门 : codeforces 85D. Sum of Medians /*codeforces 85D. Sum of Medians正解线段树或是平衡树结果用vector暴力卡过去了 */ ...
- codeforces 85D. Sum of Medians(线段树or分块)
题目链接:codeforces 85D. Sum of Medians 题意: add x 表示向集合中添加x(添加x的时候保证x是第一次被添加入集合) del x 表示从集合中删除x (删除x的时候 ...
- Codeforces 85D Sum of Medians(线段树)
题目链接:Codeforces 85D - Sum of Medians 题目大意:N个操作,add x:向集合中添加x:del x:删除集合中的x:sum:将集合排序后,将集合中所有下标i % 5 ...
- Codeforces 85D Sum of Medians
传送门 D. Sum of Medians time limit per test 3 seconds memory limit per test 256 megabytes input standa ...
- CodeForces 85D Sum of Medians Splay | 线段树
Sum of Medians 题解: 对于这个题目,先想到是建立5棵Splay,然后每次更新把后面一段区间的树切下来,然后再转圈圈把切下来的树和别的树合并. 但是感觉写起来太麻烦就放弃了. 建立5棵线 ...
- Codeforces 85D Sum of Medians[线段树]
题意:给了一个set,有n个操作,有三种操作 1. add x 把 x 放入set中: 2. del x 把 x 从set中删去: 3. sum 求set中,第n大的数,n%5==3,的总和. 分 ...
- 85D - Sum of Medians
又一题线段树哦,要进行离散化处理 题目有三种操作 把位置x填上 把位置x的数去掉 询问当前序列中存在的数,位置按照顺序%5之后余3的数的和... 哇...感觉我没说清楚题意 不过看代码吧,给代码加了个 ...
- Sum of Medians CodeForces - 85D(线段树+离散化)
Sum of Medians 题目链接:CodeForces - 85D 题意:对于一个集合set(有序的)有三个操作(集合是有序的,下标由1开始): 一:add x:在集合中加入x; 二:del ...
- 「一题多解」【CodeForces 85D】Sum of Medians(线段树 / 分块)
题目链接 [CodeForces 85D]Sum of Medians 题目大意 实现一个setsetset,支持插入,删除,求∑a5k+3∑a5k+3\sum a_{5k+3}.注意,setsets ...
最新文章
- 【CLR via C#】CSC将源代码编译成托管模块
- PHP的查找stripos strpos strripos strpos
- react封装函数_GitHub - daifee/react-component: 用 React 封装一套常用组件
- 深度优先搜索知识总结
- XHTML教会我的一些东西-1
- uva 1218——Perfect Service
- 王译潇20162314 第九周作业总结
- Shell date连接mysql执行指令
- NetApp 数据存储 AFF 和 FAS 系统的磁盘架和存储介质
- 云打印SDK来袭,支持飞鹅云,芯烨云,易联云,优声云等云打印机
- 正睿(比赛--Day10)
- htc android sd卡,HTC M8支持扩展储存卡吗?HTC M8支持多大的储存卡?
- 小程序源码:随机头像大全,多分类带历史记录-多玩法安装简单
- 【编程学习】浅谈哈希表及用C语言构建哈希表!
- [图像] 金字塔模型
- 重庆大学计算机科学与工程学院,何中市
- SpringAop代理模式
- maven配置项目根路径_maven配置src/resources默认目录
- 4.11 数值分析: 求重根/带参数m的牛顿迭代法
- Java字符串转数组,数组转字符串