QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#209887 | #6134. Soldier Game | Selnev | WA | 316ms | 17312kb | C++14 | 3.0kb | 2023-10-10 18:55:13 | 2023-10-10 18:55:14 |
Judging History
answer
#include <bits/stdc++.h>
#define BUFFSIZE (1 << 20 | 1)
#define fgetc(f) (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BUFFSIZE, f), p1 == p2) ? EOF : *p1 ++)
struct freader {
char buf[BUFFSIZE], *p1 = buf, *p2 = buf;
FILE *f;
freader(FILE *f_ = stdin): f(f_) {
setvbuf(f, NULL, _IONBF, 0);
}
template<typename T>
void read(T &x) {
char c;
for (c = fgetc(f); c != EOF && (c < '0' || '9' < c) && c != '-'; c = fgetc(f));
if (c == '-') for (x = 0, c = fgetc(f); c != EOF && '0' <= c && c <= '9'; c = fgetc(f)) x = (x << 3) + (x << 1) - (c ^ '0');
else for (x = 0; c != EOF && '0' <= c && c <= '9'; c = fgetc(f)) x = (x << 3) + (x << 1) + (c ^ '0');
}
template<typename T, typename ... Args>
void read(T &x, Args &...args) {
return read(x), read(args...);
}
} fin;
#undef fgetc
#undef BUFFSIZE
#define INF 0xffffffff
using namespace std;
struct Segment {
long long f00, f01, f10, f11;
} tree[400003];
struct Node {
int x, val;
bool tp;
Node() = default;
Node(int x_, int val_, bool tp_): x(x_), val(val_), tp(tp_) {}
} b[200003];
int T, n;
int a[100003];
inline void pushUp(int u) {
tree[u].f00 = min(max(tree[u << 1].f00, tree[u << 1 | 1].f00), max(tree[u << 1].f01, tree[u << 1 | 1].f10));
tree[u].f01 = min(max(tree[u << 1].f00, tree[u << 1 | 1].f01), max(tree[u << 1].f01, tree[u << 1 | 1].f11));
tree[u].f10 = min(max(tree[u << 1].f10, tree[u << 1 | 1].f00), max(tree[u << 1].f11, tree[u << 1 | 1].f10));
tree[u].f11 = min(max(tree[u << 1].f10, tree[u << 1 | 1].f01), max(tree[u << 1].f11, tree[u << 1 | 1].f11));
}
void buildTree(int u, int L, int R) {
if (L == R) {
tree[u].f00 = a[L];
tree[u].f01 = (L == n ? INF : a[L] + a[L + 1]);
tree[u].f10 = -INF;
tree[u].f11 = INF;
return;
}
const int mid = (L + R) >> 1;
buildTree(u << 1, L, mid);
buildTree(u << 1 | 1, mid + 1, R);
pushUp(u);
}
void update0(int u, int L, int R, int x) {
if (L == R) {
tree[u].f00 = INF;
return;
}
const int mid = (L + R) >> 1;
if (x <= mid) update0(u << 1, L, mid, x);
else update0(u << 1 | 1, mid + 1, R, x);
pushUp(u);
}
void update1(int u, int L, int R, int x) {
if (L == R) {
tree[u].f01 = INF;
return;
}
const int mid = (L + R) >> 1;
if (x <= mid) update1(u << 1, L, mid, x);
else update1(u << 1 | 1, mid + 1, R, x);
pushUp(u);
}
int main() {
fin.read(T);
while (T --) {
int m = 0;
long long ans = 0x3f3f3f3f3f3f3f3f;
fin.read(n);
for (int i = 1; i <= n; ++ i) fin.read(a[i]);
for (int i = 1; i <= n; ++ i) b[++ m] = Node(i, a[i], false);
for (int i = 1; i < n; ++ i) b[++ m] = Node(i, a[i] + a[i + 1], true);
sort(b + 1, b + m + 1, [](Node n1, Node n2) {return n1.val < n2.val;});
buildTree(1, 1, n);
for (int i = 1; i <= m; ++ i) {
ans = min(ans, (long long)(tree[1].f00) - b[i].val);
if (b[i].tp) update1(1, 1, n, b[i].x);
else update0(1, 1, n, b[i].x);
}
printf("%lld\n", ans);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5864kb
input:
3 5 -1 4 2 1 1 4 1 3 2 4 1 7
output:
1 2 0
result:
ok 3 number(s): "1 2 0"
Test #2:
score: -100
Wrong Answer
time: 316ms
memory: 17312kb
input:
10010 1 1000000000 1 -1000000000 2 1000000000 -1000000000 4 1000000000 1000000000 -1000000000 -1000000000 3 100 -100 100 16 -17 91 -19 66 100 -70 -71 76 -58 99 52 19 25 -67 -63 -32 7 -95 -26 63 -55 -19 77 -100 17 -100 72 -53 -32 8 -100 53 44 -100 -65 -81 -59 100 100 57 -47 1 11 99 10 -100 3 32 2 -26...
output:
0 0 1 2000000000 100 139 158 200 199 105 163 190 200 0 200 135 200 136 200 166 137 0 200 0 72 200 199 21 183 77 176 189 200 200 77 199 159 131 158 189 70 0 38 1999783074 200 175 0 132 176 200 0 118 200 50 1 188 157 36 183 136 155 17 191 1999894276 134 164 200 163 96 119 130 52 161 153 130 162 0 195 ...
result:
wrong answer 3rd numbers differ - expected: '0', found: '1'