40pts求调呜呜对拍跑了半天不知道错哪里了
查看原帖
40pts求调呜呜对拍跑了半天不知道错哪里了
516722
WSSBWSSWSW楼主2024/10/12 15:20
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
const int M = 1e9;
int a[N],b[N];
int lg[N];
struct node{
	int ma,mi;
	int maz,miz;
	int maf,mif;
	int t;
}c[2][N][30];
node merge(node x,node y){
	node it = {-M,M,-M,M,-M,M,0};
	if(x.t||y.t){
		it.t = 1;
	}
	it.ma = max(x.ma,y.ma);
	it.mi = min(x.mi,y.mi);
	if(x.ma>0){
		it.maz = x.maz;
		it.miz = x.miz;
	}
	if(y.ma>0){
		it.maz = max(y.maz,it.maz);
		it.miz = min(y.miz,it.miz);
	}
	if(x.mi<0){
		it.maf = x.maf;
		it.mif = x.mif;
	}
	if(y.mi<0){
		it.maf = max(y.maf,it.maf);
		it.mif = min(y.mif,it.mif);
	}
	return it;
}
void init(){
	lg[1] = 0;
	for(int i = 2;i<N;++i){
		lg[i] = lg[i/2]+1;
	}
}
int n,m,q;
long long work(int l1,int r1,int l2,int r2){
	long long ans = -M;
	int k1 = lg[r1-l1+1],k2=lg[r2-l2+1];
	node x = merge(c[0][l1][k1],c[0][r1-(1<<k1)+1][k1]);
	node y = merge(c[1][l2][k2],c[1][r2-(1<<k2)+1][k2]);
	if(x.t)ans = 0;
	if(x.ma>0){
		if(y.mi<0){
			ans = max(ans,1ll*x.miz*y.mif);
		}else if(y.t){
			ans = max(ans,0ll);
		}else{
			ans = max(ans,1ll*x.maz*y.miz);
		}
	}
	if(x.mi<0){
		if(y.ma>0){
			ans = max(ans,1ll*x.maf*y.maz);
		}else if(y.t){
			ans = max(ans,0ll);
		}else{
			ans = max(ans,1ll*x.mif*y.maf);
		}
	}
	return ans;
}
int main(){
	//freopen("game.in","r",stdin);
	//freopen("game.out","w",stdout);
	scanf("%d%d%d",&n,&m,&q);
	for(int i = 1;i<=n;++i){
		scanf("%d",&a[i]);
		if(a[i]){
			if(a[i]>0){
				c[0][i][0]={a[i],a[i],a[i],a[i],0,0,0};
			}else{
				c[0][i][0]={a[i],a[i],0,0,a[i],a[i],0};
			}
		}else{
			c[0][i][0]={0,0,0,0,0,0,1};
		}
		
	}
	for(int i = 1;i<=m;++i){
		scanf("%d",&b[i]);
		if(b[i]){
			if(b[i]>0){
				c[1][i][0]={b[i],b[i],b[i],b[i],0,0,0};
			}else{
				c[1][i][0]={b[i],b[i],0,0,b[i],b[i],0};
			}
		}else{
			c[1][i][0]={0,0,0,0,0,0,1};
		}
	}
	init();
	for(int k = 1;k<=20;++k){
		for(int i = 1;i+(1<<k)-1<=n;++i){
			c[0][i][k]=merge(c[0][i][k-1],c[0][i+(1<<(k-1))][k-1]);
		}
	}
	for(int k = 1;k<=20;++k){
		for(int i = 1;i+(1<<k)-1<=m;++i){
			c[1][i][k]=merge(c[1][i][k-1],c[1][i+(1<<(k-1))][k-1]);
		}
	}
	while(q--){
		int l1,r1,l2,r2;
		scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
		printf("%lld\n",work(l1,r1,l2,r2));
	}
	return 0;
}
2024/10/12 15:20
加载中...