样例全过WA0pts
#include <bits/stdc++.h>
using namespace std;
//For the basic const define.
const int MAXN = 1e5 + 10;
const int LOGN = 21;
const int inf = 2147483647;
const int inm = -2147483647;
//For the basic define.
int n, m, q;
int a[MAXN], b[MAXN];
//For the maximum of a and b.
int mxsta[MAXN][LOGN], mxstb[MAXN][LOGN];
//For the minimum of a and b.
int mnsta[MAXN][LOGN], mnstb[MAXN][LOGN];
//For the minimum which bigger then 0 of a.
int mnbsta[MAXN][LOGN];
//For the maximum which smaller then 0 of a.
int mxssta[MAXN][LOGN];
//For the quick log2.
int logx[MAXN];
//For the quick read of inteeger.
inline int read() {
char ch = getchar();
int x = 0, f = 1;
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) + ch - '0';
ch = getchar();
}
return x * f;
}
//For the initialization.
inline void init() {
//Read.
n = read();
m = read();
q = read();
for (int i = 1; i <= n; i++) {
mnsta[i][0] = mxsta[i][0] = a[i] = read();
if (a[i] >= 0) {
mnbsta[i][0] = a[i];
mxssta[i][0] = inm;
} else {
mxssta[i][0] = a[i];
mnbsta[i][0] = inf;
}
}
for (int i = 1; i <= m; i++)
mnstb[i][0] = mxstb[i][0] = b[i] = read();
//Prepare for the quick log2.
logx[1] = 0;
logx[2] = 1;
for (int i = 3; i < MAXN; i++)
logx[i] = logx[i / 2] + 1;
//Prepare for Sprase Tables.
for (int j = 1; j <= LOGN; j++) {
for (int i = 1; i + (1 << j) - 1 <= n; i++) {
int s = i + (1 << (j - 1));
mxsta[i][j] = max(mxsta[i][j - 1], mxsta[s][j - 1]);
mxssta[i][j] = max(mxssta[i][j - 1], mxssta[s][j - 1]);
mnsta[i][j] = min(mnsta[i][j - 1], mnsta[s][j - 1]);
mnbsta[i][j] = min(mnbsta[i][j - 1], mnbsta[s][j - 1]);
}
for (int i = 1; i + (1 << j) - 1 <= m; i++) {
int s = i + (1 << (j - 1));
mxstb[i][j] = max(mxstb[i][j - 1], mxstb[s][j - 1]);
mnstb[i][j] = min(mnstb[i][j - 1], mnstb[s][j - 1]);
}
}
}
//For the O(1) query of max.
inline int max_query(int l, int r, int f[MAXN][LOGN]) {
int s = logx[r - l + 1];
return max(f[l][s], f[r - (1 << s) + 1][s]);
}
//For the O(1) query of min.
inline int min_query(int l, int r, int f[MAXN][LOGN]) {
int s = logx[r - l + 1];
return min(f[l][s], f[r - (1 << s) + 1][s]);
}
//Update the best idea.
void update(int &a, int b) {
if (b > a)
a = b;
}
//Solve the problem.
inline void solve() {
int l1, r1, l2, r2;
l1 = read(), r1 = read();
l2 = read(), r2 = read();
int maxa = max_query(l1, r1, mxsta);
int mina = min_query(l1, r1, mnsta);
int mxsa = max_query(l1, r1, mxssta);
int mnba = min_query(l1, r1, mnbsta);
int maxb = max_query(l2, r2, mxstb);
int minb = min_query(l2, r2, mnstb);
int ans = inm;
update(ans, maxa * (maxa >= 0 ? minb : maxb));
update(ans, mina * (mina >= 0 ? minb : maxb));
if (mxsa != inm)
update(ans, mxsa * (mxsa >= 0 ? minb : maxb));
if (mnba != inf)
update(ans, mnba * (mnba >= 0 ? minb : maxb));
printf("%d\n", ans);
}
int main() {
//Initialization.
init();
//For q times use the solve function.
while (q--)
solve();
return 0;
}