社区讨论
20WA求条
P1486[NOI2004] 郁闷的出纳员参与者 1已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @mhjuitlo
- 此快照首次捕获于
- 2025/11/04 08:43 4 个月前
- 此快照最后确认于
- 2025/11/04 08:43 4 个月前
CPP
#include<bits/stdc++.h>
#define int long long
using namespace std;
struct str{
int l,r,v,dat,cnt,size;
}a[100005];
int tot;
int root;
void dbg() {
printf("root=%d\n", root);
cout << "idx\tL\tR\tval\tsize\n";
for (int i = 1; i <= tot; i++)
printf("%d\t%d\t%d\t%d\t%d\t%d\n", i, a[i].l, a[i].r, a[i].v, a[i].size);
}
int newone(int v){
tot++;
a[tot].v=v;
a[tot].dat=rand();
a[tot].cnt=1;
a[tot].size=1;
return tot;
}
void update(int p){
a[p].size=a[a[p].l].size+a[a[p].r].size+a[p].cnt;
}
void zig(int &p){
int q=a[p].l;
a[p].l=a[q].r;
a[q].r=p;
p=q;
update(a[p].r);
update(p);
}
void zag(int &p){
int q=a[p].r;
a[p].r=a[q].l;
a[q].l=p;
p=q;
update(a[p].l);
update(p);
}
void build(){
root=newone(-0x7fffffff);
a[1].r=newone(0x7fffffff);;
update(root);
}
void insert(int &p,int v,int lazy){
if(p==0){
p=newone(v);
return;
}
if(v==a[p].v){
a[p].cnt++;
update(p);
return;
}
if(v<a[p].v){
insert(a[p].l,v,lazy);
if(a[p].dat<a[a[p].l].dat){
zig(p);
}
}
if(v>a[p].v){
insert(a[p].r,v,lazy);
if(a[p].dat<a[a[p].r].dat){
zag(p);
}
}
update(p);
}
int qv(int p,int r){
if(a[a[p].l].size<r&&a[a[p].l].size+a[p].cnt>=r){
return a[p].v;
}
else if(a[a[p].l].size>=r){
return qv(a[p].l,r);
}
else{
return qv(a[p].r,r-a[a[p].l].size-a[p].cnt);
}
}
int qr(int p,int v){
if(p==0){
return 1;
}
if(v==a[p].v){
return a[a[p].l].size+1;
}
if(v<a[p].v){
return qr(a[p].l,v);
}
if(v>a[p].v){
return a[a[p].l].size+qr(a[p].r,v)+a[p].cnt;
}
}
int lazy;
int leave;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
build();
int n;
int minn;
cin>>n>>minn;
for(int i=1;i<=n;i++){
char opt;
int k;
cin>>opt>>k;
if(opt=='I'){
if(k>=minn){
insert(root,k+lazy,lazy);
}
}
if(opt=='A'){
lazy-=k;
}
if(opt=='S'){
lazy+=k;
leave=max(leave,qr(root,minn+lazy)-2);
}
if(opt=='F'){
if(a[root].size-leave-2>=k){
cout<<qv(root,a[root].size-k)-lazy<<"\n";
}
else{
cout<<-1<<"\n";
}
}
}
cout<<leave<<"\n";
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...