QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#110717#4407. 回NOI_AK_ME0 4572ms60136kbC++208.1kb2023-06-03 15:31:012023-06-03 15:31:03

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-03 15:31:03]
  • 评测
  • 测评结果:0
  • 用时:4572ms
  • 内存:60136kb
  • [2023-06-03 15:31:01]
  • 提交

answer

#include<bits/stdc++.h>
#define F(i,l,r) for(register int i(l);i<r;++i)
#define Fe(i,l,r) for(int i=l;i<=r;++i)
#define Fer(i,l,r) for(int i=l;i>=r;--i)
const int N=1e6+10,maxm=1e6,maxv=1e8;

typedef unsigned int u32;
typedef unsigned long long u64;

typedef long long i64;
int read(int L,int R){
	int x;
	assert(scanf("%d",&x)==1);
	assert(L<=x&&x<=R);
	return x;
}


const int MEM=1<<26;
char pool[MEM],*pool_p=pool;

template<class T>
void alloc(T *&p,int sz){
	p=reinterpret_cast<T*>(pool_p);
	pool_p+=sz*sizeof(T);
	assert(pool_p<pool+MEM);
for(register int i(0);i<sz;++i)new(p+i)T();
}

template<class T>
struct Undo{
	T &x;
	T x0;
	Undo(T &x):x(x),x0(x){}
	~Undo(){x=x0;}
};

#define alloc_scope Undo<char*> _##__LINE__(pool_p)



template<class T>
struct BIT{
	T *a;
	int n;
	void alloc(int n0){
		n=n0;
		::alloc(a,n+1);
	}
	void add(int x,T y){
		int _n=n;
		for(;x<=_n;x+=x&-x)a[x]+=y;
	}
	T sum(int x){
		T s;
		s=0;
		for(;x;x-=x&-x)s+=a[x];
		return s;
	}
};

template<class T,int n>
struct Vec{
	T v[n];
	void operator=(T x){
		for(register int i(0);i<n;++i)v[i]=x;
	}
	Vec operator+(const Vec &w)const{
		Vec c;
		for(register int i(0);i<n;++i)c.v[i]=v[i]+w.v[i];
		return c;
	}
	void operator+=(const Vec &w){
		for(register int i(0);i<n;++i)v[i]+=w.v[i];
	}
	T operator*(const Vec &w)const{
		T s=0;
		for(register int i(0);i<n;++i)s+=v[i]*w.v[i];
		return s;
	}
	friend Vec operator*(T x,const Vec &w){
		Vec c;
		for(register int i(0);i<n;++i)c.v[i]=x*w.v[i];
		return c;
	}
};

template<class T,int n1,int n2>
Vec<T,n1+n2> operator&(const Vec<T,n1> &a,const Vec<T,n2> &b){
	Vec<T,n1+n2> c;
	for(register int i(0);i<n1;++i)c.v[i]=a.v[i];
	for(register int i(0);i<n2;++i)c.v[i+n1]=b.v[i];
	return c;
}

template<class T>
struct Pos{
	int x,y,id;
	T v;
};

std::vector<Pos<Vec<u32,6>>> t1,t3;
std::vector<Pos<Vec<u32,4>>> t2;
int qp=0;
u32 ans[N];

template<class T>
void solve(Pos<T> *a,int n){
	if(n<=40){
		for(register int i(0);i<n;++i)if(a[i].id)
			for(register int j(0);j<i;++j)if(!a[j].id)
				if(a[j].x<a[i].x&&a[j].y<a[i].y)
					ans[a[i].id]+=a[i].v*a[j].v;
		std::sort(a,a+n,[](const Pos<T> &a,const Pos<T> &b){return a.x<b.x;});
		return;
	}
	alloc_scope;
	int n2=n>>1;
	solve(a,n2);
	solve(a+n2,n-n2);
	int *ys,yp=0;
	alloc(ys,n2);
	for(register int i(0);i<n2;++i)if(!a[i].id)ys[yp++]=a[i].y;
	std::sort(ys,ys+yp);
	BIT<T> bit;
	bit.alloc(yp);
	
	Pos<T> *b;
	alloc(b,n);
	int p1=0,p2=n2,p3=0;
	auto f1=[&]{
		if(!a[p1].id){
			int y=std::lower_bound(ys,ys+yp,a[p1].y)-ys+1;
			bit.add(y,a[p1].v);
		}
		b[p3++]=a[p1++];
	};
	auto f2=[&]{
		if(a[p2].id){
			int y=std::upper_bound(ys,ys+yp,a[p2].y)-ys;
			ans[a[p2].id]+=bit.sum(y)*a[p2].v;
		}
		b[p3++]=a[p2++];
	};
	while(p1<n2&&p2<n){
		if(a[p1].x<=a[p2].x)f1();
		else f2();
	}
	while(p1<n2)f1();
	while(p2<n)f2();
	std::copy(b,b+n,a);
}


int tp;
int mat[8][4]={
	{1,0, 0,-1},
	{1,0, 0,1},
	{-1,0, 0,-1},
	{-1,0, 0,1},
	{0,1, -1,0},
	{0,1, 1,0},
	{0,-1, -1,0},
	{0,-1, 1,0}};
