警示后人(如果你WA0)
查看原帖
警示后人(如果你WA0)
1174292
summ1t楼主2024/9/8 18:06

如果你翻遍讨论区,发现找不到自己WA0的原因,可能是有一个地方出错,就是del操作删除的是第几个添加的不等式,而不是第几次操作。

#include<bits/stdc++.h>
using namespace std;
const int N=2e6+10,K=1e6+10;

int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*f;
}
void write(int x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}
void ot(int x){
	write(x),cout<<endl;
}

int n,tr1[N*2],tr2[N*2],kind[N],aa[N],wasdel[N];char opt[20];

int lowbit(int x){
	return x&-x;
}

void add(int x,int y,int t[]){
	x+=K;
	for(;x<=2e6+10;x+=x&(-x)) t[x]+=y;
}

int query(int x,int t[]){
	x+=K;
	int res=0;
	for(;x;x-=x&(-x)) res+=t[x];
	return res;
}

int main(){
	
	n=read();int t=0,res=0;
	while(n--){
		while(1){
			scanf("%s",opt);
			if(opt[0]=='A'||opt[0]=='Q'||opt[0]=='D') break;
		}
		int a,b,c,x;//t++;不是每次操作都要t++
		if(opt[0]=='A'){
			a=read(),b=read(),c=read();
			if(!a){
				if(b>c) res++,kind[++t]=3;
				else kind[++t]=0;
			}
			else{
				if(a>0){
					aa[++t]=floor((c*1.0-b)/a);
					kind[t]=1;
					if(aa[t]>1e6) kind[t]=0;
					else if(aa[t]<-1e6) res++,kind[t]=3;
					else add(aa[t],1,tr1);
				}
				else{
					aa[++t]=ceil((c*1.0-b)/a);
					kind[t]=2;
					if(aa[t]<-1e6) kind[t]=0;
					else if(aa[t]>1e6) res++,kind[t]=3;
					else add(aa[t],1,tr2);
				}
			}
		}
		else if(opt[0]=='D'){
			x=read();
			if(wasdel[x]) continue;
			wasdel[x]=1;
			if(kind[x]==3) res--;
			else if(kind[x]==2) add(aa[x],-1,tr2);
			else if(kind[x]==1) add(aa[x],-1,tr1);
		}
		else{
			x=read();
			cout<<query(x-1,tr1)+query(1e6,tr2)-query(x,tr2)+res<<endl;
		}
	}
	
	return 0;
}
2024/9/8 18:06
加载中...