답안 #952355

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
952355 2024-03-23T15:37:12 Z ind1v Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
2609 ms 257284 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 1;
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 9 ms 86620 KB Output is correct
2 Correct 9 ms 82524 KB Output is correct
3 Correct 10 ms 96860 KB Output is correct
4 Correct 10 ms 92764 KB Output is correct
5 Correct 10 ms 96860 KB Output is correct
6 Correct 11 ms 98908 KB Output is correct
7 Correct 11 ms 98908 KB Output is correct
8 Correct 11 ms 98908 KB Output is correct
9 Correct 11 ms 98872 KB Output is correct
10 Correct 11 ms 98908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 86620 KB Output is correct
2 Correct 9 ms 82524 KB Output is correct
3 Correct 10 ms 96860 KB Output is correct
4 Correct 10 ms 92764 KB Output is correct
5 Correct 10 ms 96860 KB Output is correct
6 Correct 11 ms 98908 KB Output is correct
7 Correct 11 ms 98908 KB Output is correct
8 Correct 11 ms 98908 KB Output is correct
9 Correct 11 ms 98872 KB Output is correct
10 Correct 11 ms 98908 KB Output is correct
11 Correct 13 ms 103004 KB Output is correct
12 Correct 13 ms 107236 KB Output is correct
13 Correct 14 ms 107100 KB Output is correct
14 Correct 14 ms 107096 KB Output is correct
15 Correct 16 ms 107108 KB Output is correct
16 Correct 14 ms 107100 KB Output is correct
17 Correct 14 ms 107096 KB Output is correct
18 Correct 14 ms 107224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 941 ms 253512 KB Output is correct
2 Correct 878 ms 254192 KB Output is correct
3 Correct 854 ms 253988 KB Output is correct
4 Correct 899 ms 254104 KB Output is correct
5 Incorrect 2609 ms 257284 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 141528 KB Output is correct
2 Correct 55 ms 141588 KB Output is correct
3 Correct 80 ms 139628 KB Output is correct
4 Correct 99 ms 139620 KB Output is correct
5 Correct 78 ms 139600 KB Output is correct
6 Correct 58 ms 141816 KB Output is correct
7 Correct 70 ms 141740 KB Output is correct
8 Correct 64 ms 141648 KB Output is correct
9 Correct 35 ms 102160 KB Output is correct
10 Correct 73 ms 141648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 86620 KB Output is correct
2 Correct 9 ms 82524 KB Output is correct
3 Correct 10 ms 96860 KB Output is correct
4 Correct 10 ms 92764 KB Output is correct
5 Correct 10 ms 96860 KB Output is correct
6 Correct 11 ms 98908 KB Output is correct
7 Correct 11 ms 98908 KB Output is correct
8 Correct 11 ms 98908 KB Output is correct
9 Correct 11 ms 98872 KB Output is correct
10 Correct 11 ms 98908 KB Output is correct
11 Correct 13 ms 103004 KB Output is correct
12 Correct 13 ms 107236 KB Output is correct
13 Correct 14 ms 107100 KB Output is correct
14 Correct 14 ms 107096 KB Output is correct
15 Correct 16 ms 107108 KB Output is correct
16 Correct 14 ms 107100 KB Output is correct
17 Correct 14 ms 107096 KB Output is correct
18 Correct 14 ms 107224 KB Output is correct
19 Correct 169 ms 169200 KB Output is correct
20 Correct 145 ms 168788 KB Output is correct
21 Correct 107 ms 168980 KB Output is correct
22 Correct 116 ms 168812 KB Output is correct
23 Correct 109 ms 168948 KB Output is correct
24 Correct 131 ms 167252 KB Output is correct
25 Correct 138 ms 167252 KB Output is correct
26 Correct 147 ms 167508 KB Output is correct
27 Correct 163 ms 167408 KB Output is correct
28 Correct 181 ms 167504 KB Output is correct
29 Correct 268 ms 167556 KB Output is correct
30 Correct 255 ms 167488 KB Output is correct
31 Correct 249 ms 167592 KB Output is correct
32 Correct 247 ms 167432 KB Output is correct
33 Correct 253 ms 167716 KB Output is correct
34 Correct 107 ms 169296 KB Output is correct
35 Correct 109 ms 169272 KB Output is correct
36 Correct 108 ms 168924 KB Output is correct
37 Correct 121 ms 169136 KB Output is correct
38 Correct 110 ms 169268 KB Output is correct
39 Correct 182 ms 168592 KB Output is correct
40 Correct 147 ms 149736 KB Output is correct
41 Correct 139 ms 168016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 86620 KB Output is correct
2 Correct 9 ms 82524 KB Output is correct
3 Correct 10 ms 96860 KB Output is correct
4 Correct 10 ms 92764 KB Output is correct
5 Correct 10 ms 96860 KB Output is correct
6 Correct 11 ms 98908 KB Output is correct
7 Correct 11 ms 98908 KB Output is correct
8 Correct 11 ms 98908 KB Output is correct
9 Correct 11 ms 98872 KB Output is correct
10 Correct 11 ms 98908 KB Output is correct
11 Correct 13 ms 103004 KB Output is correct
12 Correct 13 ms 107236 KB Output is correct
13 Correct 14 ms 107100 KB Output is correct
14 Correct 14 ms 107096 KB Output is correct
15 Correct 16 ms 107108 KB Output is correct
16 Correct 14 ms 107100 KB Output is correct
17 Correct 14 ms 107096 KB Output is correct
18 Correct 14 ms 107224 KB Output is correct
19 Correct 941 ms 253512 KB Output is correct
20 Correct 878 ms 254192 KB Output is correct
21 Correct 854 ms 253988 KB Output is correct
22 Correct 899 ms 254104 KB Output is correct
23 Incorrect 2609 ms 257284 KB Output isn't correct
24 Halted 0 ms 0 KB -