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 74
| #include<stdio.h> #include<set> #define mem(ss) memset(ss,0,sizeof(ss)) #define rep(d, s, t) for(int d=s;d<=t;d++) #define rev(d, s, t) for(int d=s;d>=t;d--) typedef long long ll; typedef long double ld; typedef double db; const ll mod = 998244353; const int N = 1e4 + 10; #define io_opt ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
int n,k; struct E{ int a; int p; }e[1000020]; int head=1,tail=0; int x,val; db ans; std::multiset<int>q; int sum=0,sum2=0; bool fg=false; int cnt; int main(){ scanf("%d%d",&n,&k); for(int i=1;i<=n;i++){ scanf("%d",&x); if(x==1){ scanf("%d",&val); e[++tail].a=val; e[tail].p=i; sum+=val; sum2+=val*val; q.insert(val); if(tail-head+1==k+1){ q.erase(q.lower_bound(e[head].a)); sum-=e[head].a; sum2-=e[head].a*e[head].a; head++; } cnt=tail-head+1; } else if(x==2){ ans=sum/cnt; printf("%.2f\n",ans); } else if(x==3){ ans=sum2/(ld)cnt-(sum/(ld)cnt)*(sum/(ld)cnt); printf("%.2f\n",ans); } else{ auto tmp=q.begin(); if(cnt%2){ for(int i=1;i<=cnt/2;i++){ tmp++; } printf("%.2f\n",(db)*tmp); } else{ for(int i=1;i<=cnt/2-1;i++){ tmp++; } val=*tmp; tmp++; val+=*tmp; printf("%.2f\n",(db)val/2.0); } } } return 0; }
|