Submission #512822

# Submission time Handle Problem Language Result Execution time Memory
512822 2022-01-16T18:36:17 Z jesus_coconut Snowball (JOI21_ho_t2) C++17
100 / 100
121 ms 21572 KB
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define all(a) begin(a), end(a)
#define F first
#define S second
using namespace std;

using ll = long long;



vector<ll> v, Q;
void load() {
  int n, q;
  cin >> n >> q;
  v.resize(n);
  Q.resize(q);
  for (auto &it : v) cin >> it;
  for (auto &it: Q) cin >> it;
}


void fix(vector<ll> const &a, vector<ll> const &b, vector<pair<ll, int>> const &items, vector<ll> &ans) {
  int p = (int)size(a) - 1;
  for (auto const &[len, idx] : items) {
	while (p >= 0 && a[p] + b[p] > len) --p;
	ll add = 0;
	if (p != size(a) - 1) add = max(add, len - b[p + 1]);
	if (p != -1) add = max(add, a[p]);
	ans[idx] += add;
  }
}

void solve() {
  Q.insert(begin(Q), 0);
  partial_sum(begin(Q), end(Q), begin(Q));
  vector<ll> mxs(size(Q)), mns(size(Q));
  partial_sum(begin(Q), end(Q), begin(mxs), [](ll a, ll b) {
	return max(a, b);
  });
  partial_sum(begin(Q), end(Q), begin(mns), [](ll a, ll b) {
	return max(a, -b);
  });
  vector<ll> ans(size(v));
  vector<pair<ll, int>> rs(size(v) - 1), ls(size(v) - 1);
  ans[0] += mns.back();
  ans.back() += mxs.back();
  for (int i = 0; i < size(v); ++i) {
	if (i != 0) ls[i - 1] = {v[i] - v[i - 1], i};
	if (i != size(v) - 1) rs[i] = {v[i+1] - v[i], i};
  }
  sort(all(rs), greater<>());
  sort(all(ls), greater<>());
  fix(mxs, mns, rs, ans);
  fix(mns, mxs, ls, ans);
  for (auto it: ans) {
	cout << it << '\n';
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);


  load();
  solve();

  return 0;
}

Compilation message

Main.cpp: In function 'void fix(const std::vector<long long int>&, const std::vector<long long int>&, const std::vector<std::pair<long long int, int> >&, std::vector<long long int>&)':
Main.cpp:29:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |  if (p != size(a) - 1) add = max(add, len - b[p + 1]);
      |      ~~^~~~~~~~~~~~~~
Main.cpp: In function 'void solve()':
Main.cpp:49:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |   for (int i = 0; i < size(v); ++i) {
      |                   ~~^~~~~~~~~
Main.cpp:51:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |  if (i != size(v) - 1) rs[i] = {v[i+1] - v[i], i};
      |      ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 1 ms 448 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 476 KB Output is correct
9 Correct 2 ms 448 KB Output is correct
10 Correct 1 ms 376 KB Output is correct
11 Correct 1 ms 368 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 1 ms 448 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 476 KB Output is correct
9 Correct 2 ms 448 KB Output is correct
10 Correct 1 ms 376 KB Output is correct
11 Correct 1 ms 368 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 27 ms 7088 KB Output is correct
21 Correct 25 ms 6836 KB Output is correct
22 Correct 36 ms 6692 KB Output is correct
23 Correct 33 ms 6696 KB Output is correct
24 Correct 32 ms 7720 KB Output is correct
25 Correct 98 ms 19724 KB Output is correct
26 Correct 104 ms 19664 KB Output is correct
27 Correct 100 ms 19276 KB Output is correct
28 Correct 104 ms 19404 KB Output is correct
29 Correct 102 ms 18884 KB Output is correct
30 Correct 95 ms 18368 KB Output is correct
31 Correct 102 ms 17756 KB Output is correct
32 Correct 62 ms 17868 KB Output is correct
33 Correct 11 ms 2252 KB Output is correct
34 Correct 97 ms 20008 KB Output is correct
35 Correct 105 ms 19496 KB Output is correct
36 Correct 100 ms 19652 KB Output is correct
37 Correct 121 ms 19352 KB Output is correct
38 Correct 98 ms 19260 KB Output is correct
39 Correct 100 ms 19520 KB Output is correct
40 Correct 115 ms 19524 KB Output is correct
41 Correct 29 ms 7716 KB Output is correct
42 Correct 86 ms 17856 KB Output is correct
43 Correct 89 ms 21200 KB Output is correct
44 Correct 31 ms 7592 KB Output is correct
45 Correct 102 ms 19396 KB Output is correct
46 Correct 91 ms 21336 KB Output is correct
47 Correct 89 ms 21572 KB Output is correct
48 Correct 103 ms 21564 KB Output is correct