题不怎么难,按线段树的解法 就是延迟标记,更新 因为找错找了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的更多相关文章

  1. Codeforces Round #174 (Div. 1) B. Cow Program(dp + 记忆化)

    题目链接:http://codeforces.com/contest/283/problem/B 思路: dp[now][flag]表示现在在位置now,flag表示是接下来要做的步骤,然后根据题意记 ...

  2. Codeforces Round #174 (Div. 2)

    A. Cows and Primitive Roots 暴力. B. Cows and Poker Game 模拟. C. Cows and Sequence 线段树维护. D. Cow Progra ...

  3. Codeforces Round #174 (Div. 1 + Div. 2)

    A. Cows and Primitive Roots 暴力. B. Cows and Poker Game 模拟. C. Cows and Sequence 线段树维护. D. Cow Progra ...

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

  5. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  6. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  7. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  8. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

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

随机推荐

  1. 使用命令行进行 VS单元测试 MSTest

    测试 指定的方法 "D:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\MSTest.exe" /test ...

  2. How Big Is A Petabyte, Exabyte, Zettabyte, Or A Yottabyte?

    一个关于Byte递增的描述,蛮有趣的! Bytes -> Kilobyte -> Megabyte -> Gigabyte -> Terabyte -> Petabyte ...

  3. 定时器 corn 表达式

    一个cron表达式有至少6个(也可能7个)有空格分隔的时间元素.按顺序依次为1.秒(0~59)2.分钟(0~59)3.小时(0~23)4.天(月)(0~31,但是你需要考虑你月的天数)5.月(0~11 ...

  4. mysql存储过程和函数使用实例

    1.需求:根据输入的年份,月份,和当前系统的年份比较,不满1年按1年计算,多出1年11个月也按1年计算. 2.计算得出来的使用年份,计算车辆残值. 3.存储过程 DELIMITER $$ USE `d ...

  5. Hungary(匈牙利算法)——二分图最大匹配

    在复习匈牙利算法的时候,发现这么一篇介绍匈牙利算法的文章,非常通俗易懂,所以就借鉴过来了. 复杂度:邻接矩阵:O(v^3)邻接表:O(V*E) 附上链接:趣写算法系列之--匈牙利算法 下面就附上代码吧 ...

  6. POJ 2070

    #include<iostream> #include<stdio.h> using namespace std; int main() { //freopen("a ...

  7. C# WINFORM 捕获全局异常

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Thr ...

  8. IE9 JSON未定义

    原文:http://social.msdn.microsoft.com/Forums/ie/en-US/fc41127c-0243-4d2e-8e7c-2b311f12e390/ie9-json-no ...

  9. phpeclipse常用快捷键

    phpeclipse常用快捷键

  10. Linux Command Line 解析

    Linux Command Line 解析 0 处理模型 Linux kernel的启动包括很多组件的初始化和相关配置,这些配置参数一般是通过command line进行配置的.在进行后续分析之前,先 ...