Codeforces Round #174 (Div. 1)A
题不怎么难,按线段树的解法 就是延迟标记,更新 因为找错找了N久 记一篇吧
向下更新时把+=写成了= 还做在了2W组的数据上 那个错找得真费劲。。
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<queue>
using namespace std;
#define N 200012
int n;
#define LL long long
LL s[N<<],lz[N<<];
void down(int w,int m)
{
if(lz[w])
{
s[w<<]+=lz[w]*(m-m/);
s[w<<|]+=lz[w]*(m/);
lz[w<<] += lz[w];
lz[w<<|]+=lz[w];
lz[w] = ;
}
}
void up(int w)
{
s[w] = s[w<<]+s[w<<|];
}
void update(int a,int b,int d,int l,int r,int w)
{
if(a<=l&&b>=r)
{
s[w]+=(r-l+)*d;
lz[w]+=d;
return ;
}
int m = (l+r)>>;
down(w,r-l+);
if(a<=m)
update(a,b,d,l,m,w<<);
if(b>m)
update(a,b,d,m+,r,w<<|);
up(w);
}
void set(int p,int d,int l,int r,int w)
{
if(l==r)
{
s[w] = d;
return ;
}
int m = (l+r)>>;
down(w,r-l+);
if(p>m)
set(p,d,m+,r,w<<|);
else
set(p,d,l,m,w<<);
up(w);
}
int main()
{ int i,t,x,y,g=;
cin>>n;
LL sum=;
for(i = ; i <= n ; i++)
{
cin>>t;
if(t==)
{
cin>>x>>y;
update(,min(g,x),y,,N-,);
sum = s[];
printf("%.6f\n",double(sum)/g);
}
else if(t==)
{
cin>>x;
set(g+,x,,N-,);
sum = s[];
g++;
printf("%.6f\n",double(sum)/g);
}
else
{
if(g>)
{
set(g,,,N-,);
g--;
sum = s[];
}
printf("%.6f\n",double(sum)/g);
}
}
return ;
}
Codeforces Round #174 (Div. 1)A的更多相关文章
- Codeforces Round #174 (Div. 1) B. Cow Program(dp + 记忆化)
题目链接:http://codeforces.com/contest/283/problem/B 思路: dp[now][flag]表示现在在位置now,flag表示是接下来要做的步骤,然后根据题意记 ...
- Codeforces Round #174 (Div. 2)
A. Cows and Primitive Roots 暴力. B. Cows and Poker Game 模拟. C. Cows and Sequence 线段树维护. D. Cow Progra ...
- Codeforces Round #174 (Div. 1 + Div. 2)
A. Cows and Primitive Roots 暴力. B. Cows and Poker Game 模拟. C. Cows and Sequence 线段树维护. D. Cow Progra ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
随机推荐
- centos6.5安装图形界面,windows远程linux图形界面
1. 查询是否已安装图形界面 yum grouplist |more 在grouplist的输出结果中的“Installed Groups:”部分中,如果你能找到“X Window System”和G ...
- AD转换后数字量的处理
假设模拟输入电压的最大值为5V,A/D转换器件为8位转换. [该转换器的分辨率为1/2n=0.3906%.] [能分辨输入模拟电压变化的最小值为5*0.3906%=19.5mv.] 则模拟电压与数字输 ...
- 1303: [CQOI2009]中位数图
早起一AC,整天萌萌哒. Problem: 1303 User: forgot93 Language: C++ Result: Accepted Time:56 ms Memory:2108 kb * ...
- 解决Notice错误,性能竟然提升了1000多倍!
先说PHP的deprecated错误的性能问题 最近刚刚完成了一个项目,在测试完基本功能后,我们就发布到线上.结果上线不久就发现产生了大量的错误,如下图: 一看都是PHP的Deprecated错误,是 ...
- (转)Maximum subarray problem--Kadane’s Algorithm
转自:http://kartikkukreja.wordpress.com/2013/06/17/kadanes-algorithm/ 本来打算自己写的,后来看到上述链接的博客已经说得很清楚了,就不重 ...
- ExtJs之FieldSet和FieldContainer
<!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...
- LINUX输入输出与文件
1 文件描述符 内核为每个进程维护一个已打开文件的记录表(实现为结构体数组),文件描述符是一个较小的正整数(0-1023)(结构体数组下标),它代表记录表的一项,通过文件描述符和一组基于文件描述符的文 ...
- Linux 删除文件夹和文件的命令
linux删除目录很简单,很多人还是习惯用rmdir,不过一旦目录非空,就陷入深深的苦恼之中,现在使用rm -rf命令即可.直接rm就可以了,不过要加两个参数-rf 即:rm -rf 目录名字-r 就 ...
- 李洪强iOS开发之OC[011] - 有参方法的声明实现以及调用练习
- unity 脚本(自定义组件)的事件触发关系