记录编号 |
577485 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
[CSP 2022S]策略游戏 |
最终得分 |
100 |
用户昵称 |
00000 |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
5.317 s |
提交时间 |
2022-11-05 17:35:53 |
内存使用 |
36.91 MiB |
显示代码纯文本
#include<bits/stdc++.h>
#define ll long long
#define vb 0x3f3f3f3f3f3f3f3f
using namespace std;
ll n,m,t,a[200000],b[200000];
ll l,r,i,j,flag;
struct sst{
ll l,r,maxn,minn,zmin,fmax;
}bb[800000],aa[800000];
void build(ll x,ll l,ll r)
{
bb[x].l=l,bb[x].r=r;
if(l==r)
{
bb[x].maxn=bb[x].minn=b[l];return;
}
ll mid=(l+r)>>1;
build(2*x,l,mid);build(2*x+1,mid+1,r);
bb[x].maxn=max(bb[2*x].maxn,bb[2*x+1].maxn);
bb[x].minn=min(bb[2*x].minn,bb[2*x+1].minn);
}
ll ask(ll x,ll l,ll r,ll s)//s=1 max s=2 min
{
if(l>bb[x].r||r<bb[x].l)
{
if(s==1) return -vb;
return vb;
}
if(bb[x].l>=l&&bb[x].r<=r)
{
if(s==1) return bb[x].maxn;
return bb[x].minn;
}
if(s==1) return max(ask(2*x,l,r,s),ask(2*x+1,l,r,s));//max(bb[2*x].maxn,bb[2*x+1].maxn);
return min(ask(2*x,l,r,s),ask(2*x+1,l,r,s));
}
void builda(ll x,ll l,ll r)
{
aa[x].l=l,aa[x].r=r;
if(l==r)
{
if(a[l]>=0) aa[x].zmin=a[l],aa[x].fmax=-vb;
else aa[x].zmin=vb,aa[x].fmax=a[l];
aa[x].maxn=aa[x].minn=a[l];return;
}
ll mid=(l+r)>>1;
builda(2*x,l,mid);builda(2*x+1,mid+1,r);
aa[x].maxn=max(aa[2*x].maxn,aa[2*x+1].maxn);
aa[x].minn=min(aa[2*x].minn,aa[2*x+1].minn);
aa[x].zmin=min(aa[2*x].zmin,aa[2*x+1].zmin);
aa[x].fmax=max(aa[2*x].fmax,aa[2*x+1].fmax);
}
ll aska(ll x,ll l,ll r,ll s)//s=1 max s=2 min s==3 zmin s=4 fmax
{
if(l>aa[x].r||r<aa[x].l)
{
if(s==1) return -vb;
if(s==2) return vb;
if(s==3) return vb;
if(s==4) return -vb;
}
if(aa[x].l>=l&&aa[x].r<=r)
{
if(s==1) return aa[x].maxn;
if(s==2)
{
return aa[x].minn;
}
if(s==3) return aa[x].zmin;
if(s==4) return aa[x].fmax;
}
if(s==1) return max(aska(2*x,l,r,s),aska(2*x+1,l,r,s));
if(s==2) return min(aska(2*x,l,r,s),aska(2*x+1,l,r,s));
if(s==3) return min(aska(2*x,l,r,s),aska(2*x+1,l,r,s));
if(s==4) return max(aska(2*x,l,r,s),aska(2*x+1,l,r,s));
}
ll check()
{
ll g=ask(1,i,j,1),h=ask(1,i,j,2);
if(g<0) return 2;// -
if(h>=0) return 3;// +
return 1;//有正有负
}
int main(){
freopen("csp2022_game.in","r",stdin);
freopen("csp2022_game.out","w",stdout);
cin>>n>>m>>t;
for(int q=1;q<=n;q++) cin>>a[q];
for(int q=1;q<=m;q++) cin>>b[q];
build(1,1,m);//b
builda(1,1,n);
while(t--)
{
cin>>l>>r>>i>>j;
if(check()==1)
{
ll c=0,d=0;
c=ask(1,i,j,2);
d=ask(1,i,j,1);
ll f=vb,g=-vb,fc,gd;
f=aska(1,l,r,3);
g=aska(1,l,r,4);
if(f==vb) fc=-vb;
else fc=f*c;
if(g==-vb) gd=-vb;
else gd=g*d;
cout<<max(fc,gd)<<endl;
}
if(check()==2)
{
ll f=vb;
f=aska(1,l,r,2);
if(f>0)
{
ll g=vb;
g=ask(1,i,j,2);
cout<<f*g<<endl;
}else
{
ll g=-vb;
g=ask(1,i,j,1);
cout<<f*g<<endl;
}
}
if(check()==3)
{
ll f=-vb;
f=aska(1,l,r,1);
if(f<0)
{
ll g=-vb;
g=ask(1,i,j,1);
cout<<f*g<<endl;
}else
{
ll g=vb;
g=ask(1,i,j,2);
cout<<f*g<<endl;
}
}
}
return 0;
}