Submission #1034657

# Submission time Handle Problem Language Result Execution time Memory
1034657 2024-07-25T16:02:53 Z juicy Triple Jump (JOI19_jumps) C++17
100 / 100
642 ms 52548 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int N = 5e5 + 5;

int n, q;
int a[N], s[4 * N], mx[4 * N], lz[4 * N], res[N];

void bld(int id = 1, int l = 1, int r = n) {
  if (l == r) {
    mx[id] = a[l];
    return;
  }
  int md = (l + r) / 2;
  bld(id * 2, l, md);
  bld(id * 2 + 1, md + 1, r);
  mx[id] = max(mx[id * 2], mx[id * 2 + 1]);
}

void app(int id, int x) {
  s[id] = max(s[id], mx[id] + x);
  lz[id] = max(lz[id], x);
}

void psh(int id) {
  if (lz[id]) {
    app(id * 2, lz[id]);
    app(id * 2 + 1, lz[id]);
    lz[id] = 0;
  }
}

void upd(int u, int v, int x, int id = 1, int l = 1, int r = n) {
  if (u <= l && r <= v) {
    app(id, x);
    return;
  }
  psh(id);
  int md = (l + r) / 2;
  if (u <= md) {
    upd(u, v, x, id * 2, l, md);
  }
  if (md < v) {
    upd(u, v, x, id * 2 + 1, md + 1, r);
  }
  s[id] = max(s[id * 2], s[id * 2 + 1]);
}

int qry(int u, int v, int id = 1, int l = 1, int r = n) {
  if (u <= l && r <= v) {
    return s[id];
  }
  psh(id);
  int md = (l + r) / 2;
  if (v <= md) {
    return qry(u, v, id * 2, l, md);
  }
  if (md < u) {
    return qry(u, v, id * 2 + 1, md + 1, r);
  }
  return max(qry(u, v, id * 2, l, md), qry(u, v, id * 2 + 1, md + 1, r));
}

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

  cin >> n;
  vector<int> st;
  vector<array<int, 2>> cands;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    while (st.size() && a[st.back()] < a[i]) {
      st.pop_back();
    }
    if (st.size()) {
      cands.push_back({st.back(), i});
    }
    st.push_back(i);
  }  
  bld();
  st.clear();
  for (int i = n; i > 0; --i) {
    while (st.size() && a[st.back()] < a[i]) {
      st.pop_back();
    }
    if (st.size()) {
      cands.push_back({i, st.back()});
    }
    st.push_back(i);
  }
  cin >> q;
  vector<array<int, 3>> Queries;
  for (int i = 1; i <= q; ++i) {
    int l, r; cin >> l >> r;
    Queries.push_back({l, r, i});
  }
  sort(cands.rbegin(), cands.rend());
  sort(Queries.rbegin(), Queries.rend());
  int j = 0;
  for (auto [l, r, id] : Queries) {
    while (j < cands.size() && cands[j][0] >= l) {
      int c = 2 * cands[j][1] - cands[j][0];
      if (c <= n) {
        upd(c, n, a[cands[j][0]] + a[cands[j][1]]);
      }
      ++j;
    }
    res[id] = qry(l, r);
  }
  for (int i = 1; i <= q; ++i) {
    cout << res[i] << "\n";
  }
  return 0;
}

Compilation message

jumps.cpp: In function 'int main()':
jumps.cpp:108:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |     while (j < cands.size() && cands[j][0] >= l) {
      |            ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 201 ms 18552 KB Output is correct
12 Correct 211 ms 18436 KB Output is correct
13 Correct 193 ms 18404 KB Output is correct
14 Correct 229 ms 18512 KB Output is correct
15 Correct 202 ms 18432 KB Output is correct
16 Correct 209 ms 17840 KB Output is correct
17 Correct 197 ms 17652 KB Output is correct
18 Correct 206 ms 17648 KB Output is correct
19 Correct 230 ms 18304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 150 ms 12224 KB Output is correct
2 Correct 59 ms 12524 KB Output is correct
3 Correct 51 ms 11700 KB Output is correct
4 Correct 101 ms 12220 KB Output is correct
5 Correct 111 ms 12220 KB Output is correct
6 Correct 108 ms 11764 KB Output is correct
7 Correct 131 ms 11452 KB Output is correct
8 Correct 120 ms 11660 KB Output is correct
9 Correct 125 ms 11980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 201 ms 18552 KB Output is correct
12 Correct 211 ms 18436 KB Output is correct
13 Correct 193 ms 18404 KB Output is correct
14 Correct 229 ms 18512 KB Output is correct
15 Correct 202 ms 18432 KB Output is correct
16 Correct 209 ms 17840 KB Output is correct
17 Correct 197 ms 17652 KB Output is correct
18 Correct 206 ms 17648 KB Output is correct
19 Correct 230 ms 18304 KB Output is correct
20 Correct 150 ms 12224 KB Output is correct
21 Correct 59 ms 12524 KB Output is correct
22 Correct 51 ms 11700 KB Output is correct
23 Correct 101 ms 12220 KB Output is correct
24 Correct 111 ms 12220 KB Output is correct
25 Correct 108 ms 11764 KB Output is correct
26 Correct 131 ms 11452 KB Output is correct
27 Correct 120 ms 11660 KB Output is correct
28 Correct 125 ms 11980 KB Output is correct
29 Correct 608 ms 52456 KB Output is correct
30 Correct 451 ms 47920 KB Output is correct
31 Correct 455 ms 47320 KB Output is correct
32 Correct 642 ms 52400 KB Output is correct
33 Correct 580 ms 52408 KB Output is correct
34 Correct 570 ms 50104 KB Output is correct
35 Correct 580 ms 49772 KB Output is correct
36 Correct 564 ms 49936 KB Output is correct
37 Correct 566 ms 51376 KB Output is correct
38 Correct 540 ms 52516 KB Output is correct
39 Correct 477 ms 52436 KB Output is correct
40 Correct 555 ms 49056 KB Output is correct
41 Correct 500 ms 48732 KB Output is correct
42 Correct 509 ms 48612 KB Output is correct
43 Correct 488 ms 50296 KB Output is correct
44 Correct 524 ms 52408 KB Output is correct
45 Correct 584 ms 52504 KB Output is correct
46 Correct 546 ms 49324 KB Output is correct
47 Correct 556 ms 48956 KB Output is correct
48 Correct 542 ms 48816 KB Output is correct
49 Correct 534 ms 51044 KB Output is correct
50 Correct 578 ms 52548 KB Output is correct
51 Correct 568 ms 52408 KB Output is correct
52 Correct 558 ms 50328 KB Output is correct
53 Correct 577 ms 49584 KB Output is correct
54 Correct 560 ms 49648 KB Output is correct
55 Correct 545 ms 51504 KB Output is correct