답안 #989749

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
989749 2024-05-28T17:35:40 Z tch1cherin Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
656 ms 70016 KB
#include <bits/stdc++.h>
using namespace std;
 
const int MAX_N = 1000000;
int W[MAX_N], L[MAX_N], R[MAX_N], K[MAX_N], W_val[MAX_N], W_max[MAX_N], W_pref[MAX_N];
bool answer[MAX_N];
 
void divide(vector<int>& queries, int left, int right) {
  if (right - left == 1) {
    for (int i : queries) {
      answer[i] = true;
    }
    vector<int>().swap(queries);
    return; 
  }
  int mid = (left + right) / 2;
  vector<int> q_left, q_mid, q_right;
  for (int i : queries) {
    if (R[i] < mid) {
      q_left.push_back(i);
    } else if (L[i] >= mid) {
      q_right.push_back(i);
    } else {
      q_mid.push_back(i);
    }
  }
  vector<int>().swap(queries);
  divide(q_left, left, mid);
  divide(q_right, mid, right);
  int current = -1e9, current_inv = 0;
  vector<int> stk;
  for (int i = mid - 1; i >= left; i--) {
    while (!stk.empty() && W[i] > W[stk.back()]) {
      current_inv = max(current_inv, W[i] + W[stk.back()]);
      stk.pop_back();
    }
    stk.push_back(i);
    W_val[i] = current_inv;
    W_max[i] = W[stk[0]];
  }
  current = -1e9, current_inv = 0;
  for (int i = mid; i < right; i++) {
    if (W[i] >= current) {
      current = W[i];
    } else {
      current_inv = max(current_inv, current + W[i]);
    }
    W_val[i] = current_inv;
    W_max[i] = current;
  }
  for (int i = mid - 1, j = mid; i >= left; i--) {
    while (j < right && W[j] < W[i]) {
      j++;
    }
    W_pref[i] = j;
  }
  for (int i = mid, j = 0; i < right; i++) {
    while (j < (int)q_mid.size() && R[q_mid[j]] == i) {
      int min_k = max({W_val[i], W_val[L[q_mid[j]]], W[mid] >= W_max[L[q_mid[j]]] ? 0 : W_max[min(W_pref[L[q_mid[j]]] - 1, i)] + W_max[L[q_mid[j]]]});
      answer[q_mid[j]] = min_k <= K[q_mid[j]];
      j++;
    }
  }
}
 
