比赛 CSP2022提高组 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 策略游戏 最终得分 100
用户昵称 ZRQ 运行时间 2.691 s
代码语言 C++ 内存使用 51.12 MiB
提交时间 2022-10-30 12:23:41
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int N=100005;
ll INF=1e10;
int n,m,q;
ll mna1[N][20],mna2[N][20],mxa1[N][20],mxa2[N][20];
ll mnb1[N][20],mxb1[N][20],mnb2[N][20],mxb2[N][20];
char ch;
int sig;
ll x;
inline ll read(){x=0;sig=1;ch=getchar();while(ch<48||ch>57){if(ch==45)sig=-1;ch=getchar();}while(ch>47&&ch<58)x=(x<<3)+(x<<1)+(ch^48),ch=getchar();x*=sig;return x;}
inline void write(ll x)
{
	if(x<0)
	{
		putchar('-'),write(-x);
		return ;
	}
	if(x>9) write(x/10);
	putchar(x%10+'0');
	return ;
}
int main()
{
	freopen("csp2022_game.in","r",stdin);
	freopen("csp2022_game.out","w",stdout);
	n=read(),m=read(),q=read();
	for(int i=1;i<=n;++i)
	{
		ll a=read();
		if(a>=0) mna1[i][0]=mxa1[i][0]=a,mxa2[i][0]=-INF,mna2[i][0]=INF;
		else mna2[i][0]=mxa2[i][0]=a,mna1[i][0]=INF,mxa1[i][0]=-INF;
	}
	for(int i=1;i<=m;++i)
	{
		ll b=read();
		if(b>=0) mnb1[i][0]=mxb1[i][0]=b,mxb2[i][0]=-INF,mnb2[i][0]=INF;
		else mnb2[i][0]=mxb2[i][0]=b,mnb1[i][0]=INF,mxb1[i][0]=-INF;
	}
	for(int i=1;i<=16;++i)
		for(int j=1;j+(1<<i)-1<=n;++j)
			mxa1[j][i]=max(mxa1[j][i-1],mxa1[j+(1<<(i-1))][i-1]),
			mxa2[j][i]=max(mxa2[j][i-1],mxa2[j+(1<<(i-1))][i-1]),
			mxb1[j][i]=max(mxb1[j][i-1],mxb1[j+(1<<(i-1))][i-1]),
			mxb2[j][i]=max(mxb2[j][i-1],mxb2[j+(1<<(i-1))][i-1]),
			mna1[j][i]=min(mna1[j][i-1],mna1[j+(1<<(i-1))][i-1]),
			mna2[j][i]=min(mna2[j][i-1],mna2[j+(1<<(i-1))][i-1]),
			mnb1[j][i]=min(mnb1[j][i-1],mnb1[j+(1<<(i-1))][i-1]),
			mnb2[j][i]=min(mnb2[j][i-1],mnb2[j+(1<<(i-1))][i-1]);
	for(int i=1;i<=q;++i)
	{
		ll l1=read(),r1=read(),l2=read(),r2=read();
		int k1=0,k2=0;
		while((1<<(k1+1))<=(r1-l1+1)) ++k1;
		while((1<<(k2+1))<=(r2-l2+1)) ++k2;
		ll res=-1e18-5;
		ll tmp=INF;
		tmp=min(mnb1[l2][k2],mnb1[r2-(1<<k2)+1][k2]);
		tmp=min(tmp,min(mnb2[l2][k2],mnb2[r2-(1<<k2)+1][k2]));
		if(tmp!=INF)
		{
			if(max(mxa1[l1][k1],mxa1[r1-(1<<k1)+1][k1])!=-INF) res=max(res,max(mxa1[l1][k1],mxa1[r1-(1<<k1)+1][k1])*tmp);
			if(min(mna1[l1][k1],mna1[r1-(1<<k1)+1][k1])!=INF) res=max(res,min(mna1[l1][k1],mna1[r1-(1<<k1)+1][k1])*tmp);//a +
		}
		tmp=-INF;
		tmp=max(mxb2[l2][k2],mxb2[r2-(1<<k2)+1][k2]);
		tmp=max(tmp,max(mxb1[l2][k2],mxb1[r2-(1<<k2)+1][k2]));
		if(tmp!=-INF)
		{
			if(max(mxa2[l1][k1],mxa2[r1-(1<<k1)+1][k1])!=-INF) res=max(res,max(mxa2[l1][k1],mxa2[r1-(1<<k1)+1][k1])*tmp);
			if(min(mna2[l1][k1],mna2[r1-(1<<k1)+1][k1])!=INF) res=max(res,min(mna2[l1][k1],mna2[r1-(1<<k1)+1][k1])*tmp);
		}
		write(res);
		puts("");
	}
	return 0;
 }