比赛 CSP2022提高组 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 策略游戏 最终得分 100
用户昵称 lihaoze 运行时间 3.481 s
代码语言 C++ 内存使用 39.66 MiB
提交时间 2022-10-30 10:58:02
显示代码纯文本
#include "bits/stdc++.h"

using i64 = long long;

constexpr i64 N = 100010, LG = 18, INF = 1LL << 63 - 1, FNI = -INF;
int n, m, q;
i64 maxA1[LG][N], maxA2[LG][N], minA1[LG][N], minA2[LG][N], maxB[LG][N], minB[LG][N];
 
i64 queryMax(i64 ST[][N], int l, int r){
    int len = std::log2(r - l + 1);
    return std::max(ST[len][l], ST[len][r - (1 << len) + 1]);
}

i64 queryMin(i64 ST[][N], int l, int r){
    int len = std::log2(r - l + 1);
    return std::min(ST[len][l], ST[len][r - (1 << len) + 1]);
}

void initST() {
    #define update(x, y) x##y[i][j] = std::x(x##y[i - 1][j], x##y[i - 1][j + (1 << (i - 1))])
    for(int i = 1; i < LG; ++ i)
        for(int j = 1; j <= n - (1 << i) + 1; ++ j)
            update(max, A1), update(max, A2), update(min, A1), update(min, A2);
    for(int i = 1; i < LG; ++ i)
        for(int j = 1; j <= m - (1 << i) + 1; ++ j)
            update(max, B), update(min, B);
}

int main() {
    freopen("csp2022_game.in", "r", stdin); 
    freopen("csp2022_game.out", "w", stdout);
    std::cin >> n >> m >> q;
    for(i64 i = 1, x; i <= n; ++ i){
        std::cin >> x;
        if(x >= 0){
            maxA1[0][i] = minA1[0][i] = x,
            maxA2[0][i] = FNI,
            minA2[0][i] = INF; 
        } else{
            maxA2[0][i] = minA2[0][i] = x,
            maxA1[0][i] = FNI,
            minA1[0][i] = INF;
        }
    }
    for(i64 i = 1, x; i <= m; ++ i){
        std::cin >> x;
        minB[0][i] = maxB[0][i] = x;
    }
    initST();   
    for(int i = 1;i <= q; ++ i){
        int l1, r1, l2, r2;
        std::cin >> l1 >> r1;
        std::cin >> l2 >> r2;
        i64 ans = FNI;
        if(queryMax(maxA1, l1, r1) != FNI) ans = std::max(ans, queryMax(maxA1, l1, r1) * queryMin(minB, l2, r2));
        if(queryMin(minA1, l1, r1) != INF) ans = std::max(ans, queryMin(minA1, l1, r1) * queryMin(minB, l2, r2));
        if(queryMax(maxA2, l1, r1) != FNI) ans = std::max(ans, queryMax(maxA2, l1, r1) * queryMax(maxB, l2, r2));
        if(queryMin(minA2, l1, r1) != INF) ans = std::max(ans, queryMin(minA2, l1, r1) * queryMax(maxB, l2, r2));
        std::cout << ans << '\n';
    } 
}