居然过了

本地TLE,,,,vj居然过了。。。。。。。不得不称赞评测机子
```c++
#include<iostream>
using namespace std;
int flag,change;
struct sbt{
int left,right,size;
long long data,HASH;
};
int cmp(long long a,long long b,long long c,long long d){
if (a<c) return 1;
if (a>c) return -1;
if (b<d) return 1;
if (b>d) return -1;
return 0;
}
class SBT{
public:
int top,root;
sbt* tree;

SBT(int n){
tree=new sbt[n+1];
top=root=0;
for (int i=0;i<=n;i++)
tree[i].left=tree[i].right=tree[i].size=0;
}
void left_rot(int &x){
int y=tree[x].right;
tree[x].right=tree[y].left;
tree[y].left=x;
tree[y].size=tree[x].size;
tree[x].size=tree[tree[x].left].size+tree[tree[x].right].size+1;
x=y;
}
void right_rot(int &x){
int y=tree[x].left;
tree[x].left=tree[y].right;
tree[y].right=x;
tree[y].size=tree[x].size;
tree[x].size=tree[tree[x].left].size+tree[tree[x].right].size+1;
x=y;
}
void Maintain(int &x,bool flag){
if (!flag){
if (tree[tree[tree[x].left].left].size>tree[tree[x].right].size)
right_rot(x);
else
if (tree[tree[tree[x].left].right].size>tree[tree[x].right].size)
left_rot(tree[x].left),right_rot(x);
else
return;
}
else{
if (tree[tree[tree[x].right].right].size>tree[tree[x].left].size)
left_rot(x);
else
if (tree[tree[tree[x].right].left].size>tree[tree[x].left].size)
right_rot(tree[x].right),left_rot(x);
else
return;
}
Maintain(tree[x].left,0);
Maintain(tree[x].right,1);
Maintain(x,1);
Maintain(x,0);
}
void insert(int &x,long long data,long long has){
if (x==0){
x=++top;
tree[x].size=1;
tree[x].left=tree[x].right=0;
tree[x].data=data;
tree[x].HASH=has;
}
else{
tree[x].size++;
if (cmp(data,has,tree[x].data,tree[x].HASH)==1) insert(tree[x].left,data,has);
else insert(tree[x].right,data,has);
Maintain(x,data>=tree[x].data);
}
}
int remove(int &x,long long data,long long has){
tree[x].size--;
if (cmp(data,has,tree[x].data,tree[x].HASH)==-1)
remove(tree[x].right,data,has);
else
if (cmp(data,has,tree[x].data,tree[x].HASH)==1)
remove(tree[x].left,data,has);
else{
if (tree[x].left!=0&&tree[x].right==0){
int ret=x;
x=tree[x].left;
return x;
}
else
if (tree[x].right!=0&&tree[x].left==0){
int ret=x;
x=tree[x].right;
return x;
}
else
if (tree[x].left==0&&tree[x].right==0){
int ret=x;
x=0;
return ret;
}
else{
int ret=tree[x].right;
while (tree[ret].left) ret=tree[x].left;
tree[x].data=tree[ret].data;
remove(tree[x].right,tree[ret].data,has);
}
}
}
int select(int &x,int k){
int r=tree[tree[x].left].size+1;
if (k<r) return select(tree[x].left,k);
else
if (k>r) return select(tree[x].right,k-r);
else
return tree[x].data;
}
int getmin(){
int x=root;
while (tree[x].left) x=tree[x].left;
return x;
}
void Insert(long long data,long long has){
insert(root,data,has);
}
void Remove(long long data,long long has){
remove(root,data,has);
}
int Select(int k){
if (k<=0||k>tree[root].size) return -1;
return select(root,k);
}
} a(200000);
int main(){
int n,MIN,x,total=0;
char tmp;
cin>>n>>MIN;
for (int i=0;i<n;i++){
cin>>tmp>>x;
if (tmp=='I'&&x>=MIN) {
a.Insert(x-change,flag++);
total++;
}
else {
if (tmp=='A') change+=x;
else if (tmp=='S'){
change-=x;
while (1){
if (!a.root) break;
int ttt=a.getmin();
if (a.tree[ttt].data+change<MIN) a.Remove(a.tree[ttt].data,a.tree[ttt].HASH);
else break;
}
}
else if (tmp=='F') {
int ans=a.Select(a.tree[a.root].size+1-x);
if (ans!=-1) cout<<ans+change<<endl;
else cout<<ans<<endl;
}
}
}
cout<<total-a.tree[a.root].size<<endl;
return 0;
}

3 条评论

  • @ 2016-03-19 16:44:23

    srO

  • @ 2016-03-19 11:36:15

    你本地评测时开没开优化?

  • @ 2016-03-17 22:37:15

    std::cin >> ...
    这东西有点慢,还是用scanf(...)吧。

  • 1

信息

ID
1507
难度
7
分类
数据结构 | 平衡树 点击显示
标签
递交数
2541
已通过
409
通过率
16%
被复制
4
上传者