답안 #1092029

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1092029 2024-09-23T01:12:55 Z juicy Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
493 ms 63644 KB
#include <bits/stdc++.h>

using namespace std;

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

const int N = 1e6 + 5;

int n, m;
int a[N], s[N], res[N];

void upd(int i, int x) {
  for (; i; i -= i & -i) {
    s[i] = max(s[i], x);
  }
}

int qry(int i) {
  int res = 0;
  for (; i <= n; i += i & -i) {
    res = max(res, s[i]);
  }
  return res;
}

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

  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  vector<array<int, 4>> que;
  for (int i = 1; i <= m; ++i) {
    int l, r, k; cin >> l >> r >> k;
    que.push_back({r, l, k, i});
  }
  sort(que.begin(), que.end());
  vector<int> st;
  for (int i = 1, j = 0; i <= n; ++i) {
    while (st.size() && a[st.back()] <= a[i]) {
      st.pop_back();
    }
    if (st.size()) {
      upd(st.back(), a[st.back()] + a[i]);
    }
    st.push_back(i);
    while (j < m && que[j][0] == i) {
      res[que[j][3]] = qry(que[j][1]) <= que[j][2]; 
      ++j;
    }
  }
  for (int i = 1; i <= m; ++i) {
    cout << res[i] << "\n";
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 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 480 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 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 480 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 4 ms 848 KB Output is correct
15 Correct 2 ms 852 KB Output is correct
16 Correct 2 ms 856 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 3 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 474 ms 61600 KB Output is correct
2 Correct 482 ms 62628 KB Output is correct
3 Correct 477 ms 62552 KB Output is correct
4 Correct 480 ms 62620 KB Output is correct
5 Correct 465 ms 58820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 5452 KB Output is correct
2 Correct 43 ms 5320 KB Output is correct
3 Correct 40 ms 5076 KB Output is correct
4 Correct 38 ms 5068 KB Output is correct
5 Correct 39 ms 5052 KB Output is correct
6 Correct 41 ms 4808 KB Output is correct
7 Correct 40 ms 4820 KB Output is correct
8 Correct 38 ms 4816 KB Output is correct
9 Correct 30 ms 4044 KB Output is correct
10 Correct 37 ms 4868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 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 480 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 4 ms 848 KB Output is correct
15 Correct 2 ms 852 KB Output is correct
16 Correct 2 ms 856 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 3 ms 604 KB Output is correct
19 Correct 94 ms 12992 KB Output is correct
20 Correct 101 ms 12988 KB Output is correct
21 Correct 89 ms 12760 KB Output is correct
22 Correct 89 ms 12848 KB Output is correct
23 Correct 94 ms 12744 KB Output is correct
24 Correct 84 ms 11968 KB Output is correct
25 Correct 84 ms 11968 KB Output is correct
26 Correct 85 ms 11960 KB Output is correct
27 Correct 84 ms 11968 KB Output is correct
28 Correct 84 ms 11964 KB Output is correct
29 Correct 87 ms 12172 KB Output is correct
30 Correct 91 ms 12216 KB Output is correct
31 Correct 88 ms 12236 KB Output is correct
32 Correct 92 ms 12220 KB Output is correct
33 Correct 90 ms 12056 KB Output is correct
34 Correct 88 ms 11708 KB Output is correct
35 Correct 98 ms 11712 KB Output is correct
36 Correct 96 ms 11712 KB Output is correct
37 Correct 91 ms 11712 KB Output is correct
38 Correct 94 ms 11672 KB Output is correct
39 Correct 91 ms 11192 KB Output is correct
40 Correct 80 ms 9740 KB Output is correct
41 Correct 86 ms 10248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 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 480 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 4 ms 848 KB Output is correct
15 Correct 2 ms 852 KB Output is correct
16 Correct 2 ms 856 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 3 ms 604 KB Output is correct
19 Correct 474 ms 61600 KB Output is correct
20 Correct 482 ms 62628 KB Output is correct
21 Correct 477 ms 62552 KB Output is correct
22 Correct 480 ms 62620 KB Output is correct
23 Correct 465 ms 58820 KB Output is correct
24 Correct 41 ms 5452 KB Output is correct
25 Correct 43 ms 5320 KB Output is correct
26 Correct 40 ms 5076 KB Output is correct
27 Correct 38 ms 5068 KB Output is correct
28 Correct 39 ms 5052 KB Output is correct
29 Correct 41 ms 4808 KB Output is correct
30 Correct 40 ms 4820 KB Output is correct
31 Correct 38 ms 4816 KB Output is correct
32 Correct 30 ms 4044 KB Output is correct
33 Correct 37 ms 4868 KB Output is correct
34 Correct 94 ms 12992 KB Output is correct
35 Correct 101 ms 12988 KB Output is correct
36 Correct 89 ms 12760 KB Output is correct
37 Correct 89 ms 12848 KB Output is correct
38 Correct 94 ms 12744 KB Output is correct
39 Correct 84 ms 11968 KB Output is correct
40 Correct 84 ms 11968 KB Output is correct
41 Correct 85 ms 11960 KB Output is correct
42 Correct 84 ms 11968 KB Output is correct
43 Correct 84 ms 11964 KB Output is correct
44 Correct 87 ms 12172 KB Output is correct
45 Correct 91 ms 12216 KB Output is correct
46 Correct 88 ms 12236 KB Output is correct
47 Correct 92 ms 12220 KB Output is correct
48 Correct 90 ms 12056 KB Output is correct
49 Correct 88 ms 11708 KB Output is correct
50 Correct 98 ms 11712 KB Output is correct
51 Correct 96 ms 11712 KB Output is correct
52 Correct 91 ms 11712 KB Output is correct
53 Correct 94 ms 11672 KB Output is correct
54 Correct 91 ms 11192 KB Output is correct
55 Correct 80 ms 9740 KB Output is correct
56 Correct 86 ms 10248 KB Output is correct
57 Correct 484 ms 63388 KB Output is correct
58 Correct 485 ms 63644 KB Output is correct
59 Correct 493 ms 63396 KB Output is correct
60 Correct 492 ms 63388 KB Output is correct
61 Correct 492 ms 63176 KB Output is correct
62 Correct 462 ms 63392 KB Output is correct
63 Correct 449 ms 57504 KB Output is correct
64 Correct 463 ms 57624 KB Output is correct
65 Correct 450 ms 59324 KB Output is correct
66 Correct 450 ms 59280 KB Output is correct
67 Correct 465 ms 59296 KB Output is correct
68 Correct 459 ms 59540 KB Output is correct
69 Correct 459 ms 59552 KB Output is correct
70 Correct 466 ms 59400 KB Output is correct
71 Correct 486 ms 59316 KB Output is correct
72 Correct 451 ms 59576 KB Output is correct
73 Correct 469 ms 55964 KB Output is correct
74 Correct 475 ms 57124 KB Output is correct
75 Correct 465 ms 55968 KB Output is correct
76 Correct 459 ms 55968 KB Output is correct
77 Correct 471 ms 56080 KB Output is correct
78 Correct 436 ms 54688 KB Output is correct
79 Correct 383 ms 46752 KB Output is correct
80 Correct 439 ms 50676 KB Output is correct