forked from marioyc/Online-Judge-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path283A.cpp
73 lines (58 loc) · 1.32 KB
/
283A.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define MAXN 200005
int sz = 0;
long long bit[MAXN + 1],sum[MAXN + 1];
int a[MAXN + 1],b[MAXN + 1];
void update(int idx, long long add){
for(int x = idx;x <= MAXN;x += x & -x)
bit[x] += add;
}
long long query(int idx){
long long ret = 0;
for(int x = idx;x > 0;x -= x & -x)
ret += bit[x];
return ret;
}
int main(){
int n;
scanf("%d",&n);
sz = 1;
a[0] = 0;
for(int i = 0;i < n;++i){
int t;
scanf("%d",&t);
if(t == 1){
int pos,x;
scanf("%d %d",&pos,&x);
b[pos] += x;
update(pos,x * pos);
}else if(t == 2){
scanf("%d",&a[sz]);
++sz;
sum[sz] = sum[sz - 1] + a[sz - 1];
}else{
long long cur = b[sz];
update(sz,-cur * sz);
b[sz] = 0;
--sz;
if(sz){
update(sz,cur * sz);
b[sz] += cur;
}
}
printf("%.8f\n",(double)(query(sz) + sum[sz]) / sz);
}
return 0;
}