QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#93671 | #6134. Soldier Game | Lucina | AC ✓ | 856ms | 52540kb | C++17 | 2.8kb | 2023-04-02 02:40:30 | 2023-04-02 02:40:34 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int int64_t
const int nax = 3e5 + 10;
const int INF = 1e12;
int n;
int a[nax];
struct Node {
int f[2][2];
Node(int i = 0) : f{} {
f[0][0] = a[i]; /**no segment outside i*/
f[0][1] = a[i] + a[i + 1]; /** segments covered i-> goto i + 1, we will used left-based and consider only left value*/
f[1][0] = -INF; /** as previously mentioned, we will consider only left-based cover*/
f[1][1] = INF; /**impossible scenarion*/
}
int *operator [](int r) {
return f[r];
}
Node operator +(Node &other) {
Node res;
// cout << "A ";
// for (int x = 0 ; x < 2 ; ++ x, cout << '\n')
// for (int y = 0 ; y < 2 ; ++ y) cout << f[x][y] << ' ';
// cout << '\n';
// cout << "B ";
// for (int x = 0 ; x < 2 ; ++ x, cout << '\n')
// for (int y = 0 ; y < 2 ; ++ y) cout << other[x][y] << ' ';
// cout << '\n';
for (int x = 0 ; x < 2 ; ++ x)
for (int y = 0 ; y < 2 ; ++ y) {
res[x][y] = INF;
for (int k = 0 ; k < 2 ; ++ k) {
res[x][y] = min(res[x][y], max(f[x][k], other[k][y]));
}
}
// cout << "B ";
// for (int x = 0 ; x < 2 ; ++ x, cout << '\n')
// for (int y = 0 ; y < 2 ; ++ y) cout << res[x][y] << ' ';
// cout << '\n';
// cout << endl;
return res;
}
}sg[nax << 2];
void pull(int v) {
sg[v] = sg[v << 1] + sg[v << 1 | 1];
}
void build(int v, int x, int y) {
if (x == y) {
sg[v] = Node(x);
return;
}
int mid = x + y >> 1;
build(v << 1, x, mid);
build(v << 1 | 1, mid + 1, y);
pull(v);
}
void update(int v, int x, int y, int pos, int len) {
if (x == y) {
sg[v][0][len] = INF; /// this will baned the values for being used
return;
}
int mid = (x + y) >> 1;
if (pos <= mid) update(v << 1, x, mid, pos, len);
else update(v << 1 | 1, mid + 1, y, pos, len);
pull(v);
}
void solve() {
cin >> n;
for (int i = 1 ; i <= n ; ++ i) {
cin >> a[i];
}
build(1, 1, n);
vector <array <int, 3>> all;
for (int i = 1 ; i <= n ; ++ i) {
all.push_back({a[i], i, 0});
if (i + 1 <= n) all.push_back({a[i] + a[i + 1], i, 1});
}
sort(begin(all), end(all));
int ans = INF;
for (auto [k, pos, len] : all) {
ans = min(ans, sg[1][0][0] - k);
// cout << sg[1][0][0] << endl;
update(1, 1, n , pos, len);
// cout << pos << ' ' << len << endl;
}
cout << ans << '\n';
}
int32_t main() {
cin.tie(0)->sync_with_stdio(false);
int T;
for (cin >> T ; T -- ;) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 6ms
memory: 41036kb
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: 0
Accepted
time: 783ms
memory: 52424kb
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 0 136 0 72 171 146 0 183 77 176 89 200 135 38 109 119 126 158 189 70 0 38 999804364 188 161 0 116 116 200 0 101 200 39 0 183 139 0 183 107 139 0 178 85993 126 153 168 163 96 53 96 52 126 47 130 79 0 123 188 173 33 0 83 1...
result:
ok 10010 numbers
Test #3:
score: 0
Accepted
time: 101ms
memory: 49016kb
input:
1 100000 -999999999 999999999 999999998 -999999998 -999999997 999999997 999999996 -999999996 999999995 -999999995 -999999994 999999994 -999999993 999999993 -999999992 999999992 -999999991 999999991 999999990 -999999990 999999989 -999999989 999999988 -999999988 999999987 -999999987 999999986 -9999999...
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 856ms
memory: 52540kb
input:
10011 1 1000000000 1 -1000000000 2 1000000000 -1000000000 4 1000000000 1000000000 -1000000000 -1000000000 12 48 54 98 -20 -45 56 -100 78 47 23 -100 -21 19 66 41 52 17 -9 -90 -36 90 -26 66 -86 -83 -39 -83 35 78 100 -68 -62 2 -100 -23 17 89 -26 -100 -38 -14 87 32 -100 16 -31 -35 100 73 -61 -100 43 -48...
output:
0 0 0 2000000000 155 168 0 173 137 167 127 25 91 109 176 0 0 173 115 56 66 67 0 1999775909 121 166 128 77 60 146 152 78 172 110 60 200 89 160 200 130 175 79 97 1999891177 122 154 136 164 123 0 175 77 167 76 40 82 79 159 99 141 165 147 158 1999730298 0 179 31 181 192 193 47 91 164 63 65 138 100 168 1...
result:
ok 10011 numbers
Test #5:
score: 0
Accepted
time: 73ms
memory: 49140kb
input:
1 100000 50000 50000 50001 50001 50002 50002 50003 50003 50004 50004 50005 50005 50006 50006 50007 50007 50008 50008 50009 50009 50010 50010 50011 50011 50012 50012 50013 50013 50014 50014 50015 50015 50016 50016 50017 50017 50018 50018 50019 50019 50020 50020 50021 50021 50022 50022 50023 50023 500...
output:
49999
result:
ok 1 number(s): "49999"