QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#420955#6134. Soldier GamewaynetuWA 1576ms37304kbC++203.7kb2024-05-25 06:35:202024-05-25 06:35:20

Judging History

This is the latest submission verdict.

  • [2024-05-25 06:35:20]
  • Judged
  • Verdict: WA
  • Time: 1576ms
  • Memory: 37304kb
  • [2024-05-25 06:35:20]
  • Submitted

answer

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  cin >> T;
  while (T--) {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) {
      cin >> A[i];
    }

    vector<vector<int64_t>> tree(N * 4, vector<int64_t>(4));
    vector<tuple<int, int, int>> vec;
    for (int i = 0; i < N; ++i) {
      vec.emplace_back(A[i], i, -1);
      if (i > 0) {
        vec.emplace_back(A[i - 1] + A[i], i - 1, i);
      }
    }
    sort(vec.rbegin(), vec.rend());

    auto Build = [&]() {
      auto dfs = [&](auto self, int l, int r, int o = 0) -> void {
        if (r - l == 1) {
          tree[o][0] = 4e-9;
          tree[o][1] = tree[o][2] = tree[o][3] = 4e9;
          return;
        }
        int m = (l + r) >> 1;
        self(self, l, m, o * 2 + 1);
        self(self, m, r, o * 2 + 2);
        for (int s = 0; s < 4; ++s) {
          tree[o][s] = 4e9;
        }
        for (int s = 0; s < 4; ++s) {
          for (int t = 0; t < 4; ++t) {
            // if ((s >> 1 & 1) == 0 && (t & 1) == 0) {
            //   tree[o][(s & 1) + 2 * (t >> 1 & 1)] =
            //       min(tree[o][(s & 1) + 2 * (t >> 1 & 1)],
            //           max({tree[o * 2 + 1][s], tree[o * 2 + 2][t],
            //                A[m - 1] + A[m]}));
            // }
            if ((s >> 1 & 1) == 1 && (t & 1) == 1) {
              tree[o][(s & 1) + 2 * (t >> 1 & 1)] =
                  min(tree[o][(s & 1) + 2 * (t >> 1 & 1)],
                      max({tree[o * 2 + 1][s], tree[o * 2 + 2][t]}));
            }
          }
        }
      };

      dfs(dfs, 0, N);
    };

    Build();

    auto Update = [&](int p, int v) {
      auto dfs = [&](auto self, int l, int r, int o = 0) -> void {
        if (r - l == 1) {
          tree[o][0] = 4e-9;
          tree[o][1] = tree[o][2] = 4e9;
          if (A[l] >= v) {
            tree[o][3] = A[l];
          } else {
            tree[o][3] = 4e9;
          }
          return;
        }
        int m = (l + r) >> 1;
        if (p < m) {
          self(self, l, m, o * 2 + 1);
        } else {
          self(self, m, r, o * 2 + 2);
        }
        for (int s = 0; s < 4; ++s) {
          tree[o][s] = 4e9;
        }
        for (int s = 0; s < 4; ++s) {
          for (int t = 0; t < 4; ++t) {
            if ((s >> 1 & 1) == 0 && (t & 1) == 0 && A[m - 1] + A[m] >= v) {
              int a = (s & 1), b = (t >> 1 & 1);
              if (m - l == 1) {
                a = 1;
              }
              if (r - m == 1) {
                b = 1;
              }
              tree[o][a + 2 * b] =
                  min(tree[o][a + 2 * b],
                      max<int64_t>({tree[o * 2 + 1][s], tree[o * 2 + 2][t],
                                    A[m - 1] + A[m]}));
            }
            if (((s >> 1 & 1) == 1 || m - l == 1) &&
                ((t & 1) == 1 || r - m == 1)) {
              tree[o][(s & 1) + 2 * (t >> 1 & 1)] =
                  min(tree[o][(s & 1) + 2 * (t >> 1 & 1)],
                      max<int64_t>({tree[o * 2 + 1][s], tree[o * 2 + 2][t]}));
            }
          }
        }
      };

      dfs(dfs, 0, N);
    };

    int64_t ans = 4e9;
    for (int i = 0, j = 0; i < vec.size(); i = j) {
      while (j < vec.size() && get<0>(vec[j]) == get<0>(vec[i])) {
        auto [v, x, y] = vec[j];
        Update(x, v);
        if (y != -1) {
          Update(y, v);
        }
        j++;
      }
      // cerr << "v = " << get<0>(vec[i]) << " global = " << tree[0][3] << endl;
      ans = min(ans, tree[0][3] - get<0>(vec[i]));
    }
    cout << ans << "\n";
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1576ms
memory: 37304kb

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'