Submission #362373

# Submission time Handle Problem Language Result Execution time Memory
362373 2021-02-02T19:30:35 Z vkgainz Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1255 ms 97768 KB
#include <bits/stdc++.h>
using namespace std;
const int MX = 1e6 + 5;
#define f first
#define s second
int seg[2 * MX];
int n, m;
void upd(int i, int v) {
  i+=n;
  seg[i] = max(seg[i], v);
  while(i>1) {
    i/=2;
    seg[i] = max(seg[2*i], seg[2*i+1]);
  }
}
int query(int l, int r) {
  l+=n, r+=n;
  int ans = 0;
  while(l<r) {
    if(l%2) ans = max(ans, seg[l++]);
    if(r%2) ans = max(ans, seg[--r]);
    l/=2, r/=2;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m;
  vector<int> w(n);
  for(int i=0;i<n;i++) cin >> w[i];
  vector<pair<pair<int, int>, int>> queries[n];
  for(int i=0;i<m;i++) {
    int l, r, k; cin >> l >> r >> k;
    --l, --r;
    queries[l].push_back({{r, k}, i});
  }
  vector<int> in;
  vector<int> ans(m);
  for(int i=n-1;i>=0;i--) {
    while(in.size() && w[i] > w[in.back()]) {
      upd(in.back(), w[i] + w[in.back()]);
      in.pop_back();
    }
    in.push_back(i);
    for(auto &it : queries[i]) {
      ans[it.s] = query(i, it.f.f+1) <= it.f.s;
    }
  }
  for(auto &it : ans) cout << it << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
12 Correct 3 ms 748 KB Output is correct
13 Correct 4 ms 748 KB Output is correct
14 Correct 5 ms 876 KB Output is correct
15 Correct 4 ms 876 KB Output is correct
16 Correct 4 ms 768 KB Output is correct
17 Correct 4 ms 748 KB Output is correct
18 Correct 3 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1212 ms 63700 KB Output is correct
2 Correct 1211 ms 63756 KB Output is correct
3 Correct 1206 ms 63792 KB Output is correct
4 Correct 1200 ms 63840 KB Output is correct
5 Correct 1085 ms 59872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 7148 KB Output is correct
2 Correct 78 ms 8556 KB Output is correct
3 Correct 89 ms 8300 KB Output is correct
4 Correct 75 ms 8420 KB Output is correct
5 Correct 80 ms 8428 KB Output is correct
6 Correct 57 ms 7792 KB Output is correct
7 Correct 57 ms 7792 KB Output is correct
8 Correct 72 ms 8228 KB Output is correct
9 Correct 40 ms 3748 KB Output is correct
10 Correct 71 ms 8100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
12 Correct 3 ms 748 KB Output is correct
13 Correct 4 ms 748 KB Output is correct
14 Correct 5 ms 876 KB Output is correct
15 Correct 4 ms 876 KB Output is correct
16 Correct 4 ms 768 KB Output is correct
17 Correct 4 ms 748 KB Output is correct
18 Correct 3 ms 748 KB Output is correct
19 Correct 225 ms 19776 KB Output is correct
20 Correct 222 ms 19744 KB Output is correct
21 Correct 171 ms 19052 KB Output is correct
22 Correct 185 ms 19180 KB Output is correct
23 Correct 170 ms 19052 KB Output is correct
24 Correct 158 ms 18340 KB Output is correct
25 Correct 154 ms 18280 KB Output is correct
26 Correct 185 ms 18528 KB Output is correct
27 Correct 177 ms 18624 KB Output is correct
28 Correct 183 ms 18536 KB Output is correct
29 Correct 194 ms 19044 KB Output is correct
30 Correct 203 ms 19224 KB Output is correct
31 Correct 192 ms 19040 KB Output is correct
32 Correct 197 ms 19040 KB Output is correct
33 Correct 199 ms 18912 KB Output is correct
34 Correct 137 ms 17632 KB Output is correct
35 Correct 137 ms 17504 KB Output is correct
36 Correct 129 ms 17476 KB Output is correct
37 Correct 128 ms 17376 KB Output is correct
38 Correct 135 ms 17728 KB Output is correct
39 Correct 181 ms 17572 KB Output is correct
40 Correct 135 ms 14240 KB Output is correct
41 Correct 160 ms 17184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
12 Correct 3 ms 748 KB Output is correct
13 Correct 4 ms 748 KB Output is correct
14 Correct 5 ms 876 KB Output is correct
15 Correct 4 ms 876 KB Output is correct
16 Correct 4 ms 768 KB Output is correct
17 Correct 4 ms 748 KB Output is correct
18 Correct 3 ms 748 KB Output is correct
19 Correct 1212 ms 63700 KB Output is correct
20 Correct 1211 ms 63756 KB Output is correct
21 Correct 1206 ms 63792 KB Output is correct
22 Correct 1200 ms 63840 KB Output is correct
23 Correct 1085 ms 59872 KB Output is correct
24 Correct 83 ms 7148 KB Output is correct
25 Correct 78 ms 8556 KB Output is correct
26 Correct 89 ms 8300 KB Output is correct
27 Correct 75 ms 8420 KB Output is correct
28 Correct 80 ms 8428 KB Output is correct
29 Correct 57 ms 7792 KB Output is correct
30 Correct 57 ms 7792 KB Output is correct
31 Correct 72 ms 8228 KB Output is correct
32 Correct 40 ms 3748 KB Output is correct
33 Correct 71 ms 8100 KB Output is correct
34 Correct 225 ms 19776 KB Output is correct
35 Correct 222 ms 19744 KB Output is correct
36 Correct 171 ms 19052 KB Output is correct
37 Correct 185 ms 19180 KB Output is correct
38 Correct 170 ms 19052 KB Output is correct
39 Correct 158 ms 18340 KB Output is correct
40 Correct 154 ms 18280 KB Output is correct
41 Correct 185 ms 18528 KB Output is correct
42 Correct 177 ms 18624 KB Output is correct
43 Correct 183 ms 18536 KB Output is correct
44 Correct 194 ms 19044 KB Output is correct
45 Correct 203 ms 19224 KB Output is correct
46 Correct 192 ms 19040 KB Output is correct
47 Correct 197 ms 19040 KB Output is correct
48 Correct 199 ms 18912 KB Output is correct
49 Correct 137 ms 17632 KB Output is correct
50 Correct 137 ms 17504 KB Output is correct
51 Correct 129 ms 17476 KB Output is correct
52 Correct 128 ms 17376 KB Output is correct
53 Correct 135 ms 17728 KB Output is correct
54 Correct 181 ms 17572 KB Output is correct
55 Correct 135 ms 14240 KB Output is correct
56 Correct 160 ms 17184 KB Output is correct
57 Correct 1255 ms 97768 KB Output is correct
58 Correct 1238 ms 85584 KB Output is correct
59 Correct 1181 ms 95464 KB Output is correct
60 Correct 1233 ms 77528 KB Output is correct
61 Correct 1184 ms 95520 KB Output is correct
62 Correct 1162 ms 83948 KB Output is correct
63 Correct 741 ms 86100 KB Output is correct
64 Correct 744 ms 86104 KB Output is correct
65 Correct 1069 ms 91856 KB Output is correct
66 Correct 1102 ms 91652 KB Output is correct
67 Correct 1045 ms 74712 KB Output is correct
68 Correct 1094 ms 93816 KB Output is correct
69 Correct 1100 ms 93912 KB Output is correct
70 Correct 1105 ms 93576 KB Output is correct
71 Correct 1090 ms 93400 KB Output is correct
72 Correct 1097 ms 93396 KB Output is correct
73 Correct 647 ms 83860 KB Output is correct
74 Correct 674 ms 84484 KB Output is correct
75 Correct 630 ms 66436 KB Output is correct
76 Correct 656 ms 83556 KB Output is correct
77 Correct 654 ms 83720 KB Output is correct
78 Correct 944 ms 87096 KB Output is correct
79 Correct 718 ms 64512 KB Output is correct
80 Correct 968 ms 86376 KB Output is correct