QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#209505#6134. Soldier GameSham_DevourWA 459ms19092kbC++171.8kb2023-10-10 15:26:262023-10-10 15:26:26

Judging History

你现在查看的是最新测评结果

  • [2023-10-10 15:26:26]
  • 评测
  • 测评结果:WA
  • 用时:459ms
  • 内存:19092kb
  • [2023-10-10 15:26:26]
  • 提交

answer

#include <cstdio>
#include <iostream>
#include <algorithm>
#define ll long long
#define lson p << 1
#define rson p << 1 | 1
using namespace std;
const int N = 1e5 + 5;

int n, a[N];

struct node {
	int val, id, type;
	node() {}
	node(int _val, int _id, int _type) : val(_val), id(_id), type(_type) {}
} val[N << 1];

struct matrix {
	ll a[2][2];
	matrix() {
		for (int i = 0; i < 2; i++)
			for (int j = 0; j < 2; j++) a[i][j] = 1e18;
	}
} t[N << 2];
matrix operator * (matrix x, matrix y) {
	matrix z;
	for (int k = 0; k < 2; k++)
		for (int i = 0; i < 2; i++)
			for (int j = 0; j < 2; j++) z.a[i][j] = min(z.a[i][j], max(x.a[i][k], y.a[k][j]));
	return z;
}

void pushup(int p) {t[p] = t[lson] * t[rson];}
void build(int p, int l, int r) {
	if (l == r) {
		t[p].a[0][0] = t[p].a[1][0] = t[p].a[1][1] = 1e18;
		t[p].a[0][1] = -1e18;
		return;
	}
	int mid = l + r >> 1;
	build(lson, l, mid), build(rson, mid + 1, r);
	pushup(p);
}
void update(int p, int L, int R, int l, int r, int type) {
	if (L == R) return t[p].a[type][0] = r, void();
	int mid = L + R >> 1;
	if (l <= mid) update(lson, L, mid, l, r, type);
	else update(rson, mid + 1, R, l, r, type);
	pushup(p);
}

int main() {
	int T;
	scanf("%d", &T);
	while (T--) {
		scanf("%d", &n);
		int tot = 0;
		for (int i = 1; i <= n; i++) {
			scanf("%d", &a[i]);
			val[++tot] = node(a[i], i, 0);
			if (i > 1) val[++tot] = node(a[i] + a[i - 1], i, 1);
		}
		if (n == 2) {printf("%lld\n", min(a[1] + a[2], abs(a[1] - a[2]))); continue;}
		sort(val + 1, val + 1 + tot, [&](node x, node y) {return x.val < y.val;});
		build(1, 1, n);
		ll ans = 1e18;
		for (int i = tot; i; i--) update(1, 1, n, val[i].id, val[i].val, val[i].type), ans = min(ans, t[1].a[0][0] - val[i].val);
		printf("%lld\n", ans);
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 16524kb

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: 459ms
memory: 19092kb

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
0
2000000000
100
135
103
181
189
84
63
164
176
0
147
135
152
36
200
131
134
33
136
53074
72
171
146
4294967281
183
77
176
89
200
135
38
109
119
126
158
189
70
0
38
999804364
188
161
4
116
116
200
0
101
200
39
4294967251
183
139
4294967136
183
107
139
4294967183
178
85993
126
153
168
163
96
53
96...

result:

wrong answer 22nd numbers differ - expected: '0', found: '33'