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 ...
随机推荐
- yebis error ---depth of field
前几天在墙外无法登陆cnblogs...导致很多blogs就没写了 有几篇比较值得记下来的,但是我已经不记得了,应该和sao有关scalable ambient obscurance 我似乎回忆起一点 ...
- sqlserver 查询库中有多少张表
表数目:select count(1) from sysobjects where xtype='U' 视图数::select count(1) from sysobjects where xtype ...
- iOS开发之runtime的运用-获取当前网络状态
之前写过runtime的一些东西,这次通过runtime获取一些苹果官方不想让你拿到的东西,比如,状态栏内部的控件属性.本文将通过runtime带你一步步拿到状态栏中显示网络状态的控件,然后通过监测该 ...
- 在C++的类中,普通成员函数不能作为pthread_create的线程函数,如果要作为pthread_create中的线程函数,必须是static
在C++的类中,普通成员函数不能作为pthread_create的线程函数,如果要作为pthread_create中的线程函数,必须是static ! 在C语言中,我们使用pthread_create ...
- 疯狂java讲义——初始化块
- java基础知识回顾之javaIO类---BufferedInputStream和BufferedOutputStream
MP3的复制过程: package com.lp.ecjtu; import java.io.BufferedInputStream; import java.io.BufferedOutputStr ...
- javascript中onclick事件能调用多个方法吗
Q: javascript中onclick事件能调用多个方法吗? A: 可以的,方法如下onclick="aa();bb();cc();"每个方法用“;”分号隔开就行了
- C#中对象的输出
假设有个Costmer类如下: class Costmer { public string Id { get; set; } public string City { get; set; } publ ...
- 知问前端——创建header区
创建界面 我们首先要设计一个header,这个区域将要设计成永远置顶.也就是,往下拉出滚动条也永远在页面最上层可视区内.在header区,目前先设计LOGO.搜索框.按钮.注册和登录即可. 项目的大致 ...
- The first day of HTML
这是韩顺平老师的<轻松搞定网页设计(html.css.js)>,讲的还凑合,仅作入门.决定还是做好笔记,记录学习的过程,这是HTML的第一天. HTML(HyperText Mark-up ...