QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#209432#6134. Soldier GameSham_DevourWA 448ms17108kbC++171.8kb2023-10-10 15:00:192023-10-10 15:00:19

Judging History

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

  • [2023-10-10 15:00:19]
  • 评测
  • 测评结果:WA
  • 用时:448ms
  • 内存:17108kb
  • [2023-10-10 15:00:19]
  • 提交

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];
	void init() {
		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;
	z.init();
	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].init();
		t[p].a[0][1] = 1;
		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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5984kb

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: 448ms
memory: 17108kb

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
101
164
176
0
147
135
152
101
200
131
134
33
136
53074
72
171
146
4294967281
183
77
176
101
200
135
38
109
119
126
158
189
70
0
38
999867615
188
161
4
116
116
200
0
101
200
50
4294967251
183
139
4294967136
183
107
139
4294967183
178
85993
126
153
168
163
96
10...

result:

wrong answer 11th numbers differ - expected: '63', found: '101'