using std::swap;
struct M{
	int x,y;
	u32 v,sgn;
};
std::vector<M> ms;
void f1b(int x0,int y0,u32 mv,u32 sgn){
	ms.push_back(M{x0,y0,mv,sgn});
	{
		u32 my=y0;
		auto vec=sgn*Vec<u32,4>{
			my*my*my+(3+mv*3)*my*my+(2+mv*3)*my,
			-3*my*my+(3+mv*3)*-2*my-(2+mv*3),
			3*my+(3+mv*3),
			-1u,
		};
		t2.push_back({-x0*2,-y0*2,0,vec});
	}
	{
		u32 mx=x0+y0,my=x0;
		auto vec=sgn*Vec<u32,6>{
			mx*mx*mx+(3+3*mv-3*my)*mx*mx+(2+3*mv-3*my)*mx,
			-3*mx*mx-2*(3+3*mv-3*my)*mx+-(2+3*mv-3*my)*1,
			3*mx+(3+3*mv-3*my)*1,
			1,
			mx,
			mx*mx,
		};
		t3.push_back({-(x0+y0)*2,x0*2,0,vec});
	}
}
void f1c(int x0,int y0,u32 mv,u32 sgn){
	u32 my=y0,mx=x0;
	auto vec=(sgn*3)*Vec<u32,6>{
	(mv*2+1)*my*mx-my*mx*mx,
	-(mv*2+1)*my+2*my*mx,
	-(mv*2+1)*mx+mx*mx,
	(mv*2+1)-2*mx,
	1,
	-my};
	t1.push_back({-x0*2,-y0*2,0,vec});
}
bool flag=1;
void f1a(int x0,int y0,int d,u32 v){
	int x1=mat[tp][0];
	int y1=mat[tp][1];
	int x2=mat[tp][2];
	int y2=mat[tp][3];
	if(y1)x1^=y1^=x1^=y1,x2^=y2^=x2^=y2,x0^=y0^=x0^=y0;
	x0*=x1;
	y0*=y2;
	f1b(x0,y0+d-1,0,v);
	f1b(x0+d,y0-1,d,-v);
	f1c(x0+d-1,y0-1,d,-v);
	f1c(x0-1,y0-1,0,v);
}
void f1(int x,int y,int d,u32 v){
	switch(tp){
	case 0:f1a(x-d,y-1, d,v);break;
	case 1:f1a(x-d,y  , d+1,v);break;
	case 2:f1a(x+d,y-1, d-1,v);break;
	case 3:f1a(x+d,y  , d,v);break;
	case 4:f1a(x  ,y-d, d,v);break;
	case 5:f1a(x+1,y-d, d,v);break;
	case 6:f1a(x  ,y+d, d,v);break;
	case 7:f1a(x+1,y+d, d,v);break;
	}
}
void f2b(int X1,int Y1,u32 sgn){
	int x=X1,y=Y1;
	{
		u32 y1=y-1;
		auto vec=sgn*Vec<u32,4>{1,y1,y1*y1,y1*y1*y1};
		t2.push_back({-x*2+1,-y*2+1,qp,vec});
	}
	{
		u32 x1=x+y-1,y1=x;
		auto vec=sgn*Vec<u32,6>{1,x1,x1*x1,-x1*x1*x1+y1*3*x1*(x1-1),y1*3*(1-2*x1),y1*3,};
		t3.push_back({-(x+y)*2+1,(x-1)*2+1,qp,vec});
	}
	{
		u32 y1=y-1,x1=x-1;
		auto vec=sgn*Vec<u32,6>{1,x1,y1,x1*y1,y1*x1*x1,x1*x1};
		t1.push_back({-x*2+1,-y*2+1,qp,vec});
	}
}
void f2a(int X1,int X2,int Y1,int Y2){
	int x1=mat[tp][0];
	int y1=mat[tp][1];
	int x2=mat[tp][2];
	int y2=mat[tp][3];
	if(y1)x1^=y1^=x1^=y1,x2^=y2^=x2^=y2,X1^=Y1^=X1^=Y1,X2^=Y2^=X2^=Y2;
	X1*=x1,X2*=x1;
	if(X1>X2)X1^=X2^=X1^=X2;
	Y1*=y2,Y2*=y2;
	if(Y1>Y2)Y1^=Y2^=Y1^=Y2;
	
	f2b(X1,Y1,1);
	f2b(X1,Y2+1,-1);
	f2b(X2+1,Y1,-1);
	f2b(X2+1,Y2+1,1);
}
struct Q{
	int o,a,b,c,d;
}qs[N];
u32 mod(u32 x){
	x>>=1;
	u32 P=1073741824;
	x&=P-1;
	while(x%3)x+=P;
	return x/3;
}
int main(){
	int m=read(1,maxm);
	for(register int _(0);_<m;++_){
		int o=read(1,2);
		if(o==1){
			int x=read(1,maxv),y=read(1,maxv),d=read(1,maxv);
			int v=read(1,maxv);
			qs[_]=Q{1,x,y,d-1,v};
		}else{
			int x1=read(1,maxv),x2=read(x1,maxv);
			int y1=read(1,maxv),y2=read(y1,maxv);
			qs[_]=Q{2,x1,x2,y1,y2};
		}
	}
    t1.clear();
		t2.clear();
		t3.clear();
		
		ms.clear();
		
		tp=1;
		qp=0;
		F(_,0,m){
			Q &q=qs[_];
			if(q.o==1)f1(q.a,q.b,q.c,q.d);
			else{
				++qp;
				f2a(q.a,q.b,q.c,q.d);
			}
		}
		solve(t1.data(),t1.size());
		solve(t2.data(),t2.size());
		solve(t3.data(),t3.size());
    t1.clear();
		t2.clear();
		t3.clear();
		
		ms.clear();
		
		tp=2;
		qp=0;
		F(_,0,m){
			Q &q=qs[_];
			if(q.o==1)f1(q.a,q.b,q.c,q.d);
			else{
				++qp;
				f2a(q.a,q.b,q.c,q.d);
			}
		}
		solve(t1.data(),t1.size());
		solve(t2.data(),t2.size());
		solve(t3.data(),t3.size());t1.clear();
		t2.clear();
		t3.clear();
		
		ms.clear();
		
		tp=3;
		qp=0;
		F(_,0,m){
			Q &q=qs[_];
			if(q.o==1)f1(q.a,q.b,q.c,q.d);
			else{
				++qp;
				f2a(q.a,q.b,q.c,q.d);
			}
		}
		solve(t1.data(),t1.size());
		solve(t2.data(),t2.size());
		solve(t3.data(),t3.size());t1.clear();
		t2.clear();
		t3.clear();
		
		ms.clear();
		
		tp=4;
		qp=0;
		F(_,0,m){
			Q &q=qs[_];
			if(q.o==1)f1(q.a,q.b,q.c,q.d);
			else{
				++qp;
				f2a(q.a,q.b,q.c,q.d);
			}
		}
		solve(t1.data(),t1.size());
		solve(t2.data(),t2.size());
		solve(t3.data(),t3.size());t1.clear();
		t2.clear();
		t3.clear();
		
		ms.clear();
		
		tp=5;
		qp=0;
		F(_,0,m){
			Q &q=qs[_];
			if(q.o==1)f1(q.a,q.b,q.c,q.d);
			else{
				++qp;
				f2a(q.a,q.b,q.c,q.d);
			}
		}
		solve(t1.data(),t1.size());
		solve(t2.data(),t2.size());
		solve(t3.data(),t3.size());t1.clear();
		t2.clear();
		t3.clear();
		
		ms.clear();
		
		tp=6;
		qp=0;
		F(_,0,m){
			Q &q=qs[_];
			if(q.o==1)f1(q.a,q.b,q.c,q.d);
			else{
				++qp;
				f2a(q.a,q.b,q.c,q.d);
			}
		}
		solve(t1.data(),t1.size());
		solve(t2.data(),t2.size());
		solve(t3.data(),t3.size());t1.clear();
		t2.clear();
		t3.clear();
		
		ms.clear();
		
		tp=7;
		qp=0;
		F(_,0,m){
			Q &q=qs[_];
			if(q.o==1)f1(q.a,q.b,q.c,q.d);
			else{
				++qp;
				f2a(q.a,q.b,q.c,q.d);
			}
		}
		solve(t1.data(),t1.size());
		solve(t2.data(),t2.size());
		solve(t3.data(),t3.size());t1.clear();
		t2.clear();
		t3.clear();
		
		ms.clear();
		
		tp=8;
		qp=0;
		F(_,0,m){
			Q &q=qs[_];
			if(q.o==1)f1(q.a,q.b,q.c,q.d);
			else{
				++qp;
				f2a(q.a,q.b,q.c,q.d);
			}
		}
		solve(t1.data(),t1.size());
		solve(t2.data(),t2.size());
		solve(t3.data(),t3.size());
	Fe(_,1,qp)printf("%u\n",mod(ans[_]));
}

Details

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 23ms
memory: 8196kb

Subtask #2:

score: 0
Wrong Answer

Test #3:

score: 0
Wrong Answer
time: 698ms
memory: 16236kb

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 1563ms
memory: 27140kb

Subtask #4:

score: 0
Wrong Answer

Test #7:

score: 0
Wrong Answer
time: 2507ms
memory: 38620kb

Subtask #5:

score: 0
Wrong Answer

Test #9:

score: 0
Wrong Answer
time: 3506ms
memory: 45712kb

Subtask #6:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 3618ms
memory: 57344kb

Subtask #7:

score: 0
Wrong Answer

Test #13:

score: 0
Wrong Answer
time: 4089ms
memory: 56712kb

Subtask #8:

score: 0
Wrong Answer

Test #15:

score: 0
Wrong Answer
time: 4453ms
memory: 58116kb

Subtask #9:

score: 0
Wrong Answer

Test #17:

score: 0
Wrong Answer
time: 4572ms
memory: 60136kb