1 solutions

  • 0
    @ 2026-8-27 22:44:46

    60pts

    #include <bits/stdc++.h>
    using namespace std;
    
    const long long INF = 4e18;
    int n, m, q;
    vector<long long> A, B;
    
    // 查询B区间的最小值和最大值(暴力查询,O(length))
    pair<long long, long long> getMinMaxB(int l, int r) {
        long long mn = INF, mx = -INF;
        for (int i = l; i <= r; i++) {
            mn = min(mn, B[i]);
            mx = max(mx, B[i]);
        }
        return {mn, mx};
    }
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0);
        
        cin >> n >> m >> q;
        A.resize(n + 1);
        B.resize(m + 1);
        
        for (int i = 1; i <= n; i++) cin >> A[i];
        for (int i = 1; i <= m; i++) cin >> B[i];
        
        while (q--) {
            int l1, r1, l2, r2;
            cin >> l1 >> r1 >> l2 >> r2;
            
            // 获取B区间的最值
            auto [minB, maxB] = getMinMaxB(l2, r2);
            
            long long ans = -INF;
            for (int x = l1; x <= r1; x++) {
                long long score;
                if (A[x] > 0) {
                    score = A[x] * minB;
                } else if (A[x] < 0) {
                    score = A[x] * maxB;
                } else {
                    score = 0;
                }
                ans = max(ans, score);
            }
            
            cout << ans << "\n";
        }
        
        return 0;
    }
    
    • 1

    Information

    ID
    1151
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    10
    Tags
    # Submissions
    5
    Accepted
    1
    Uploaded By