MnZn 求助 WA 60 总是比答案多一个
查看原帖
MnZn 求助 WA 60 总是比答案多一个
196899
lndjy18智99楼主2021/1/4 22:57

rt 用的树状数组

#include<iostream>
#include<string>
#include<cmath>
using namespace std;
const int N=2e6+5;
int c[N];
int lowbit(int x)
{
	return x&(-x);
 } 
void add(int x,int v)
{
	if(x<=0) return;
	for(;x<N;x+=lowbit(x))
	c[x]+=v;
}
int ask(int x)
{
	if(x<=0) return 0;
	int ans=0;
	while(x)
	{
		ans+=c[x];
		x-=lowbit(x); 
	}
	return ans;
}
int l[100005],r[100005],flag[100005],cnt,n,cont;
const int M=1e6+1;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		string s;
		cin>>s;
		if(s[0]=='A')
		{
			int a,b,c;
			cin>>a>>b>>c;
			cont++;
			if(a>0)
			{
				int k=floor(((double)(c)-(double)(b))/(double)(a));
				l[cont]=k+1+M;
				r[cont]=1e6+M;
			}
			else if(a==0)
			{
				if(b>c) cnt++,flag[cont]=1;
				else flag[cont]=2;
			 } 
			 else
			 {
			 	int k=floor(((double)(c)-(double)(b))/(double)(a));
			 	l[cont]=-1e6+M;
			 	r[cont]=k+M; 
			 }
			 if(l[cont]<-1e6+M&&flag[cont]==0) cnt++,flag[cont]=1;
			 else if(r[cont]>1e6+M&&flag[cont]==0)  cnt++,flag[cont]=1;
			 else if(r[cont]<-1e6+M&&flag[cont]==0) flag[cont]=2;
			 else if(l[cont]>1e6+M&&flag[cont]==0) flag[cont]=2;
			 else if(flag[cont]==0)
			 {
			 	add(r[cont]+1,-1);
				 add(l[cont],1);
			 }
			 //cout<<l[cont]<<" "<<r[cont]<<endl;
		}
		if(s[0]=='D')
		{
			int k;
			cin>>k;
			if(flag[k]==1) cnt--;
			else if(flag[k]==0)
			{
				add(r[k]+1,1);
				add(l[k],-1);
			}
			flag[k]=2;
		//	cout<<l[k]<<" "<<r[k]<<endl;
		}
		if(s[0]=='Q')
		{
			int k;
			cin>>k;
			//cout<<k+M<<endl;
			cout<<ask(k+M)+cnt<<"\n";
		}
	}
 	return 0;
}
2021/1/4 22:57
加载中...