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 ...
随机推荐
- Android4.0 主线程不能访问网络异常解决办法
从两个方面说下这个问题: 1. 不让访问网络的原因 2. 解决该问题的办法 不让访问网络的原因: 由于对于网络状况的不可预见性,很有可能在网络访问的时候造成阻塞,那么这样一来我们的主线程UI线程 就会 ...
- echarts遇到的问题
X轴无偏移: axisTick: { alignWithLabel: true }, x轴显示所有数据项且避免拥挤在xAxis设置: axisLabel: { interval: 0, rotate: ...
- eHR自动同步获取LDAP中的邮箱地址
背景:公司里有eHR系统,有网域,IBM Lotus Notes邮件系统,新人入职会在eHR系统里提前建好档案,网域帐号.邮箱帐号均会在入职前提前建好,因为邮箱帐号是晚于eHR建档的,因此在eHR建档 ...
- php 阳历转农历优化版
网上转换方法很多例子错误. 测试例子1:输入公历 2010年2月1号测试,对比百度万年历 农历应该为己丑年(2009)腊月(12月)十八. 测试例子2:输入农历1990.11.初十,丑时,公历应该为1 ...
- End of script output before headers错误解决方法
注意是否丢失两个换行符\n\n printf("Content-type: text/html;charset=utf-8\n\n");
- mysql/oracle jdbc大数据量插入优化
10.10.6 大数据量插入优化 在很多涉及支付和金融相关的系统中,夜间会进行批处理,在批处理的一开始或最后一般需要将数据回库,因为应用和数据库通常部署在不同的服务器,而且应用所在的服务器一般也不会 ...
- 使用ccache大幅度加速gcc编译速度至少1倍以上(不需要修改任何编译选项)
因为我们整个项目都是使用c++开发的,生成的so足有50M,原来编译一遍要三五分钟,一个针对oracle,一个针对mysql,整个轮回下来这部分就要10来分钟,加上代码上传.翻译,一轮配管打包下来二三 ...
- 写给大忙人的ELK最新版6.2.4学习笔记-Logstash和Filebeat解析(java异常堆栈下多行日志配置支持)
接前一篇CentOS 7下最新版(6.2.4)ELK+Filebeat+Log4j日志集成环境搭建完整指南,继续对ELK. logstash官方最新文档https://www.elastic.co/g ...
- Python3.6.2在线安装pymysql模块
我是一个python新手刚才使用python写邮件发送代码的时候想着需要连接数据库, 下面的安装步骤 python -m pip install pymysql PS C:\Users\hp> ...
- JavaBean的getters和setters方法自动生成
xgClass.java文件: public class XgClass { private String ccCityDerate1000Num; } 添加getter/setter方法: 在代码区 ...