Submission #431415

# Submission time Handle Problem Language Result Execution time Memory
431415 2021-06-17T11:48:33 Z MilosMilutinovic Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
2779 ms 96580 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 5;
const int M = 4 * N;

int a[N], st[M];
vector<tuple<int, int, int>> qq[N];

void modify(int node, int l, int r, int pos, int val) {
  if (l == r) {
    st[node] = max(st[node], val);
    return;
  }
  int mid = l + r >> 1;
  if (pos <= mid) modify(node * 2, l, mid, pos, val);
  else modify(node * 2 + 1, mid + 1, r, pos, val);
  st[node] = max(st[node * 2], st[node * 2 + 1]);
}

int get(int node, int l, int r, int ll, int rr) {
  if (l > r || l > rr || r < ll) return 0;
  if (ll <= l && r <= rr) return st[node];
  int mid = l + r >> 1;
  return max(get(node * 2, l, mid, ll, rr), get(node * 2 + 1, mid + 1, r, ll, rr));
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < q; i++) {
    int l, r, v;
    cin >> l >> r >> v;
    --l, --r;
    qq[r].push_back({l, v, i});
  }
  stack<int> s;
  vector<int> ans(q);
  for (int i = 0; i < n; i++) {
    while (!s.empty() && a[s.top()] <= a[i]) {
      s.pop();
    }
    if (!s.empty()) {
      modify(1, 0, n - 1, s.top(), a[s.top()] + a[i]);
    }
    for (auto& p : qq[i]) {
      if (get(1, 0, n - 1, get<0>(p), i) <= get<1>(p)) {
        ans[get<2>(p)] = 1;
      }
    }
    s.push(i);
  }
  for (int i = 0; i < q; i++) {
    cout << ans[i] << '\n';
  }
  return 0;
}

Compilation message

sortbooks.cpp: In function 'void modify(int, int, int, int, int)':
sortbooks.cpp:16:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   16 |   int mid = l + r >> 1;
      |             ~~^~~
sortbooks.cpp: In function 'int get(int, int, int, int, int)':
sortbooks.cpp:25:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   25 |   int mid = l + r >> 1;
      |             ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23780 KB Output is correct
