比赛 |
CSP2022提高组 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
策略游戏 |
最终得分 |
100 |
用户昵称 |
zxhhh |
运行时间 |
2.244 s |
代码语言 |
C++ |
内存使用 |
57.84 MiB |
提交时间 |
2022-10-30 08:52:53 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
typedef long long LL;
int n, m, q;
LL a[N], b[N], fax[N][30], fan[N][30], fbx[N][30], fbn[N][30], fann[N][30], faxn[N][30];
LL get_maxa (int l, int r) {
int s = log2(r - l + 1);
return max(fax[l][s], fax[r - (1 << s) + 1][s]);
}
LL get_maxna (int l, int r) {
int s = log2(r - l + 1);
return max(faxn[l][s], faxn[r - (1 << s) + 1][s]);
}
LL get_mina (int l, int r) {
int s = log2(r - l + 1);
return min(fan[l][s], fan[r - (1 << s) + 1][s]);
}
LL get_minna (int l, int r) {
int s = log2(r - l + 1);
return min(fann[l][s], fann[r - (1 << s) + 1][s]);
}
LL get_maxb (int l, int r) {
int s = log2(r - l + 1);
return max(fbx[l][s], fbx[r - (1 << s) + 1][s]);
}
LL get_minb (int l, int r) {
int s = log2(r - l + 1);
return min(fbn[l][s], fbn[r - (1 << s) + 1][s]);
}
int main () {
freopen("csp2022_game.in", "r", stdin);
freopen("csp2022_game.out", "w", stdout);
scanf("%d%d%d", &n, &m, &q);
for (int i = 1;i <= n;i++) {
scanf("%lld", &a[i]);
fax[i][0] = fan[i][0] = a[i];
if (a[i] >= 0) fann[i][0] = a[i];
else fann[i][0] = 0x3f3f3f3f;
if (a[i] < 0) faxn[i][0] = a[i];
else faxn[i][0] = -0x3f3f3f3f;
}
for (int i = 1;i <= m;i++) {
scanf("%lld", &b[i]);
fbx[i][0] = fbn[i][0] = b[i];
}
for (int l = 1;l <= log2(n);l++) {
for (int i = 1;i + (1 << l) - 1 <= n;i++) {
fax[i][l] = max(fax[i][l - 1], fax[i + (1 << (l - 1))][l - 1]);
fan[i][l] = min(fan[i][l - 1], fan[i + (1 << (l - 1))][l - 1]);
faxn[i][l] = max(faxn[i][l - 1], faxn[i + (1 << (l - 1))][l - 1]);
fann[i][l] = min(fann[i][l - 1], fann[i + (1 << (l - 1))][l - 1]);
}
}
for (int l = 1;l <= log2(m);l++) {
for (int i = 1;i + (1 << l) - 1 <= m;i++) {
fbx[i][l] = max(fbx[i][l - 1], fbx[i + (1 << (l - 1))][l - 1]);
fbn[i][l] = min(fbn[i][l - 1], fbn[i + (1 << (l - 1))][l - 1]);
}
}
while (q--) {
int al, ar, bl, br;
scanf("%d%d%d%d", &al, &ar, &bl, &br);
if (get_maxa(al, ar) < 0) {
if (get_maxb(bl, br) < 0) printf("%lld\n", get_mina(al, ar) * get_maxb(bl, br));
else printf("%lld\n", get_maxa(al, ar) * get_maxb(bl, br));
}
else if (get_mina(al, ar) > 0) {
if (get_minb(bl, br) > 0) printf("%lld\n", get_maxa(al, ar) * get_minb(bl, br));
else printf("%lld\n", get_mina(al, ar) * get_minb(bl, br));
}
else if (get_maxb(bl, br) < 0) {
if (get_mina(al, ar) > 0) printf("%lld\n", get_mina(al, ar) * get_minb(bl, br));
else {
printf("%lld\n", get_mina(al, ar) * get_maxb(bl, br));
}
}
else if (get_minb(bl, br) > 0) {
if (get_maxa(al, ar) < 0) printf("%lld\n", get_maxa(al, ar) * get_maxb(bl, br));
else printf("%lld\n", get_maxa(al, ar) * get_minb(bl, br));
}
else {
printf("%lld\n", max(get_maxna(al, ar) * get_maxb(bl, br), get_minna(al, ar) * get_minb(bl, br)));
}
}
return 0;
}