Codeforces 85 D. Sum of Medians
题目链接:http://codeforces.com/contest/85/problem/D
做法果然男默女泪啊.....
大概就是直接开了一个$vector$每次插入删除都用自带的$insert$和$erase$,然后查询也是暴力搞。
那么为啥么过得很有理有据呢?
1.首先考虑如果没有修改我就能继承上一次的答案...
2.修改我们假设(就是)${O(logn)}$的。
3.每次暴力查询是$5$个数字一步。
4.显然一开始并不是上来就有${100000}$个数字
所以大概复杂度会是${O(n^{2}/40)}$的....
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<cstring>
using namespace std;
#define maxn 10010
#define llg int
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
llg n,m,w,x;
vector<llg>a;
long long ans;
bool pd;
char s[];
inline int getint()
{
int w=,q=; char c=getchar();
while((c<'' || c>'') && c!='-') c=getchar(); if(c=='-') q=,c=getchar();
while (c>='' && c<='') w=w*+c-'', c=getchar(); return q ? -w : w;
} int main()
{
yyj("sum");
cin>>n;
while (n--)
{
scanf("%s",s);
if (s[]=='s')
{
if (!pd) {printf("%lld\n",ans); continue;}
ans=;
w=a.size();
for (llg i=;i<w;i+=) ans+=a[i];
pd=false;
printf("%lld\n",ans);
}
else
{
x=getint();
if (s[]=='a') a.insert(lower_bound(a.begin(),a.end(),x),x);
else a.erase(lower_bound(a.begin(), a.end(), x));
pd=true;
}
}
return ;
}
当然正解也是可以想出来的,就是一个线段树每个点维护所有数字%5=x的数字和,然后记录右移多少。
Codeforces 85 D. Sum of Medians的更多相关文章
- codeforces 85D D. Sum of Medians Vector的妙用
D. Sum of Medians Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/prob ...
- codeforces 85D D. Sum of Medians 线段树
D. Sum of Medians time limit per test 3 seconds memory limit per test 256 megabytes input standard i ...
- Coderforces 85 D. Sum of Medians(线段树单点修改)
D. Sum of Medians time limit per test 3 seconds memory limit per test 256 megabytes input standard i ...
- 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
D. Sum of Medians time limit per test 3 seconds memory limit per test 256 megabytes input standard i ...
- CodeForces 85D Sum of Medians Splay | 线段树
Sum of Medians 题解: 对于这个题目,先想到是建立5棵Splay,然后每次更新把后面一段区间的树切下来,然后再转圈圈把切下来的树和别的树合并. 但是感觉写起来太麻烦就放弃了. 建立5棵线 ...
- Yandex.Algorithm 2011 Round 1 D. Sum of Medians 线段树
题目链接: Sum of Medians Time Limit:3000MSMemory Limit:262144KB 问题描述 In one well-known algorithm of find ...
- Codeforces 396B On Sum of Fractions 数论
题目链接:Codeforces 396B On Sum of Fractions 题解来自:http://blog.csdn.net/keshuai19940722/article/details/2 ...
随机推荐
- 使用Wisdom RESTClient自动化测试REST API,如何取消对返回的body内容的校验?
使用Wisdom RESTClient V1.1 自动化测试API,默认是对返回HTTP状态码和body内容进行校验的. 如果您的API返回body内容是变化的,可以通过设置来取消对body内容的校验 ...
- STM32硬件IIC (转)
源: STM32硬件IIC
- IntelliJ IDEA的使用之调试方法
不管学什么要及时复习和练习!!不然就会忘掉,有个输入输出的过程 IntelJ IDEA的使用之断点调试 1)添加断点:直接在代码的最左侧点一下就行,出现红色圈圈. 2)单步运行:mac中F7.F8有其 ...
- amoeba_mysql 读写分离
环境 amoeba需要java环境,配置:略. MySQL主从配置:略. 基本架构 MySQL主:192.168.31.140 MySQL从:192.168.31.150 MySQL代理:192.16 ...
- oracle 18c的版本号规则
18C之后的版本标识 从2017年7月开始,Oracle改变了以往的数据库软件发布流程,采用年度Release和季度更新的策略. Yearly Release 将之前的N年一发布更改为每年一发布.每年 ...
- MySQL更改relay-bin名称导致同步停止的解决办法
今天在优化io的时候,移动了从库relay-bin的位置,并将hostname部分去掉了,启动后,从库slave状态如下: mysql> show slave status\G; ******* ...
- 20145308 《网络对抗》 Web应用 学习总结
20145308 <网络对抗> Web应用 学习总结 实验内容 (1)Web前端HTML (2)Web前端javascipt (3)Web后端:MySQL基础:正常安装.启动MySQL,建 ...
- 导入maven项目各个注解均报错了
所遇问题: 导入maven项目各个注解均报错了; 思考1: 这个项目使用了springboot;spring是个”大容器”,所有对象的创建和管理都交给了它, (SpringBoot是一个框架,一种全新 ...
- bzoj 1095 Hide 捉迷藏 - 动态点分治 -堆
Description 捉迷藏 Jiajia和Wind是一对恩爱的夫妻,并且他们有很多孩子.某天,Jiajia.Wind和孩子们决定在家里玩捉迷藏游戏.他们的家很大且构造很奇特,由N个屋子和N-1条双 ...
- windows进程中的几个杂项-hpguard 进程终止
打印机后台进程 c:\windows\system32\spool printers,servers, tool等, 清空printers中的内容就可以正常打印; 锐爽的后视镜跟其他的车型的后视镜不一 ...