萌新刚学CDQ,为何wa70
查看原帖
萌新刚学CDQ,为何wa70
449230
JYFHYX楼主2021/9/7 15:04

RT

#include<bits/stdc++.h>
#define int long long
using namespace std;
inline 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<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*f;
}
const int maxn=1e7+6;
int s,w;bool vis[maxn];int xs[maxn],ans[maxn];
struct node{
	int a,b,c,cnt,num,xs;
	friend bool operator!=(const node &a,const node &b)
	{
		return a.a!=b.a||a.b!=b.b||a.c!=b.c;
	}
	friend bool operator<(const node &a,const node &b)
	{
		return ((a.a==b.a)&(a.b==b.b)&(a.c<b.c))|((a.a==b.a)&(a.b<b.b))|(a.a<b.a);
	}
}f[maxn];
namespace szsz{
	int c[maxn];
	inline int lowbit(int x){return x&(-x);}
	inline void update(int x,int num)
	{
		while(x<=w)
		{
			c[x]+=num;
			x+=lowbit(x);
		}
	}
	inline int query(int x)
	{
		int res=0;
		while(x)
		{
			res+=c[x];
			x-=lowbit(x);
		} 
		return res;
	}
}using namespace szsz;
node tmp[maxn];
inline void msort(int l,int r)
{
	if(l==r) return ;
	int mid=l+r>>1;
	msort(l,mid);msort(mid+1,r);
	int tmp1=l,tmp2=mid+1,p=l;
	while(tmp1<=mid&&tmp2<=r)
	{
		
		if(f[tmp1].b<=f[tmp2].b)
		{
			update(f[tmp1].c,f[tmp1].num);
			tmp[p++]=f[tmp1++];
		}
		else 
		{
			tmp[p]=f[tmp2];
			tmp[p++].cnt+=query(f[tmp2++].c);
		}
	}
	while(tmp1<=mid) 
	{
		update(f[tmp1].c,f[tmp1].num)	;
		tmp[p++]=f[tmp1++];
	}
	while(tmp2<=r)
	{
		tmp[p]=f[tmp2];
		tmp[p++].cnt+=query(f[tmp2++].c);
	}	
	for(int i=l;i<=mid;i++)
	update(f[i].c,-f[i].num);
	for(int i=l;i<=r;i++)
	f[i]=tmp[i];
}	
signed main()
{
	int type=read(),chuo=0,tmpp=0;
	while(type!=3)
	{
		chuo++;
		if(type==0) w=read()+1;
		else if(type==1)
		{
			f[++tmpp].a=read()+1;
			f[tmpp].b=read()+1;
			f[tmpp].c=chuo;
			f[tmpp].num=read();
		}
		else
		{
			vis[chuo]=1;
			int px1=read()+1,px2=read()+1,px3=read()+1,px4=read()+1;
			f[++tmpp].a=px3;f[tmpp].b=px4;f[tmpp].c=chuo;f[tmpp].xs=1;
			f[++tmpp].a=px3;f[tmpp].b=px2-1;f[tmpp].c=chuo;f[tmpp].xs=-1;
			f[++tmpp].a=px1-1;f[tmpp].b=px4;f[tmpp].c=chuo;f[tmpp].xs=-1;			
			f[++tmpp].a=px1-1;f[tmpp].b=px2-1;f[tmpp].c=chuo;f[tmpp].xs=1;
		}
		type=read();
	}
	sort(f+1,f+1+tmpp);
	msort(1,tmpp);
	for(int i=1;i<=tmpp;i++)
	{
		if(vis[f[i].c])
		ans[f[i].c]+=f[i].cnt*f[i].xs;
	}		
	for(int i=1;i<=chuo;i++)
	if(vis[i]) printf("%lld\n",ans[i]);
}
2021/9/7 15:04
加载中...