QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#844954#4407. 回275307894a#100 ✓2774ms49040kbC++145.7kb2025-01-06 12:53:512025-01-06 12:53:56

Judging History

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

  • [2025-01-06 12:53:56]
  • 评测
  • 测评结果:100
  • 用时:2774ms
  • 内存:49040kb
  • [2025-01-06 12:53:51]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=4e5+5,M=N*40+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(28382);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#ifdef LOCAL
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
	#else 
	#define gdb(...) void()
	#endif
}using namespace Debug;
int m;
struct ques{
	int x,y,w,id;
}q1[N],q2[N],q3[N],q[N];
int h1,h2,h3,qh;
const ui i3=2863311531u;
ui ans[N];int vis[N];
int nx[N],ny[N],xh,yh;
struct bit{
	ui f[N];
	void clr(){Me(f,0);}
	void add(int x,ui y){while(x<=4*m) f[x]+=y,x+=x&-x;}
	ui qry(int x){ui ans=0;while(x) ans+=f[x],x-=x&-x;return ans;}
	void clr(int x){while(x<=4*m&&f[x]) f[x]=0,x+=x&-x;}
}f[4][2],g[3];
ui w[5][3][5][3],wg[5][3][5][3];
void cdq(int l,int r,int op){
	if(l==r) return;
	int m=l+r>>1;cdq(l,m,op);cdq(m+1,r,op);
	sort(q+l,q+m+1,[](ques x,ques y){return x.x<y.x;});
	sort(q+m+1,q+r+1,[](ques x,ques y){return x.x<y.x;});
	int R=m;
	for(int i=r;i>m;i--){
		while(R>=l&&q[R].x>=q[i].x){
			if(!q[R].id){
				ui pw=q[R].w;
				for(int a=0;a<4;a++){
					ui ps=pw;
					for(int b=0;b<2;b++) f[a][b].add(q[R].y,ps),ps*=q[R].x+nx[q[R].y];
					pw*=q[R].x;
				} 
			}
			R--;
		}
		gdb(l,r,i,R);
		if(!q[i].id) continue;
		static ui w[4][2];
		for(int a=0;a<4;a++) for(int b=0;b<2;b++) w[a][b]=f[a][b].qry(xh)-f[a][b].qry(q[i].y+op-1);
		ui pw=q[i].w;
		for(int c=0;c<4;c++){
			ui ps=pw;
			for(int d=0;d<2;d++){
				for(int a=0;a<4;a++) for(int b=0;b<2;b++) ans[q[i].id]+=w[a][b]*ps*::w[a][b][c][d];
				ps*=q[i].x+nx[q[i].y]-1;
			}
			pw*=q[i].x-1;
		}
	}
	while(R<m){
		R++;
		if(!q[R].id){
			for(int a=0;a<4;a++) for(int b=0;b<2;b++) f[a][b].clr(q[R].y);
		}
	}
	/*for(int i=l;i<=m;i++) if(!q[i].id) for(int j=m+1;j<=r;j++) if(q[j].id&&q[j].x<=q[i].x&&q[j].y+op<=q[i].y){
		ui dx=q[i].x-(q[j].x-1),dy=(q[i].x+nx[q[i].y])-(q[j].x+nx[q[j].y]-1);
		ans[q[j].id]+=(dx*(dx+1)*dy-dx*dx*(dx+1)+dx*(dx+1)*(2*dx+1)*i3)*q[j].w*q[i].w;
	}*/
}
void mul(ui A,ui B,ui C,ui D,ui E){
	for(int a=3;~a;a--) for(int b=1;~b;b--) for(int c=3;~c;c--) for(int d=1;~d;d--) if(wg[a][b][c][d]){
		wg[a+1][b][c][d]+=wg[a][b][c][d]*A;
		wg[a][b+1][c][d]+=wg[a][b][c][d]*B;
		wg[a][b][c+1][d]+=wg[a][b][c][d]*C;
		wg[a][b][c][d+1]+=wg[a][b][c][d]*D;
		wg[a][b][c][d]*=E;
	}
}
void clr(){
	for(int a=0;a<4;a++) for(int b=0;b<2;b++) for(int c=0;c<4;c++) for(int d=0;d<2;d++) w[a][b][c][d]+=wg[a][b][c][d],wg[a][b][c][d]=0;
	wg[0][0][0][0]=1;
}
void calc(ques *qs,int l,int r){

	clr();Me(w,0);
	mul(1,0,-1,0,0);mul(1,0,-1,0,1);mul(0,1,0,-1,0);clr();
	mul(1,0,-1,0,0);mul(1,0,-1,0,0);mul(1,0,-1,0,1);mul(0,0,0,0,-1);clr();
	mul(1,0,-1,0,0);mul(1,0,-1,0,1);mul(2,0,-2,0,1);mul(0,0,0,0,i3);clr();



	for(int i=l;i<=r;i++) q[i]=qs[i];
	xh=0;
	for(int i=l;i<=r;i++) nx[++xh]=q[i].y-q[i].x;
	sort(nx+1,nx+xh+1);xh=unique(nx+1,nx+xh+1)-nx-1;
	for(int i=l;i<=r;i++) q[i].y=LB(nx+1,nx+xh+1,q[i].y-q[i].x)-nx;
	cdq(l,r,0);
	for(int i=l;i<=r;i++) q[i]=qs[i],swap(q[i].x,q[i].y);
	xh=0;
	for(int i=l;i<=r;i++) nx[++xh]=q[i].y-q[i].x;
	sort(nx+1,nx+xh+1);xh=unique(nx+1,nx+xh+1)-nx-1;
	for(int i=l;i<=r;i++) q[i].y=LB(nx+1,nx+xh+1,q[i].y-q[i].x)-nx;
	cdq(l,r,1);
}
void calcs(ques *q,int l,int r){
	xh=0;
	for(int i=l;i<=r;i++) nx[++xh]=q[i].x;
	sort(nx+1,nx+xh+1);xh=unique(nx+1,nx+xh+1)-nx-1;
	for(int i=l;i<=r;i++) q[i].x=LB(nx+1,nx+xh+1,q[i].x)-nx;
	for(int i=l;i<=r;i++){
		if(!q[i].id){
			g[0].add(q[i].x,q[i].w);
			g[1].add(q[i].x,q[i].w*nx[q[i].x]);
			g[2].add(q[i].x,q[i].w*nx[q[i].x]*nx[q[i].x]);
		}else{
			static ui w[3];
			for(int o:{0,1,2}) w[o]=g[o].qry(xh)-g[o].qry(q[i].x-1);
			ui tx=nx[q[i].x]-1;
			ans[q[i].id]+=q[i].w*q[i].y*((tx*tx-tx)*w[0]+(1-2*tx)*w[1]+w[2]);
		}
	}
	/*for(int i=l;i<=r;i++)if(!q[i].id){
		for(int j=i+1;j<=r;j++) if(q[j].id&&q[j].x<=q[i].x){
			ui dx=q[i].x-q[j].x+1;
			ans[q[j].id]+=dx*(dx+1)*q[j].y*q[j].w*q[i].w;
			gdb(ans[q[j].id],q[i].x,q[i].y,q[j].x,q[j].y);;
		}
	}*/
}
void Solve(){
	scanf("%d",&m);
	// if(m>2e4) return;
	for(int i=1;i<=m;i++){
		int op;scanf("%d",&op);
		if(op==1){
			int x,y,d,w;
			scanf("%d%d%d%d",&x,&y,&d,&w);
			q3[++h3]=(ques){y+d-1,0,-w,0};
			q3[++h3]=(ques){y-d-1,0,w,0};
			
			q1[++h1]=(ques){x+d-1,y+d-1,w,0};
			q1[++h1]=(ques){x-d-1,y-d-1,-w,0};
			x*=-1;
			q2[++h2]=(ques){x+d-1,y+d-1,w,0};
			q2[++h2]=(ques){x-d-1,y-d-1,-w,0};
		}else{
			vis[i]=1;
			int sx,sy,tx,ty;
			scanf("%d%d%d%d",&sx,&tx,&sy,&ty);
			q3[++h3]=(ques){sy,tx-sx+1,1,i};
			q3[++h3]=(ques){ty+1,tx-sx+1,-1,i};
			q1[++h1]=(ques){sx,sy,1,i};
			q1[++h1]=(ques){tx+1,ty+1,1,i};
			q1[++h1]=(ques){tx+1,sy,-1,i};
			q1[++h1]=(ques){sx,ty+1,-1,i};
			sx*=-1;tx*=-1;swap(sx,tx);
			q2[++h2]=(ques){sx,sy,1,i};
			q2[++h2]=(ques){tx+1,ty+1,1,i};
			q2[++h2]=(ques){tx+1,sy,-1,i};
			q2[++h2]=(ques){sx,ty+1,-1,i};
		}
	}
	calc(q1,1,h1);
	gdb(ans[2]>>1);
	calc(q2,1,h2);
	gdb(ans[2]>>1);
	calcs(q3,1,h3);
	for(int i=1;i<=m;i++) if(vis[i]) printf("%u\n",(ans[i]>>1)&(1<<30)-1);
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

详细

Subtask #1:

score: 23
Accepted

Test #1:

score: 23
Accepted
time: 10ms
memory: 16508kb

Test #2:

score: 23
Accepted
time: 14ms
memory: 14504kb

Subtask #2:

score: 8
Accepted

Test #3:

score: 8
Accepted
time: 342ms
memory: 32964kb

Test #4:

score: 8
Accepted
time: 384ms
memory: 31868kb

Subtask #3:

score: 8
Accepted

Test #5:

score: 8
Accepted
time: 753ms
memory: 39948kb

Test #6:

score: 8
Accepted
time: 897ms
memory: 29216kb

Subtask #4:

score: 8
Accepted

Test #7:

score: 8
Accepted
time: 1248ms
memory: 34048kb

Test #8:

score: 8
Accepted
time: 1365ms
memory: 46208kb

Subtask #5:

score: 8
Accepted

Test #9:

score: 8
Accepted
time: 1783ms
memory: 35296kb

Test #10:

score: 8
Accepted
time: 2046ms
memory: 42788kb

Subtask #6:

score: 15
Accepted

Test #11:

score: 15
Accepted
time: 2113ms
memory: 47904kb

Test #12:

score: 15
Accepted
time: 2071ms
memory: 48928kb

Subtask #7:

score: 10
Accepted

Test #13:

score: 10
Accepted
time: 2150ms
memory: 34780kb

Test #14:

score: 10
Accepted
time: 2231ms
memory: 47488kb

Subtask #8:

score: 10
Accepted

Test #15:

score: 10
Accepted
time: 2284ms
memory: 48532kb

Test #16:

score: 10
Accepted
time: 2638ms
memory: 49040kb

Subtask #9:

score: 10
Accepted

Test #17:

score: 10
Accepted
time: 2294ms
memory: 46012kb

Test #18:

score: 10
Accepted
time: 2774ms
memory: 44860kb