답안 #952353

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
952353 2024-03-23T15:36:03 Z ind1v Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++11
77 / 100
2584 ms 262148 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 5;
const int L = 20;

int n, m;
int rx[L][N];
int mx[L][N];
int mxr[L][N];

int rmx(int l, int r) {
  int w = __lg(r - l + 1);
  return max(mx[w][l], mx[w][r - (1 << w) + 1]);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> mx[0][i];
  }
  stack<int> st;
  for (int i = n; i >= 1; i--) {
    while (!st.empty() && mx[0][i] > mx[0][st.top()]) {
      st.pop();
    }
    rx[0][i] = (st.empty() ? n + 1 : st.top());
    st.push(i);
  }
  rx[0][n + 1] = n + 1;
  for (int j = 1; j < L; j++) {
    for (int i = 1; i <= n + 1; i++) {
      rx[j][i] = rx[j - 1][rx[j - 1][i]];
    }
    for (int i = 1; i + (1 << j) - 1 <= n; i++) {
      mx[j][i] = max(mx[j - 1][i], mx[j - 1][i + (1 << (j - 1))]);
    }
  }
  for (int i = 1; i <= n + 1; i++) {
    if (rx[0][i] > i + 1) {
      mxr[0][i] = mx[0][i] + rmx(i + 1, rx[0][i] - 1);
    }
  }
  for (int j = 1; j < L; j++) {
    for (int i = 1; i <= n + 1; i++) {
      mxr[j][i] = max(mxr[j - 1][i], mxr[j - 1][rx[j - 1][i]]);
    }
  }
  while (m--) {
    int l, r, k;
    cin >> l >> r >> k;
    bool f = true;
    for (int i = L - 1; i >= 0; i--) {
      if (rx[i][l] <= r) {
        f &= (mxr[i][l] <= k);
        l = rx[i][l];
      }
    }
    if (l < r) {
      f &= (mx[0][l] + rmx(l + 1, r) <= k);
    }
    cout << f << '\n';
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 86608 KB Output is correct
2 Correct 9 ms 82516 KB Output is correct
3 Correct 13 ms 96800 KB Output is correct
4 Correct 10 ms 92760 KB Output is correct
5 Correct 12 ms 96860 KB Output is correct
6 Correct 12 ms 98908 KB Output is correct
7 Correct 12 ms 98968 KB Output is correct
8 Correct 10 ms 98908 KB Output is correct
9 Correct 11 ms 98848 KB Output is correct
10 Correct 11 ms 98908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 86608 KB Output is correct
2 Correct 9 ms 82516 KB Output is correct
3 Correct 13 ms 96800 KB Output is correct
4 Correct 10 ms 92760 KB Output is correct
5 Correct 12 ms 96860 KB Output is correct
6 Correct 12 ms 98908 KB Output is correct
7 Correct 12 ms 98968 KB Output is correct
8 Correct 10 ms 98908 KB Output is correct
9 Correct 11 ms 98848 KB Output is correct
10 Correct 11 ms 98908 KB Output is correct
11 Correct 12 ms 103044 KB Output is correct
12 Correct 15 ms 107100 KB Output is correct
13 Correct 16 ms 107352 KB Output is correct
14 Correct 15 ms 107348 KB Output is correct
15 Correct 14 ms 107324 KB Output is correct
16 Correct 14 ms 107100 KB Output is correct
17 Correct 13 ms 107148 KB Output is correct
18 Correct 14 ms 107100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 899 ms 260456 KB Output is correct
2 Correct 935 ms 261804 KB Output is correct
3 Correct 865 ms 261416 KB Output is correct
4 Correct 856 ms 261716 KB Output is correct
5 Correct 2584 ms 262144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 141396 KB Output is correct
2 Correct 55 ms 141392 KB Output is correct
3 Correct 79 ms 139756 KB Output is correct
4 Correct 86 ms 139824 KB Output is correct
5 Correct 91 ms 139860 KB Output is correct
6 Correct 67 ms 141648 KB Output is correct
7 Correct 58 ms 141652 KB Output is correct
8 Correct 62 ms 141280 KB Output is correct
9 Correct 35 ms 101968 KB Output is correct
10 Correct 76 ms 141272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 86608 KB Output is correct
2 Correct 9 ms 82516 KB Output is correct
3 Correct 13 ms 96800 KB Output is correct
4 Correct 10 ms 92760 KB Output is correct
5 Correct 12 ms 96860 KB Output is correct
6 Correct 12 ms 98908 KB Output is correct
7 Correct 12 ms 98968 KB Output is correct
8 Correct 10 ms 98908 KB Output is correct
9 Correct 11 ms 98848 KB Output is correct
10 Correct 11 ms 98908 KB Output is correct
11 Correct 12 ms 103044 KB Output is correct
12 Correct 15 ms 107100 KB Output is correct
13 Correct 16 ms 107352 KB Output is correct
14 Correct 15 ms 107348 KB Output is correct
15 Correct 14 ms 107324 KB Output is correct
16 Correct 14 ms 107100 KB Output is correct
17 Correct 13 ms 107148 KB Output is correct
18 Correct 14 ms 107100 KB Output is correct
19 Correct 150 ms 168624 KB Output is correct
20 Correct 149 ms 168528 KB Output is correct
21 Correct 105 ms 168676 KB Output is correct
22 Correct 106 ms 168640 KB Output is correct
23 Correct 108 ms 168764 KB Output is correct
24 Correct 131 ms 166944 KB Output is correct
25 Correct 174 ms 167248 KB Output is correct
26 Correct 185 ms 167128 KB Output is correct
27 Correct 152 ms 167284 KB Output is correct
28 Correct 167 ms 167228 KB Output is correct
29 Correct 230 ms 167236 KB Output is correct
30 Correct 294 ms 167356 KB Output is correct
31 Correct 245 ms 167332 KB Output is correct
32 Correct 244 ms 167228 KB Output is correct
33 Correct 237 ms 167348 KB Output is correct
34 Correct 113 ms 169148 KB Output is correct
35 Correct 108 ms 169044 KB Output is correct
36 Correct 106 ms 169040 KB Output is correct
37 Correct 106 ms 169044 KB Output is correct
38 Correct 109 ms 168948 KB Output is correct
39 Correct 171 ms 168276 KB Output is correct
40 Correct 143 ms 149648 KB Output is correct
41 Correct 141 ms 167760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 86608 KB Output is correct
2 Correct 9 ms 82516 KB Output is correct
3 Correct 13 ms 96800 KB Output is correct
4 Correct 10 ms 92760 KB Output is correct
5 Correct 12 ms 96860 KB Output is correct
6 Correct 12 ms 98908 KB Output is correct
7 Correct 12 ms 98968 KB Output is correct
8 Correct 10 ms 98908 KB Output is correct
9 Correct 11 ms 98848 KB Output is correct
10 Correct 11 ms 98908 KB Output is correct
11 Correct 12 ms 103044 KB Output is correct
12 Correct 15 ms 107100 KB Output is correct
13 Correct 16 ms 107352 KB Output is correct
14 Correct 15 ms 107348 KB Output is correct
15 Correct 14 ms 107324 KB Output is correct
16 Correct 14 ms 107100 KB Output is correct
17 Correct 13 ms 107148 KB Output is correct
18 Correct 14 ms 107100 KB Output is correct
19 Correct 899 ms 260456 KB Output is correct
20 Correct 935 ms 261804 KB Output is correct
21 Correct 865 ms 261416 KB Output is correct
22 Correct 856 ms 261716 KB Output is correct
23 Correct 2584 ms 262144 KB Output is correct
24 Correct 68 ms 141396 KB Output is correct
25 Correct 55 ms 141392 KB Output is correct
26 Correct 79 ms 139756 KB Output is correct
27 Correct 86 ms 139824 KB Output is correct
28 Correct 91 ms 139860 KB Output is correct
29 Correct 67 ms 141648 KB Output is correct
30 Correct 58 ms 141652 KB Output is correct
31 Correct 62 ms 141280 KB Output is correct
32 Correct 35 ms 101968 KB Output is correct
33 Correct 76 ms 141272 KB Output is correct
34 Correct 150 ms 168624 KB Output is correct
35 Correct 149 ms 168528 KB Output is correct
36 Correct 105 ms 168676 KB Output is correct
37 Correct 106 ms 168640 KB Output is correct
38 Correct 108 ms 168764 KB Output is correct
39 Correct 131 ms 166944 KB Output is correct
40 Correct 174 ms 167248 KB Output is correct
41 Correct 185 ms 167128 KB Output is correct
42 Correct 152 ms 167284 KB Output is correct
43 Correct 167 ms 167228 KB Output is correct
44 Correct 230 ms 167236 KB Output is correct
45 Correct 294 ms 167356 KB Output is correct
46 Correct 245 ms 167332 KB Output is correct
47 Correct 244 ms 167228 KB Output is correct
48 Correct 237 ms 167348 KB Output is correct
49 Correct 113 ms 169148 KB Output is correct
50 Correct 108 ms 169044 KB Output is correct
51 Correct 106 ms 169040 KB Output is correct
52 Correct 106 ms 169044 KB Output is correct
53 Correct 109 ms 168948 KB Output is correct
54 Correct 171 ms 168276 KB Output is correct
55 Correct 143 ms 149648 KB Output is correct
56 Correct 141 ms 167760 KB Output is correct
57 Correct 950 ms 253648 KB Output is correct
58 Correct 914 ms 262144 KB Output is correct
59 Correct 824 ms 262144 KB Output is correct
60 Runtime error 948 ms 262148 KB Memory limit exceeded
61 Halted 0 ms 0 KB -