Submission #557455

# Submission time Handle Problem Language Result Execution time Memory
557455 2022-05-05T10:39:38 Z erray Snowball (JOI21_ho_t2) C++17
100 / 100
86 ms 11384 KB
// author: erray
#include <bits/stdc++.h>

#ifdef DEBUG
  #include "debug.h"
#else
  #define debug(...) void(37)
#endif

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int N, Q;
  cin >> N >> Q;
  vector<long long> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  

  vector<int> ord(N - 1);
  iota(ord.begin(), ord.end(), 0);
  sort(ord.begin(), ord.end(), [&](int x, int y) {
    return A[x + 1] - A[x] < A[y + 1] - A[y];
  });

  long long mn = 0, mx = 0;
  long long cur = 0;
  int p = 0;
  vector<long long> ans(N);
  for (int q = 0; q < Q; ++q) {
    long long W;
    cin >> W;
    cur += W;
    while (p < N - 1 && A[ord[p] + 1] - A[ord[p]] <= max(mx, cur) - min(mn, cur)) {
      int x = ord[p];
      if (cur < mn) {
        ans[x] += mx;
        ans[x + 1] += A[x + 1] - A[x] - mx;
      } else if (cur > mx) {
        ans[x + 1] += -mn;
        ans[x] += A[x + 1] - A[x] + mn; 
      } else {
        assert(false);
      }
      ++p;
    }
    mx = max(mx, cur);
    mn = min(mn, cur);
  }
  debug(ans, mx, mn, p);
  ans[0] -= mn;
  ans[N - 1] += mx;
  for (int i = p; i < N - 1; ++i) {
    ans[ord[i]] += mx;
    ans[ord[i] + 1] -= mn;
  }
  for (int i = 0; i < N; ++i) {
    cout << ans[i] << " \n"[i == N - 1];
  }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 372 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 380 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 372 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 380 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 25 ms 2344 KB Output is correct
21 Correct 25 ms 2220 KB Output is correct
22 Correct 24 ms 1960 KB Output is correct
23 Correct 21 ms 1872 KB Output is correct
24 Correct 26 ms 2504 KB Output is correct
25 Correct 80 ms 9556 KB Output is correct
26 Correct 86 ms 9420 KB Output is correct
27 Correct 84 ms 9164 KB Output is correct
28 Correct 82 ms 9296 KB Output is correct
29 Correct 85 ms 8772 KB Output is correct
30 Correct 66 ms 8136 KB Output is correct
31 Correct 56 ms 7620 KB Output is correct
32 Correct 53 ms 7752 KB Output is correct
33 Correct 9 ms 1232 KB Output is correct
34 Correct 83 ms 9816 KB Output is correct
35 Correct 80 ms 9288 KB Output is correct
36 Correct 80 ms 9428 KB Output is correct
37 Correct 86 ms 9292 KB Output is correct
38 Correct 79 ms 9040 KB Output is correct
39 Correct 73 ms 9304 KB Output is correct
40 Correct 65 ms 9296 KB Output is correct
41 Correct 28 ms 2972 KB Output is correct
42 Correct 71 ms 7640 KB Output is correct
43 Correct 74 ms 11000 KB Output is correct
44 Correct 28 ms 2848 KB Output is correct
45 Correct 82 ms 9304 KB Output is correct
46 Correct 78 ms 11084 KB Output is correct
47 Correct 80 ms 11352 KB Output is correct
48 Correct 80 ms 11384 KB Output is correct