CF283A.Cows and Sequence

普及/提高-

通过率:0%

时间限制:1.50s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Bessie and the cows are playing with sequences and need your help. They start with a sequence, initially containing just the number 0, and perform n operations. Each operation is one of the following:

  1. Add the integer x__i to the first a__i elements of the sequence.
  2. Append an integer k__i to the end of the sequence. (And hence the size of the sequence increases by 1)
  3. Remove the last element of the sequence. So, the size of the sequence decreases by one. Note, that this operation can only be done if there are at least two elements in the sequence.

After each operation, the cows would like to know the average of all the numbers in the sequence. Help them!

贝茜和奶牛们正在玩序列游戏,需要你的帮助。她们从一个初始只包含数字 0 的序列开始,并执行 nn 次操作。每次操作是以下三种之一:

  1. 将整数 xix_i 加到序列的前 aia_i 个元素上。
  2. 在序列末尾追加一个整数 kik_i。(因此序列长度增加 1)
  3. 删除序列的最后一个元素。(因此序列长度减少 1)注意:该操作仅在序列中至少有两个元素时才能执行。

每次操作后,奶牛们都想知道当前序列中所有数字的平均值。请帮助她们!

输入格式

The first line contains a single integer n (1 ≤ n ≤ 2·105) — the number of operations. The next n lines describe the operations. Each line will start with an integer t__i (1 ≤ t__i ≤ 3), denoting the type of the operation (see above). If t__i = 1, it will be followed by two integers a__i, x__i (|x__i| ≤ 103; 1 ≤ a__i). If t__i = 2, it will be followed by a single integer k__i (|k__i| ≤ 103). If t__i = 3, it will not be followed by anything.

It is guaranteed that all operations are correct (don't touch nonexistent elements) and that there will always be at least one element in the sequence.

第一行包含一个整数 nn(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5),表示操作的次数。接下来的 nn 行描述这些操作。每行以一个整数 tit_i(1≤ti≤31 \leq t_i \leq 3)开头,表示该操作的类型(见上文)。若 ti=1t_i = 1,则其后跟随两个整数 aia_i 和 xix_i(∣xi∣≤103|x_i| \leq 10^3;1≤ai1 \leq a_i)。若 ti=2t_i = 2,则其后跟随一个整数 kik_i(∣ki∣≤103|k_i| \leq 10^3)。若 ti=3t_i = 3,则其后不跟随任何内容。

保证所有操作均合法(不会访问不存在的元素),且序列中始终至少存在一个元素。

输出格式

Output n lines each containing the average of the numbers in the sequence after the corresponding operation.

The answer will be considered correct if its absolute or relative error doesn't exceed 10 - 6.

输出 n 行,每行包含对应操作后序列中数字的平均值。

若答案的绝对误差或相对误差不超过 10 - 6,则视为正确。

输入输出样例

  • 输入#1

    5
    2 1
    3
    2 3
    2 1
    3

    输出#1

    0.500000
    0.000000
    1.500000
    1.333333
    1.500000
  • 输入#2

    6
    2 1
    1 2 20
    2 2
    1 2 -3
    3
    3

    输出#2

    0.500000
    20.500000
    14.333333
    12.333333
    17.500000
    17.000000

说明/提示

In the second sample, the sequence becomes

在第二个样例中,序列变为

输入解题思路,AI测评打分。不知道怎么写?

首页