本该是线段树的题目,二分也勉强能过
#include <iostream>
#include <cstdio>
#include <memory.h>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=10010;
char buf[50];
long long val[maxn],n,curSize;
int remBinSearch(long long v){
int l=0,r=curSize-1,m=(l+curSize)>>1;
while (l<=r){
if(val[m]<v){
l=m+1;
}else if(val[m]>v){
r=m-1;
}else return m;
m=(l+r)>>1;
}
return -1;
}
void add(long long v){
int j;
for (j=curSize-1;j>=0;--j){
if(val[j]>v){
val[j+1]=val[j];
}else{
val[j+1]=v;
break;
}
}
if(j==-1){
val[0]=v;
}
curSize++;
if(curSize&1){
printf("%lld\n",val[curSize/2]);
}else{
long long ans=val[curSize/2]+val[(curSize-1)/2];
if(ans%2==0){
printf("%lld\n",ans/2);
}else{
printf("%.1lf\n",(double)ans/2.0);
}
}
}
void remove(long long v){
int pos=remBinSearch(v);
if(pos==-1){
printf("Wrong!\n");
return;
}
for (int j=pos;j<curSize;++j){
val[j]=val[j+1];
}
curSize--;
if(curSize==0){
printf("Empty!\n");
return;
}else if(curSize&1){
printf("%lld\n",val[curSize/2]);
}else{
long long ans=val[curSize/2]+val[(curSize-1)/2];
if(ans%2==0){
printf("%lld\n",ans/2);
}else{
printf("%.1lf\n",(double)ans/2.0);
}
}
}
int main(){
int t;
scanf("%d",&t);
while (t--){
scanf("%lld",&n);
curSize=0;
memset(val,0,sizeof(val));
while (n--){
long long v;
scanf("%s%lld",buf,&v);
if(strcmp(buf,"add")==0){
add(v);
}else{
remove(v);
}
}
}
return 0;
}