如果发现广告等破坏行为,请尽量将条目恢复到较早的版本而不是把相应内容直接删除,谢谢合作。
URAL/1316
来自"NOCOW"
< URAL
树状数组啦~
#include <iostream> #include <cstring> using namespace std; char s[10]; int f[1000001]={0},n; __int64 ans=0; double p; inline int lowbit(int x) { return (x&(-x)); } inline void modify(int x,int flag) { while (x <= 1000000) { f[x]+=flag; x+=lowbit(x); } } inline int query(int x) { int sum=0; while (x > 0) { sum+=f[x]; x-=lowbit(x); } return sum; } int main() { while (true) { scanf("%s",s); if (s[0] == 'Q') break; else if (s[0] == 'B') { scanf("%lf",&p); modify(1000001-(int)(p*100.0+0.4),1); } else if (s[0] == 'S') { scanf("%lf%d",&p,&n); ans+=min(query(1000001-(int)(p*100.0+0.4)),n); } else { scanf("%lf",&p); modify(1000001-(int)(p*100.0+0.4),-1); } } printf("%.2lf\n",(double)ans/100.0); return 0; } //by zzy