比赛 |
CSP2022提高组 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
策略游戏 |
最终得分 |
100 |
用户昵称 |
op_组撒头屯 |
运行时间 |
1.838 s |
代码语言 |
C++ |
内存使用 |
21.67 MiB |
提交时间 |
2022-10-30 09:56:59 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100000+5;
const ll inf=1e18;
int n,m,q;
int has0[N]={0};
ll a[3][N];
struct sdf{
int l,r;
ll mn,mx,s1,s2;
}tr[3][4*N];
void pushup(int pt,int k){
tr[k][pt].mn=min(tr[k][pt*2].mn,tr[k][pt*2+1].mn);
tr[k][pt].s1=max(tr[k][pt*2].s1,tr[k][pt*2+1].s1);
tr[k][pt].s2=min(tr[k][pt*2].s2,tr[k][pt*2+1].s2);
tr[k][pt].mx=max(tr[k][pt*2].mx,tr[k][pt*2+1].mx);
return ;
}
void build(int pt,int l,int r,int k){
tr[k][pt]={l,r};
if (l==r){
tr[k][pt].mn=tr[k][pt].mx=a[k][l];
if (a[k][l]<=0)tr[k][pt].s1=a[k][l],tr[k][pt].s2=inf;
else tr[k][pt].s2=a[k][l],tr[k][pt].s1=-inf;
return ;
}
int mid=(l+r)/2;
build(pt*2,l,mid,k);build(pt*2+1,mid+1,r,k);
pushup(pt,k);return ;
}
inline sdf cmp(sdf x,sdf y){
sdf tmp;
tmp.mn=min(x.mn,y.mn);
tmp.mx=max(x.mx,y.mx);
tmp.s1=max(x.s1,y.s1);
tmp.s2=min(x.s2,y.s2);
return tmp;
}
sdf query(int pt,int x,int y,int k){
int l=tr[k][pt].l,r=tr[k][pt].r;
if (x<=l&&r<=y)return tr[k][pt];
int mid=(l+r)/2;sdf now;
now={0,0,inf,-inf,-inf,inf};
if (x<=mid)now=cmp(now,query(pt*2,x,y,k));
if (mid+1<=y)now=cmp(now,query(pt*2+1,x,y,k));
return now;
}
int main(){
freopen ("csp2022_game.in","r",stdin);
freopen ("csp2022_game.out","w",stdout);
scanf("%d%d%d",&n,&m,&q);
for (int i=1;i<=n;i++){
scanf("%lld",&a[0][i]);
has0[i]=has0[i-1]+(a[0][i]==0);
}
for (int i=1;i<=m;i++)scanf("%lld",&a[1][i]);
build(1,1,n,0);build(1,1,m,1);
while(q--){
int l1,r1,l2,r2;
scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
sdf nowb=query(1,l2,r2,1);
sdf nowa=query(1,l1,r1,0);
ll ans=-inf;
if (nowb.mn>0){
if (nowa.mx<0)ans=max(ans,nowa.mx*nowb.mx);
else ans=max(ans,nowa.mx*nowb.mn);
}
else if (nowb.mx<0){
if (nowa.mn<0)ans=max(ans,nowa.mn*nowb.mx);
else ans=max(ans,nowa.mn*nowb.mn);
}
else{
if (nowa.s1!=-inf)ans=max(ans,nowa.s1*nowb.mx);
if (nowa.s2!=inf)ans=max(ans,nowa.s2*nowb.mn);
}
printf("%lld\n",ans);
}
return 0;
}