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 ...
随机推荐
- mysql查看连接数和状态,设置连接数和超时时间
1.mysql> show status like '%connect%'; Connections,试图连接到(不管是否成功)MySQL服务器的连接数. Max_used_connecti ...
- HTML5程序设计--SVG
SVG(Scalable Vector Graphics):可缩放矢量图形,一种二维图形表示语言. 借助SVG,我们可以实现很多同Canvas API类型的绘制操作,但在Canvas元素上绘制文本的时 ...
- HDU 4027 Can you answer these queries?(线段树,区间更新,区间查询)
题目 线段树 简单题意: 区间(单点?)更新,区间求和 更新是区间内的数开根号并向下取整 这道题不用延迟操作 //注意: //1:查询时的区间端点可能前面的比后面的大: //2:优化:因为每次更新都 ...
- C#中反射泛型 CreateInstance
假设1我有个类叫SortClass,类中有个BubbleSort(int[] array)用于给数组进行排序. 假设2我有个类叫SortT<T>,类中有个BubbleSort(T[] ar ...
- 使用时间戳引入css、js文件
前言 最近在一家创业公司实习,主要负责新版官网和商家平台管理系统的前端开发和维护,每次测试都要上传文件到ftp服务器端测试,初期由于更新修改比较频繁,每次都是直接上传覆盖css.js.php文件,链接 ...
- POJ 1279 Art Gallery(半平面交求多边形核的面积)
题目链接 题意 : 求一个多边形的核的面积. 思路 : 半平面交求多边形的核,然后在求面积即可. #include <stdio.h> #include <string.h> ...
- zoj 2686 Cycle Game 博弈论
其实规律很好找的,当从某点开始,向某一边找出非0的个数,为奇数时必胜. 代码如下: #include<iostream> #include<cstdio> using name ...
- Cpp多重继承会产生的问题
多重继承常常被认为是 OOP 中一种复杂且不必要的部分.多重继承面临 crash 的场景并非难以想象,来看下面的例子. 1. 名称冲突 来看以下情况: 如果 Dog 类以及 Bird 类都有一个名为 ...
- android真机自动化测试
appium执行用例时报错问题: 问题解析: 一般该种情况都是因为来连接了多个设备,验证办法:cmd->执行adb devices 看结果是否是多个devices ,如果是这个问题,停掉多余设 ...
- 今天来做一个PHP电影小爬虫。
今天来做一个PHP电影小爬虫.我们来利用simple_html_dom的采集数据实例,这是一个PHP的库,上手很容易.simple_html_dom 可以很好的帮助我们利用php解析html文档.通过 ...