记录编号 586144 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 [CSP 2022S]策略游戏 最终得分 100
用户昵称 Gravatarjacken 是否通过 通过
代码语言 C++ 运行时间 2.746 s
提交时间 2024-01-06 19:00:36 内存使用 51.73 MiB
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5;
int a[N];
int b[N];
int fza[N][20];
int fza1[N][20];
int fzb[N][20];
int fzb1[N][20];
int ffa[N][20];
int ffa1[N][20];
int ffb[N][20];
int ffb1[N][20];
int n,q,m;
signed main()
{
    freopen("csp2022_game.in","r",stdin);
    freopen("csp2022_game.out","w",stdout);
    scanf("%lld %lld %lld",&n,&m,&q);
    for(int i = 1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        fza[i][0] = a[i]>=0?a[i]:(int)-1e10;
        fza1[i][0] = a[i]>=0?a[i]:(int)1e10;
        ffa[i][0] = a[i]<0?a[i]:(int)-1e10;
        ffa1[i][0] = a[i]<0?a[i]:(int)1e10;
    }
    for(int i = 1;i<=m;i++)
    {
        scanf("%lld",&b[i]);
        fzb[i][0] = b[i]>=0?b[i]:(int)-1e10;
        fzb1[i][0] = b[i]>=0?b[i]:(int)1e10;
        ffb[i][0] = b[i]<0?b[i]:(int)-1e10;
        ffb1[i][0] = b[i]<0?b[i]:(int)1e10;
    }
    for(int i = 1;i<=log2(n);i++)
    {
        for(int j = 1;j<=n-(1<<i)+1;j++)
        {
            fza[j][i] = max(fza[j][i-1],fza[j+(1<<(i-1))][i-1]);
            fza1[j][i] = min(fza1[j][i-1],fza1[j+(1<<(i-1))][i-1]);
            ffa[j][i] = max(ffa[j][i-1],ffa[j+(1<<(i-1))][i-1]);
            ffa1[j][i] = min(ffa1[j][i-1],ffa1[j+(1<<(i-1))][i-1]);
        }
    }
    for(int i = 1;i<=log2(m);i++)
    {
        for(int j = 1;j<=m-(1<<i)+1;j++)
        {
            fzb[j][i] = max(fzb[j][i-1],fzb[j+(1<<(i-1))][i-1]);
            fzb1[j][i] = min(fzb1[j][i-1],fzb1[j+(1<<(i-1))][i-1]);
            ffb[j][i] = max(ffb[j][i-1],ffb[j+(1<<(i-1))][i-1]);
            ffb1[j][i] = min(ffb1[j][i-1],ffb1[j+(1<<(i-1))][i-1]);
        }
    }
    for(int i = 1;i<=q;i++)
    {
        int la,ra,lb,rb;
        scanf("%lld %lld %lld %lld",&la,&ra,&lb,&rb);
        int kl = log2(ra-la+1);
        int num;
        int kr = log2(rb-lb+1);
        if(max(fza[la][kl],fza[ra-(1<<kl)+1][kl])!=(int)-1e10&&max(ffa[la][kl],ffa[ra-(1<<kl)+1][kl])!=(int)-1e10)
        {
            if(max(ffb[lb][kr],ffb[rb-(1<<kr)+1][kr]) == (int)-1e10)
            {
                num = max(fza[la][kl],fza[ra-(1<<kl)+1][kl])*min(fzb1[lb][kr],fzb1[rb-(1<<kr)+1][kr]);
            }
            if(max(fzb[lb][kr],fzb[rb-(1<<kr)+1][kr]) == (int)-1e10)
            {
                num = min(ffa1[la][kl],ffa1[ra-(1<<kl)+1][kl])*max(ffb[lb][kr],ffb[rb-(1<<kr)+1][kr]);
            }
            if(max(fzb[lb][kr],fzb[rb-(1<<kr)+1][kr])!=(int)-1e10&&max(ffb[lb][kr],ffb[rb-(1<<kr)+1][kr])!=(int)-1e10)
            {
                int L1 = min(fza1[la][kl],fza1[ra-(1<<kl)+1][kl])*min(ffb1[lb][kr],ffb1[rb-(1<<kr)+1][kr]),L2 = max(ffa[la][kl],ffa[ra-(1<<kl)+1][kl])*max(fzb[lb][kr],fzb[rb-(1<<kr)+1][kr]);
                num = max(L1,L2);
            }
        }
        if(max(fza[la][kl],fza[ra-(1<<kl)+1][kl]) == (int)-1e10&&max(ffa[la][kl],ffa[ra-(1<<kl)+1][kl])!=(int)-1e10)
        {
            if(max(fzb[lb][kr],fzb[rb-(1<<kr)+1][kr]) == (int)-1e10&&max(ffb[lb][kr],ffb[rb-(1<<kr)+1][kr])!=(int)-1e10)
            {
                num = min(ffa1[la][kl],ffa1[ra-(1<<kl)+1][kl])*max(ffb[lb][kr],ffb[rb-(1<<kr)+1][kr]);
            }
            else
            {
                num = max(ffa[la][kl],ffa[ra-(1<<kl)+1][kl])*max(fzb[lb][kr],fzb[rb-(1<<kr)+1][kr]);
            }
        }
        if(max(fza[la][kl],fza[ra-(1<<kl)+1][kl])!=(int)-1e10&&max(ffa[la][kl],ffa[ra-(1<<kl)+1][kl]) == (int)-1e10)
        {
            if(max(fzb[lb][kr],fzb[rb-(1<<kr)+1][kr])!=(int)-1e10&&max(ffb[lb][kr],ffb[rb-(1<<kr)+1][kr]) == (int)-1e10)
            {
                num = max(fza[la][kl],fza[ra-(1<<kl)+1][kl])*min(fzb1[lb][kr],fzb1[rb-(1<<kr)+1][kr]);
            }
            else
            {
                num = min(fza1[la][kl],fza1[ra-(1<<kl)+1][kl])*min(ffb1[lb][kr],ffb1[rb-(1<<kr)+1][kr]);
            }
        }
        printf("%lld\n",num);
    }
    return 0;
}