题目链接: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的更多相关文章

  1. codeforces 85D D. Sum of Medians Vector的妙用

    D. Sum of Medians Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/prob ...

  2. 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 ...

  3. 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 ...

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

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

  5. Codeforces 85D Sum of Medians

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

  6. 数据结构(线段树):CodeForces 85D Sum of Medians

    D. Sum of Medians time limit per test 3 seconds memory limit per test 256 megabytes input standard i ...

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

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

  8. Yandex.Algorithm 2011 Round 1 D. Sum of Medians 线段树

    题目链接: Sum of Medians Time Limit:3000MSMemory Limit:262144KB 问题描述 In one well-known algorithm of find ...

  9. Codeforces 396B On Sum of Fractions 数论

    题目链接:Codeforces 396B On Sum of Fractions 题解来自:http://blog.csdn.net/keshuai19940722/article/details/2 ...

随机推荐

  1. 前端框架VUE----导入Bootstrap以及jQuery的两种方式

    Vue引入bootstrap主要有两种方法 方法一:在main.js中引入,此方法导入的bootstrap中对于html,body的一些预设置的css样式可能无效. 一.引入jQuery 在当前项目的 ...

  2. ubuntu重启+sublime快捷键

    sudo reboot Sublime常用快捷键: 掌握基本的代码编辑器的快捷键,能让你打码更有效率,刚开始可能不大记得住,多敲几次就能熟悉并使用它 精华键 : Ctrl+Shift+P:打开命令面板 ...

  3. Python爬虫【三】利用requests和正则抓取猫眼电影网上排名前100的电影

    #利用requests和正则抓取猫眼电影网上排名前100的电影 import requests from requests.exceptions import RequestException imp ...

  4. HashMap和LinkedHashMap区别

    import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.uti ...

  5. hiho一下 第148周

    题目1 : Font Size 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Steven loves reading book on his phone. The b ...

  6. Angular 父子组件传值

    Angular 父子组件传值 @Input  @Output  @ViewChild 新建一个头部组件 newsheader 在主组件引用 news 组件,在news组件添加 newsheader 组 ...

  7. BootstrapTable(附源码)

    Bootstrap结合BootstrapTable的使用,分为两种模试显示列表. 引用的css: <link href="@Url.Content("~/Css/bootst ...

  8. 上传代码到github的步骤

    在你的电脑上装好git 大致流程是: 1.在github上创建项目 2.使用git clone https://github.com/xxxxxxx/xxxxx.git克隆到本地 3.编辑项目 4.g ...

  9. PHP 重置数组为连续数字索引的几种方式

    原文链接:https://blog.csdn.net/zhang197093/article/details/78606916 推荐的方式  array_values 方法 这样方式无论对普通数组还是 ...

  10. Ymodem协议(参考STM32)

    相信很多人都希望,不开盖就可以对固件进行升级吧,就像手机那些.下文中的bootload就来实现这样的功能. 前段时间有项目关于Bootload设计.所以就仔细的去了研究了一翻.以前都是用的stm32官 ...