Submission #733457

# Submission time Handle Problem Language Result Execution time Memory
733457 2023-04-30T19:02:26 Z tch1cherin Snowball (JOI21_ho_t2) C++17
100 / 100
239 ms 14256 KB
#include <bits/stdc++.h>
using namespace std;

template <typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

const long long INF = 1e18;

int main() {
  int n, q;
  cin >> n >> q;
  vector<long long> X(n);
  for (auto &v : X) {
    cin >> v;
  }
  X.insert(X.begin(), -INF);
  X.insert(X.end(), INF);
  min_heap<pair<long long, int>> h;
  for (int i = 0; i <= n; i++) {
    h.push({X[i + 1] - X[i], i});
  }
  long long L = 0, R = 0, x = 0;
  vector<long long> ans(n + 2);
  vector<bool> foundl(n + 2, false), foundr(n + 2, false);
  for (int i = 0; i < q; i++) {
    long long W;
    cin >> W;
    x += W;
    L = min(L, x);
    R = max(R, x);
    while (h.top().first <= R - L) {
      auto [d, j] = h.top();
      h.pop();
      long long left = R, right = -L;
      if (W > 0)
        left = d - right;
      
      if (W < 0)
        right = d - left;

      ans[j] += left;
      ans[j + 1] += right;
      foundr[j] = foundl[j + 1] = true;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!foundl[i])
      ans[i] -= L;

    if (!foundr[i])
      ans[i] += R;

    cout << ans[i] << "\n";
  }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 352 KB Output is correct
5 Correct 3 ms 436 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 308 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 312 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 3 ms 436 KB Output is correct
16 Correct 3 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 0 ms 300 KB Output is correct
19 Correct 2 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 352 KB Output is correct
5 Correct 3 ms 436 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 308 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 312 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 3 ms 436 KB Output is correct
16 Correct 3 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 0 ms 300 KB Output is correct
19 Correct 2 ms 308 KB Output is correct
20 Correct 81 ms 2308 KB Output is correct
21 Correct 72 ms 2184 KB Output is correct
22 Correct 68 ms 1960 KB Output is correct
23 Correct 66 ms 1904 KB Output is correct
24 Correct 76 ms 2716 KB Output is correct
25 Correct 199 ms 12308 KB Output is correct
26 Correct 199 ms 12304 KB Output is correct
27 Correct 198 ms 11856 KB Output is correct
28 Correct 197 ms 12044 KB Output is correct
29 Correct 195 ms 11540 KB Output is correct
30 Correct 184 ms 10908 KB Output is correct
31 Correct 160 ms 10652 KB Output is correct
32 Correct 158 ms 10908 KB Output is correct
33 Correct 20 ms 1488 KB Output is correct
34 Correct 209 ms 12712 KB Output is correct
35 Correct 194 ms 12068 KB Output is correct
36 Correct 192 ms 12288 KB Output is correct
37 Correct 195 ms 12044 KB Output is correct
38 Correct 189 ms 11856 KB Output is correct
39 Correct 199 ms 12060 KB Output is correct
40 Correct 188 ms 12052 KB Output is correct
41 Correct 95 ms 2976 KB Output is correct
42 Correct 140 ms 10928 KB Output is correct
43 Correct 220 ms 13840 KB Output is correct
44 Correct 96 ms 2964 KB Output is correct
45 Correct 163 ms 12216 KB Output is correct
46 Correct 221 ms 13992 KB Output is correct
47 Correct 225 ms 14224 KB Output is correct
48 Correct 239 ms 14256 KB Output is correct