题目 P8818 CSP-S 2022 策略游戏
#include <bits/stdc++.h>
#define lc (p << 1)
#define rc (p << 1 | 1)
#define MAX 0
#define MIN 1
using namespace std;
typedef long long LL;
const int N = 1e5 + 5;
const LL INF = 0x3f3f3f3f3f3f3f3f;
int n, m, q;
struct Node
{
int pl, pr;
LL v;
};
struct Segment_tree
{
int flag;
Node tree[N << 2];
LL a[N];
inline LL cmp(const LL& a, const LL& b)
{
if (flag == MAX) return max(a, b);
if (flag == MIN) return min(a, b);
return 0;
}
inline LL getinf()
{
if (flag == MAX) return -INF;
if (flag == MIN) return INF;
return 0;
}
inline void push_up(int p)
{
tree[p].v = cmp(tree[lc].v, tree[rc].v);
}
void build(int p)
{
if (tree[p].pl == tree[p].pr)
{
tree[p].v = a[tree[p].pl];
return;
}
int mid = (tree[p].pl + tree[p].pr) >> 1;
tree[lc].pl = tree[p].pl;
tree[lc].pr = mid;
tree[rc].pl = mid + 1;
tree[rc].pr = tree[p].pr;
build(lc);
build(rc);
push_up(p);
}
LL query(int p, int l, int r)
{
if (l <= tree[p].pl && tree[p].pr <= r)
return tree[p].v;
int mid = (tree[p].pl + tree[p].pr) >> 1;
LL res = getinf();
if (l <= mid) res = cmp(res, query(lc, l, r));
if (r > mid) res = cmp(res, query(rc, l, r));
return res;
}
};
Segment_tree maxl = { MAX };
Segment_tree minl = { MIN };
Segment_tree minp = { MIN };
Segment_tree maxn = { MAX };
Segment_tree maxq = { MAX };
Segment_tree minq = { MIN };
void init()
{
maxl.tree[1].pl = 1;
maxl.tree[1].pr = n;
maxl.build(1);
minl.tree[1].pl = 1;
minl.tree[1].pr = n;
minl.build(1);
minp.tree[1].pl = 1;
minp.tree[1].pr = n;
minp.build(1);
maxn.tree[1].pl = 1;
maxn.tree[1].pr = n;
maxn.build(1);
maxq.tree[1].pl = 1;
maxq.tree[1].pr = m;
maxq.build(1);
minq.tree[1].pl = 1;
minq.tree[1].pr = m;
minq.build(1);
}
LL solve_Q(LL x, int l2, int r2)
{
if (x >= 0) return minq.query(1, l2, r2);
return maxq.query(1, l2, r2);
}
LL solve_L(int l1, int r1, int l2, int r2)
{
LL f1 = minl.query(1, l1, r1);
f1 *= solve_Q(f1, l2, r2);
LL f2 = maxl.query(1, l1, r1);
f2 *= solve_Q(f2, l2, r2);
LL f3 = minp.query(1, l1, r1);
f3 *= solve_Q(f3, l2, r2);
LL f4 = maxn.query(1, l1, r1);
f4 *= solve_Q(f4, l2, r2);
return max({ f1, f2, f3, f4 });
}
int main()
{
cin >> n >> m >> q;
for (int i = 1; i <= n; ++i)
{
int x;
cin >> x;
maxl.a[i] = x;
minl.a[i] = x;
minp.a[i] = minp.getinf();
maxn.a[i] = maxn.getinf();
if (x >= 0) minp.a[i] = x;
if (x <= 0) maxn.a[i] = x;
}
for (int i = 1; i <= m; ++i)
{
int x;
cin >> x;
maxq.a[i] = x;
minq.a[i] = x;
}
init();
while (q--)
{
int l1, r1, l2, r2;
cin >> l1 >> r1 >> l2 >> r2;
cout << solve_L(l1, r1, l2, r2) << endl;
}
return 0;
}
0
4
0
-2
3
2
-1
0
4
0
-2
3
2
-1
编译失败
Nothing is compiled: OUTPUT exceeds.
有没有哪位冤种遇到相同的情况吖(急)
请问这是我代码有问题还是洛谷的 BUG
求 指正代码问题/修复洛谷 BUG