QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#269788#6134. Soldier GamezlxFTHWA 398ms22748kbC++172.3kb2023-11-29 23:35:492023-11-29 23:35:49

Judging History

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

  • [2023-11-29 23:35:49]
  • 评测
  • 测评结果:WA
  • 用时:398ms
  • 内存:22748kb
  • [2023-11-29 23:35:49]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long LL;
const int N = 1e5 + 5;
const LL InfLL = 1e18;

int n, m;
LL a[N];

struct Data {
  int tg, len;
  LL v, ans, lsum, rsum, msum;
} t[4 * N];
struct Node {
  LL v, p, t;
  bool operator<(const Node &rhs) const {
    return v < rhs.v;
  }
} b[2 * N];
inline int ls(int i) {return 2 * i;}
inline int rs(int i) {return 2 * i + 1;}
inline void upd(int i) {
  t[i].tg = t[rs(i)].tg;
  t[i].v = t[rs(i)].v;

  t[i].ans = max(t[ls(i)].ans, t[rs(i)].ans);
  t[i].lsum = max(t[ls(i)].lsum, t[rs(i)].ans);
  t[i].rsum = max(t[rs(i)].rsum, t[ls(i)].ans);
  t[i].msum = max(t[ls(i)].lsum, t[rs(i)].rsum);
  if (t[ls(i)].tg) {
    t[i].ans = min(t[i].ans, max({t[ls(i)].rsum, t[rs(i)].lsum, t[ls(i)].v}));
    if (t[ls(i)].len != 1)
      t[i].lsum = min(t[i].lsum, max({t[ls(i)].msum, t[rs(i)].lsum, t[ls(i)].v}));
    if (t[rs(i)].len != 1)
      t[i].rsum = min(t[i].rsum, max({t[ls(i)].rsum, t[rs(i)].msum, t[ls(i)].v}));
    if (t[ls(i)].len != 1 && t[rs(i)].len != 1)
      t[i].msum = min(t[i].msum, max({t[ls(i)].msum, t[rs(i)].msum, t[ls(i)].v}));
  }
}
void build(int i, int l, int r) {
  t[i].len = r - l + 1;
  if (l == r) {
    t[i].tg = 1;
    t[i].v = a[l] + a[l + 1];
    t[i].lsum = t[i].rsum = t[i].msum = 0;
    t[i].ans = a[l];
    return;
  }
  int mid = (l + r) / 2;
  build(ls(i), l, mid);
  build(rs(i), mid + 1, r);
  upd(i);
}
void mdf(int i, int l, int r, int x, int tg) {
  if (l == r) {
    if (tg == 1) t[i].tg = 0;
    else {
      t[i].ans = InfLL;
    }
    return;
  }
  int mid = (l + r) / 2;
  if (x <= mid) mdf(ls(i), l, mid, x, tg);
  else mdf(rs(i), mid + 1, r, x, tg);
  upd(i);
}

void solve() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  build(1, 1, n);
  m = 0;
  for (int i = 1; i <= n; ++i) {
    b[++m] = {a[i], i, 0};
    if (i + 1 <= n)
      b[++m] = {a[i] + a[i + 1], i, 1};
  }
  sort(b + 1, b + m + 1);
  LL ans = InfLL;
  for (int i = 1; i <= m; ++i) {
    ans = min(ans, t[1].ans - b[i].v);    
    mdf(1, 1, n, b[i].p, b[i].t);
  }
  cout << ans << "\n";
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 398ms
memory: 22748kb

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
100
164
176
0
147
135
152
100
200
131
134
0
136
0
72
171
146
15
183
77
176
100
200
135
38
109
119
126
158
189
70
0
38
999867614
188
161
0
116
116
200
0
101
200
50
1
183
139
36
183
107
139
17
178
85993
126
153
168
163
96
100
96
52
126
71
130
79
0
123
188
173
33...

result:

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