1316. Electronic Auction(树状数组)

时间:2021-09-18 15:51:26

1316

我想说 要不要这么坑 WA了一个小时啊 ,都快交疯了,拿着题解的代码交都WA 最后很无语的觉得题解都错了 重读了N遍题意 发现没读错啊 难道写题解的那个人和我都想错了??

最后把g++换个C++交吧 就这么A了 我#¥#%。。

这个题有要注意的地方 WA6  取整的地方要那样处理(看代码) 具体我也不知道为什么

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<cmath>
using namespace std;
#define N 1000000
#define LL long long
#define lowbit(x) x&(-x)
LL re[N+];
void add(int x,int d)
{
while(x)
{
re[x]+=d;
x-=lowbit(x);
}
}
LL getsum(int x)
{
LL s = ;
while(x<=N)
{
s+=re[x];
x+=lowbit(x);
}
return s;
}
int main()
{
int num;
LL sum=;
double k;
char s[];
while(scanf("%s",s)!=EOF)
{
if(s[]=='Q')
break;
else if(s[]=='B')
{
scanf("%lf",&k);
int kk = floorl(k*100.0+0.5);
add(kk,);
}
else if(s[]=='D')
{
scanf("%lf",&k);
int kk = floorl(k*100.0+0.5);
add(kk,-);
}
else
{
scanf("%lf %d",&k,&num);
int kk = floorl(k*100.0+0.5);
LL ss = getsum(kk);
if(ss>=num)
sum+=num;
else
sum+=ss;
}
}
printf("%.2lf\n",(double)sum/100.0+1e-);
return ;
}