2 Correct 17 ms 23800 KB Output is correct
3 Correct 18 ms 23756 KB Output is correct
4 Correct 15 ms 23708 KB Output is correct
5 Correct 16 ms 23808 KB Output is correct
6 Correct 16 ms 23812 KB Output is correct
7 Correct 18 ms 23756 KB Output is correct
8 Correct 17 ms 23768 KB Output is correct
9 Correct 17 ms 23832 KB Output is correct
10 Correct 16 ms 23736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23780 KB Output is correct
2 Correct 17 ms 23800 KB Output is correct
3 Correct 18 ms 23756 KB Output is correct
4 Correct 15 ms 23708 KB Output is correct
5 Correct 16 ms 23808 KB Output is correct
6 Correct 16 ms 23812 KB Output is correct
7 Correct 18 ms 23756 KB Output is correct
8 Correct 17 ms 23768 KB Output is correct
9 Correct 17 ms 23832 KB Output is correct
10 Correct 16 ms 23736 KB Output is correct
11 Correct 19 ms 23940 KB Output is correct
12 Correct 18 ms 24064 KB Output is correct
13 Correct 22 ms 24068 KB Output is correct
14 Correct 27 ms 24036 KB Output is correct
15 Correct 20 ms 24068 KB Output is correct
16 Correct 20 ms 24092 KB Output is correct
17 Correct 23 ms 24048 KB Output is correct
18 Correct 20 ms 24068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1920 ms 95412 KB Output is correct
2 Correct 1870 ms 96476 KB Output is correct
3 Correct 1878 ms 96268 KB Output is correct
4 Correct 1945 ms 96416 KB Output is correct
5 Correct 1676 ms 88272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 148 ms 29876 KB Output is correct
2 Correct 149 ms 29572 KB Output is correct
3 Correct 144 ms 28732 KB Output is correct
4 Correct 150 ms 28792 KB Output is correct
5 Correct 141 ms 28824 KB Output is correct
6 Correct 106 ms 28300 KB Output is correct
7 Correct 107 ms 28348 KB Output is correct
8 Correct 125 ms 28436 KB Output is correct
9 Correct 73 ms 27188 KB Output is correct
10 Correct 139 ms 28344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23780 KB Output is correct
2 Correct 17 ms 23800 KB Output is correct
3 Correct 18 ms 23756 KB Output is correct
4 Correct 15 ms 23708 KB Output is correct
5 Correct 16 ms 23808 KB Output is correct
6 Correct 16 ms 23812 KB Output is correct
7 Correct 18 ms 23756 KB Output is correct
8 Correct 17 ms 23768 KB Output is correct
9 Correct 17 ms 23832 KB Output is correct
10 Correct 16 ms 23736 KB Output is correct
11 Correct 19 ms 23940 KB Output is correct
12 Correct 18 ms 24064 KB Output is correct
13 Correct 22 ms 24068 KB Output is correct
14 Correct 27 ms 24036 KB Output is correct
15 Correct 20 ms 24068 KB Output is correct
16 Correct 20 ms 24092 KB Output is correct
17 Correct 23 ms 24048 KB Output is correct
18 Correct 20 ms 24068 KB Output is correct
19 Correct 368 ms 38600 KB Output is correct
20 Correct 421 ms 38640 KB Output is correct
21 Correct 321 ms 37904 KB Output is correct
22 Correct 304 ms 37956 KB Output is correct
23 Correct 288 ms 37972 KB Output is correct
24 Correct 320 ms 35764 KB Output is correct
25 Correct 339 ms 35788 KB Output is correct
26 Correct 304 ms 36152 KB Output is correct
27 Correct 330 ms 36152 KB Output is correct
28 Correct 352 ms 36224 KB Output is correct
29 Correct 333 ms 36524 KB Output is correct
30 Correct 333 ms 36552 KB Output is correct
31 Correct 303 ms 36472 KB Output is correct
32 Correct 318 ms 36584 KB Output is correct
33 Correct 333 ms 36580 KB Output is correct
34 Correct 211 ms 35400 KB Output is correct
35 Correct 218 ms 35372 KB Output is correct
36 Correct 235 ms 35212 KB Output is correct
37 Correct 202 ms 35156 KB Output is correct
38 Correct 218 ms 35312 KB Output is correct
39 Correct 289 ms 35488 KB Output is correct
40 Correct 242 ms 33564 KB Output is correct
41 Correct 289 ms 34340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23780 KB Output is correct
2 Correct 17 ms 23800 KB Output is correct
3 Correct 18 ms 23756 KB Output is correct
4 Correct 15 ms 23708 KB Output is correct
5 Correct 16 ms 23808 KB Output is correct
6 Correct 16 ms 23812 KB Output is correct
7 Correct 18 ms 23756 KB Output is correct
8 Correct 17 ms 23768 KB Output is correct
9 Correct 17 ms 23832 KB Output is correct
10 Correct 16 ms 23736 KB Output is correct
11 Correct 19 ms 23940 KB Output is correct
12 Correct 18 ms 24064 KB Output is correct
13 Correct 22 ms 24068 KB Output is correct
14 Correct 27 ms 24036 KB Output is correct
15 Correct 20 ms 24068 KB Output is correct
16 Correct 20 ms 24092 KB Output is correct
17 Correct 23 ms 24048 KB Output is correct
18 Correct 20 ms 24068 KB Output is correct
19 Correct 1920 ms 95412 KB Output is correct
20 Correct 1870 ms 96476 KB Output is correct
21 Correct 1878 ms 96268 KB Output is correct
22 Correct 1945 ms 96416 KB Output is correct
23 Correct 1676 ms 88272 KB Output is correct
24 Correct 148 ms 29876 KB Output is correct
25 Correct 149 ms 29572 KB Output is correct
26 Correct 144 ms 28732 KB Output is correct
27 Correct 150 ms 28792 KB Output is correct
28 Correct 141 ms 28824 KB Output is correct
29 Correct 106 ms 28300 KB Output is correct
30 Correct 107 ms 28348 KB Output is correct
31 Correct 125 ms 28436 KB Output is correct
32 Correct 73 ms 27188 KB Output is correct
33 Correct 139 ms 28344 KB Output is correct
34 Correct 368 ms 38600 KB Output is correct
35 Correct 421 ms 38640 KB Output is correct
36 Correct 321 ms 37904 KB Output is correct
37 Correct 304 ms 37956 KB Output is correct
38 Correct 288 ms 37972 KB Output is correct
39 Correct 320 ms 35764 KB Output is correct
40 Correct 339 ms 35788 KB Output is correct
41 Correct 304 ms 36152 KB Output is correct
42 Correct 330 ms 36152 KB Output is correct
43 Correct 352 ms 36224 KB Output is correct
44 Correct 333 ms 36524 KB Output is correct
45 Correct 333 ms 36552 KB Output is correct
46 Correct 303 ms 36472 KB Output is correct
47 Correct 318 ms 36584 KB Output is correct
48 Correct 333 ms 36580 KB Output is correct
49 Correct 211 ms 35400 KB Output is correct
50 Correct 218 ms 35372 KB Output is correct
51 Correct 235 ms 35212 KB Output is correct
52 Correct 202 ms 35156 KB Output is correct
53 Correct 218 ms 35312 KB Output is correct
54 Correct 289 ms 35488 KB Output is correct
55 Correct 242 ms 33564 KB Output is correct
56 Correct 289 ms 34340 KB Output is correct
57 Correct 2164 ms 96580 KB Output is correct
58 Correct 2115 ms 96560 KB Output is correct
59 Correct 2779 ms 95004 KB Output is correct
60 Correct 2017 ms 95016 KB Output is correct
61 Correct 1933 ms 95072 KB Output is correct
62 Correct 1861 ms 95000 KB Output is correct
63 Correct 1289 ms 83640 KB Output is correct
64 Correct 1266 ms 83544 KB Output is correct
65 Correct 1630 ms 86712 KB Output is correct
66 Correct 1613 ms 86748 KB Output is correct
67 Correct 1639 ms 86792 KB Output is correct
68 Correct 1669 ms 88424 KB Output is correct
69 Correct 1646 ms 88380 KB Output is correct
70 Correct 1645 ms 88076 KB Output is correct
71 Correct 1684 ms 88072 KB Output is correct
72 Correct 1670 ms 88160 KB Output is correct
73 Correct 1140 ms 79472 KB Output is correct
74 Correct 1134 ms 80504 KB Output is correct
75 Correct 1082 ms 79592 KB Output is correct
76 Correct 1180 ms 79852 KB Output is correct
77 Correct 1164 ms 79408 KB Output is correct
78 Correct 1477 ms 83244 KB Output is correct
79 Correct 1145 ms 71564 KB Output is correct
80 Correct 1654 ms 77728 KB Output is correct