Codeforces 939E 题解
lzy20091001 · · 题解
思路
引理:一定可以选
显然
考虑还需要选哪些数,由于
题目保证输入的元素是不降的,这使得
实现
为了避免可能的精度问题,我们可以不存储
#include <iostream>
#include <iomanip>
using namespace std;
const int N = 5e5;
int a[N + 5];
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int q, i = 0, j = 0, cnt = 1;
long long sum = 0;
cin >> q;
while (q--)
{
int op;
cin >> op;
if (op == 1)
{
cin >> a[++i];
sum += a[i] - a[i - 1];
}
else
{
while (j + 1 < i && 1LL * a[j + 1] * cnt < sum)
cnt++, sum += a[++j];
cout << fixed << setprecision(10) << a[i] - 1.0L * sum / cnt << "\n";
}
}
return 0;
}