int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> W[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> L[i] >> R[i] >> K[i];
    L[i]--, R[i]--;
  }
  vector<int> queries(M);
  iota(queries.begin(), queries.end(), 0);
  sort(queries.begin(), queries.end(), [](int x, int y) { return R[x] < R[y]; });
  divide(queries, 0, N);
  for (int i = 0; i < M; i++) {
    cout << (int)answer[i] << "\n";
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 2 ms 2652 KB Output is correct
13 Correct 2 ms 2648 KB Output is correct
14 Correct 3 ms 2652 KB Output is correct
15 Correct 3 ms 2652 KB Output is correct
16 Correct 2 ms 2652 KB Output is correct
17 Correct 2 ms 2652 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 651 ms 33256 KB Output is correct
2 Correct 604 ms 33268 KB Output is correct
3 Correct 582 ms 33272 KB Output is correct
4 Correct 614 ms 33272 KB Output is correct
5 Correct 535 ms 35312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 5640 KB Output is correct
2 Correct 47 ms 6060 KB Output is correct
3 Correct 48 ms 7672 KB Output is correct
4 Correct 43 ms 7588 KB Output is correct
5 Correct 44 ms 7588 KB Output is correct
6 Correct 40 ms 7532 KB Output is correct
7 Correct 38 ms 7496 KB Output is correct
8 Correct 39 ms 7236 KB Output is correct
9 Correct 23 ms 6096 KB Output is correct
10 Correct 40 ms 7492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 2 ms 2652 KB Output is correct
13 Correct 2 ms 2648 KB Output is correct
14 Correct 3 ms 2652 KB Output is correct
15 Correct 3 ms 2652 KB Output is correct
16 Correct 2 ms 2652 KB Output is correct
17 Correct 2 ms 2652 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 111 ms 11332 KB Output is correct
20 Correct 113 ms 15640 KB Output is correct
21 Correct 105 ms 15076 KB Output is correct
22 Correct 104 ms 15136 KB Output is correct
23 Correct 105 ms 15024 KB Output is correct
24 Correct 91 ms 15780 KB Output is correct
25 Correct 90 ms 15864 KB Output is correct
26 Correct 96 ms 15876 KB Output is correct
27 Correct 95 ms 16060 KB Output is correct
28 Correct 96 ms 16060 KB Output is correct
29 Correct 102 ms 15752 KB Output is correct
30 Correct 109 ms 15720 KB Output is correct
31 Correct 111 ms 15880 KB Output is correct
32 Correct 99 ms 15716 KB Output is correct
33 Correct 103 ms 15724 KB Output is correct
34 Correct 93 ms 15544 KB Output is correct
35 Correct 88 ms 15776 KB Output is correct
36 Correct 89 ms 15564 KB Output is correct
37 Correct 89 ms 15776 KB Output is correct
38 Correct 91 ms 15552 KB Output is correct
39 Correct 92 ms 14260 KB Output is correct
40 Correct 86 ms 12404 KB Output is correct
41 Correct 86 ms 14012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 2 ms 2652 KB Output is correct
13 Correct 2 ms 2648 KB Output is correct
14 Correct 3 ms 2652 KB Output is correct
15 Correct 3 ms 2652 KB Output is correct
16 Correct 2 ms 2652 KB Output is correct
17 Correct 2 ms 2652 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 651 ms 33256 KB Output is correct
20 Correct 604 ms 33268 KB Output is correct
21 Correct 582 ms 33272 KB Output is correct
22 Correct 614 ms 33272 KB Output is correct
23 Correct 535 ms 35312 KB Output is correct
24 Correct 48 ms 5640 KB Output is correct
25 Correct 47 ms 6060 KB Output is correct
26 Correct 48 ms 7672 KB Output is correct
27 Correct 43 ms 7588 KB Output is correct
28 Correct 44 ms 7588 KB Output is correct
29 Correct 40 ms 7532 KB Output is correct
30 Correct 38 ms 7496 KB Output is correct
31 Correct 39 ms 7236 KB Output is correct
32 Correct 23 ms 6096 KB Output is correct
33 Correct 40 ms 7492 KB Output is correct
34 Correct 111 ms 11332 KB Output is correct
35 Correct 113 ms 15640 KB Output is correct
36 Correct 105 ms 15076 KB Output is correct
37 Correct 104 ms 15136 KB Output is correct
38 Correct 105 ms 15024 KB Output is correct
39 Correct 91 ms 15780 KB Output is correct
40 Correct 90 ms 15864 KB Output is correct
41 Correct 96 ms 15876 KB Output is correct
42 Correct 95 ms 16060 KB Output is correct
43 Correct 96 ms 16060 KB Output is correct
44 Correct 102 ms 15752 KB Output is correct
45 Correct 109 ms 15720 KB Output is correct
46 Correct 111 ms 15880 KB Output is correct
47 Correct 99 ms 15716 KB Output is correct
48 Correct 103 ms 15724 KB Output is correct
49 Correct 93 ms 15544 KB Output is correct
50 Correct 88 ms 15776 KB Output is correct
51 Correct 89 ms 15564 KB Output is correct
52 Correct 89 ms 15776 KB Output is correct
53 Correct 91 ms 15552 KB Output is correct
54 Correct 92 ms 14260 KB Output is correct
55 Correct 86 ms 12404 KB Output is correct
56 Correct 86 ms 14012 KB Output is correct
57 Correct 612 ms 68496 KB Output is correct
58 Correct 656 ms 68496 KB Output is correct
59 Correct 611 ms 66524 KB Output is correct
60 Correct 586 ms 66504 KB Output is correct
61 Correct 596 ms 66564 KB Output is correct
62 Correct 583 ms 66368 KB Output is correct
63 Correct 471 ms 68268 KB Output is correct
64 Correct 482 ms 68212 KB Output is correct
65 Correct 521 ms 69976 KB Output is correct
66 Correct 506 ms 70016 KB Output is correct
67 Correct 514 ms 69920 KB Output is correct
68 Correct 507 ms 68904 KB Output is correct
69 Correct 521 ms 68820 KB Output is correct
70 Correct 522 ms 68228 KB Output is correct
71 Correct 517 ms 68272 KB Output is correct
72 Correct 514 ms 68480 KB Output is correct
73 Correct 416 ms 66676 KB Output is correct
74 Correct 441 ms 67700 KB Output is correct
75 Correct 451 ms 66932 KB Output is correct
76 Correct 460 ms 66676 KB Output is correct
77 Correct 434 ms 66672 KB Output is correct
78 Correct 502 ms 63044 KB Output is correct
79 Correct 351 ms 49056 KB Output is correct
80 Correct 458 ms 59924 KB Output is correct