比赛 |
CSP2022提高组 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
策略游戏 |
最终得分 |
100 |
用户昵称 |
yrtiop |
运行时间 |
2.183 s |
代码语言 |
C++ |
内存使用 |
83.55 MiB |
提交时间 |
2022-10-30 10:56:45 |
显示代码纯文本
#include <bits/stdc++.h>
using i64 = long long;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
int a[maxn],b[maxn],n,m,Q,lg[maxn],sum[maxn];
struct ST {
int f[maxn][20],dp[maxn][20];
ST() {
memset(f , 0 , sizeof(f));
memset(dp , 0 , sizeof(dp));
}
void init0() {
for(int i = 1;i <= m;++ i)
f[i][0] = dp[i][0] = b[i];
for(int k = 1;(1 << k) <= m;++ k)
for(int i = 1;i + (1 << k) - 1 <= m;++ i) {
f[i][k] = std::max(f[i][k - 1] , f[i + (1 << (k - 1))][k - 1]);
dp[i][k] = std::min(dp[i][k - 1] , dp[i + (1 << (k - 1))][k - 1]);
}
}
void init1() {//+ max
for(int i = 1;i <= n;++ i)
if(a[i] > 0)f[i][0] = dp[i][0] = a[i];
else f[i][0] = dp[i][0] = 0;
for(int k = 1;(1 << k) <= n;++ k)
for(int i = 1;i + (1 << k) - 1 <= n;++ i) {
f[i][k] = std::max(f[i][k - 1] , f[i + (1 << (k - 1))][k - 1]);
dp[i][k] = std::min(dp[i][k - 1] , dp[i + (1 << (k - 1))][k - 1]);
}
return ;
}
void init2() {// + min
for(int i = 1;i <= n;++ i)
if(a[i] > 0)f[i][0] = dp[i][0] = a[i];
else f[i][0] = dp[i][0] = INF;
for(int k = 1;(1 << k) <= n;++ k)
for(int i = 1;i + (1 << k) - 1 <= n;++ i) {
f[i][k] = std::max(f[i][k - 1] , f[i + (1 << (k - 1))][k - 1]);
dp[i][k] = std::min(dp[i][k - 1] , dp[i + (1 << (k - 1))][k - 1]);
}
return ;
}
void init3() {// - max
for(int i = 1;i <= n;++ i)
if(a[i] < 0)f[i][0] = dp[i][0] = a[i];
else f[i][0] = dp[i][0] = -INF;
for(int k = 1;(1 << k) <= n;++ k)
for(int i = 1;i + (1 << k) - 1 <= n;++ i) {
f[i][k] = std::max(f[i][k - 1] , f[i + (1 << (k - 1))][k - 1]);
dp[i][k] = std::min(dp[i][k - 1] , dp[i + (1 << (k - 1))][k - 1]);
}
return ;
}
void init4() {// - min
for(int i = 1;i <= n;++ i)
if(a[i] < 0)f[i][0] = dp[i][0] = a[i];
else f[i][0] = dp[i][0] = 0;
for(int k = 1;(1 << k) <= n;++ k)
for(int i = 1;i + (1 << k) - 1 <= n;++ i) {
f[i][k] = std::max(f[i][k - 1] , f[i + (1 << (k - 1))][k - 1]);
dp[i][k] = std::min(dp[i][k - 1] , dp[i + (1 << (k - 1))][k - 1]);
}
return ;
}
int MAX(int l,int r) {
int k = lg[r - l + 1];
return std::max(f[l][k] , f[r - (1 << k) + 1][k]);
}
int MIN(int l,int r) {
int k = lg[r - l + 1];
return std::min(dp[l][k] , dp[r - (1 << k) + 1][k]);
}
}tr[5];
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("%d",&a[i]),sum[i] = sum[i - 1] + (!a[i]);
for(int i = 1;i <= m;++ i)
scanf("%d",&b[i]);
int cnt = std::max(n , m);
for(int i = 2;i <= cnt;++ i)
lg[i] = lg[i >> 1] + 1;
tr[0].init0();
tr[1].init1();
tr[2].init2();
tr[3].init3();
tr[4].init4();
while(Q --) {
int a,b,x,y;
scanf("%d %d %d %d",&a,&b,&x,&y);
i64 ans = -1e18;
if(sum[b] - sum[a - 1])ans = 0;
if(tr[1].MAX(a , b)) {
ans = std::max(ans , 1ll * tr[1].MAX(a , b) * tr[0].MIN(x , y));
}
if(tr[2].MIN(a , b) != INF) {
ans = std::max(ans , 1ll * tr[2].MIN(a , b) * tr[0].MIN(x , y));
}
if(tr[3].MAX(a , b) != -INF) {
ans = std::max(ans , 1ll * tr[3].MAX(a , b) * tr[0].MAX(x , y));
}
if(tr[4].MIN(a , b)) {
ans = std::max(ans , 1ll * tr[4].MIN(a , b) * tr[0].MAX(x , y));
}
printf("%lld\n",ans);
}
return 0;
}