1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
#pragma GCC optimize(2) #pragma GCC optimize(3, "Ofast", "inline") #include<bits/stdc++.h> using namespace std;
typedef long long ll; typedef __int128 int128;
namespace FastIO { char buf[1 << 20], *p1, *p2; #define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2) ? EOF : *p1++) template<typename T> inline T read(T& x) { x = 0; int f = 1; char ch; while (!isdigit(ch = getchar())) if (ch == '-') f = -1; while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); x *= f; return x; } template<typename T, typename... Args> inline void read(T& x, Args &...x_) { read(x); read(x_...); return; } inline ll read() { ll x; read(x); return x; } inline void read(char *s) { scanf("%s", s + 1); } }; using namespace FastIO;
const int N = 1e5 + 10; const int INF = 1e9 + 10;
int n, m, Q; int a[N], b[N], c[N];
int mia[N][20], mxa[N][20]; int mib[N][20], mxb[N][20]; int fia[N][20], zia[N][20]; int lg[N];
inline void Input() { read(n, m, Q); for(int i = 1; i <= n; i++) { read(a[i]); mia[i][0] = mxa[i][0] = a[i]; fia[i][0] = (a[i] < 0 ? a[i] : -INF); zia[i][0] = (a[i] >= 0 ? a[i] : INF); } for(int i = 1; i <= m; i++) { read(b[i]); mib[i][0] = mxb[i][0] = b[i]; } }
inline void Init() { for (int i = 2; i <= max(n, m); i++) { lg[i] = lg[i >> 1] + 1; } for (int j = 1; j <= lg[n]; ++j) { for (int i = 1; i + (1 << j) - 1 <= n; ++i) { int p = i + (1 << (j - 1)); mxa[i][j] = max(mxa[i][j - 1], mxa[p][j - 1]); fia[i][j] = max(fia[i][j - 1], fia[p][j - 1]); mia[i][j] = min(mia[i][j - 1], mia[p][j - 1]); zia[i][j] = min(zia[i][j - 1], zia[p][j - 1]); } } for (int j = 1; j <= lg[m]; ++j) { for (int i = 1; i + (1 << j) - 1 <= m; ++i) { int p = i + (1 << (j - 1)); mxb[i][j] = max(mxb[i][j - 1], mxb[p][j - 1]); mib[i][j] = min(mib[i][j - 1], mib[p][j - 1]); } } }
inline int getmax(int st[N][20], int l, int r) { int k = lg[r - l + 1]; return max(st[l][k], st[r - (1 << k) + 1][k]); } inline int getmin(int st[N][20], int l, int r) { int k = lg[r - l + 1]; return min(st[l][k], st[r - (1 << k) + 1][k]); }
inline void Work() { Init(); int la, ra, lb, rb; while(Q--) { read(la, ra, lb, rb); int amax = getmax(mxa, la, ra); int amin = getmin(mia, la, ra); int afmx = getmax(fia, la, ra); int azmn = getmin(zia, la, ra); int bmax = getmax(mxb, lb, rb); int bmin = getmin(mib, lb, rb); int ans = -INF; ans = max(ans, amax * (amax >= 0 ? bmin : bmax)); ans = max(ans, amin * (amin >= 0 ? bmin : bmax)); if (afmx != -INF) { ans = max(ans, afmx * (afmx >= 0 ? bmin : bmax)); } if (azmn != INF) { ans = max(ans, azmn * (azmn >= 0 ? bmin : bmax)); } printf("%lld\n", ans); } }
int main() { int T = 1; while(T--) { Input(); Work(); } return 0; }
|