#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 10009;
const double esp = 1e-6;
double bef[maxn];
double aft[maxn];
char str[maxn][10];
int C[maxn];
int num, nn;
int lowbit(int x)
{
return x&(-x);
}
int find(double val)
{
int l = 1, r = num, mid;
while(1)
{
mid = (l+r)/2;
if(aft[mid]==val) return mid;
else if(aft[mid]<val) l = mid+1;
else r = mid-1;
}
}
void updata(int pos, int tmp)
{
for(; pos<=num; pos+=lowbit(pos))
C[pos] += tmp;
}
int query(int pos)
{
int a = 0;
for(; pos>0; pos-=lowbit(pos)) a+=C[pos];
return a;
}
double ans(int x)
{
int l=1, r=num, mid;
while(l<r)
{
mid = (l+r)/2;
int tmp = query(mid);
//if(tmp == x) {cout<<" mid ++ "<<mid<<endl; return aft[mid];}
if(tmp<x) l = mid+1;
else r = mid;
}
//cout<<" l ++ "<<l<<endl;
return aft[l];
}
void print(double key)
{
char s[20];
sprintf(s,"%.6lf",key);
int len=strlen(s)-1;
while(s[len]=='0')
{
len--;
}
if(s[len]=='.')
{
s[len]='\0';
}
else
s[len+1]='\0';
puts(s);
}
void add(double val)
{
int t = find(val);
nn++;
updata(t, 1);
if(nn&1)
{
print(ans(nn/2+1));
}
else
{
print(( ans(nn/2) + ans(nn/2+1) )/2);
}
}
void remove(double val)
{
int t = find(val);
if( query(t)==query(t-1) )
{
puts("Wrong!");
return;
}
nn--;
updata(t, -1);
if(nn==0)
{
puts("Empty!");
return;
}
else if(nn&1)
{
print(ans(nn/2+1));
}
else
{
print(( ans(nn/2) + ans(nn/2+1) )/2);
}
}
int main()
{
int t, n;
scanf("%d", &t);
double aa;
while(cin>>aa)
cout<<aa<<endl;
while(t--)
{
memset(C, 0, sizeof(C));
scanf("%d", &n);
for(int i=1; i<=n; i++)
{
scanf("%s%lf", str[i], &bef[i]);
aft[i] = bef[i];
}
num = 1;
sort(aft+1, aft+n+1);
for(int i=1; i<=n; i++)
if(aft[i]!=aft[i-1])
aft[num++] = aft[i];
nn = 0;
for(int i=1; i<=n; i++)
{
if(str[i][0]=='a') add(bef[i]);
else remove(bef[i]);
}
}
return 0;
}
ZOJ-3612-树状数组+第k小数+离散化
最新推荐文章于 2024-04-18 23:25:48 发布