답안 #346606

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
346606 2021-01-10T10:37:19 Z milleniumEeee Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1792 ms 63960 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = (int)1e6 + 6;

struct Query {
  int l, k, id;
  Query (int l_, int k_, int id_) {
    l = l_, k = k_, id = id_;
  }
  Query () {
    
  }
};

vector <Query> query[MAXN];
int a[MAXN];
int ans[MAXN];
int tree[MAXN * 4];

void upd(int pos, int val, int v = 1, int tl = 1, int tr = MAXN) {
  if (tl == tr) {
    tree[v] = max(tree[v], val);
    return;
  }
  int mid = (tl + tr) >> 1;
  if (pos <= mid) {
    upd(pos, val, v + v, tl, mid);
  } else {
    upd(pos, val, v + v + 1, mid + 1, tr);
  }
  tree[v] = max(tree[v + v], tree[v + v + 1]);
}

int get(int l, int r, int v = 1, int tl = 1, int tr = MAXN) {
  if (l <= tl && tr <= r) {
    return tree[v];
  }
  if (l > tr || tl > r) {
    return 0;
  }
  int mid = (tl + tr) >> 1;
  return max(get(l, r, v + v, tl, mid), get(l, r, v + v + 1, mid + 1, tr));
}

signed main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  int n, q;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  vector <Query> vec;
  for (int i = 1; i <= q; i++) {
    int l, r, k;
    cin >> l >> r >> k;
    query[r].push_back(Query(l, k, i));
  }
  vector <pair<int, int>> st;
  for (int r = 1; r <= n; r++) {
    while (!st.empty() && st.back().first < a[r]) {
      st.pop_back();
    }
    if (!st.empty() && st.back().first > a[r]) {
      upd(st.back().second, st.back().first + a[r]);
    }
    st.push_back({a[r], r});
    while (!query[r].empty()) {
      int l = query[r].back().l;
      int k = query[r].back().k;
      int id = query[r].back().id;
      query[r].pop_back();
      ans[id] = (get(l, r) <= k);
    }
  }
  for (int i = 1; i <= q; i++) {
    cout << ans[i] << "\n";
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23936 KB Output is correct
2 Correct 16 ms 23788 KB Output is correct
3 Correct 17 ms 23916 KB Output is correct
4 Correct 16 ms 23916 KB Output is correct
5 Correct 17 ms 23916 KB Output is correct
6 Correct 17 ms 23916 KB Output is correct
7 Correct 17 ms 23916 KB Output is correct
8 Correct 17 ms 23916 KB Output is correct
9 Correct 17 ms 23916 KB Output is correct
10 Correct 17 ms 23916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23936 KB Output is correct
2 Correct 16 ms 23788 KB Output is correct
3 Correct 17 ms 23916 KB Output is correct
4 Correct 16 ms 23916 KB Output is correct
5 Correct 17 ms 23916 KB Output is correct
6 Correct 17 ms 23916 KB Output is correct
7 Correct 17 ms 23916 KB Output is correct
8 Correct 17 ms 23916 KB Output is correct
9 Correct 17 ms 23916 KB Output is correct
10 Correct 17 ms 23916 KB Output is correct
11 Correct 19 ms 24044 KB Output is correct
12 Correct 21 ms 24044 KB Output is correct
13 Correct 20 ms 24044 KB Output is correct
14 Correct 22 ms 24044 KB Output is correct
15 Correct 22 ms 24044 KB Output is correct
16 Correct 21 ms 24044 KB Output is correct
17 Correct 21 ms 24044 KB Output is correct
18 Correct 21 ms 24172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1781 ms 63656 KB Output is correct
2 Correct 1792 ms 63960 KB Output is correct
3 Correct 1792 ms 63852 KB Output is correct
4 Correct 1784 ms 63896 KB Output is correct
5 Correct 1427 ms 55692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 141 ms 27756 KB Output is correct
2 Correct 134 ms 27560 KB Output is correct
3 Correct 119 ms 26860 KB Output is correct
4 Correct 122 ms 26912 KB Output is correct
5 Correct 119 ms 26988 KB Output is correct
6 Correct 99 ms 26604 KB Output is correct
7 Correct 98 ms 26732 KB Output is correct
8 Correct 109 ms 27684 KB Output is correct
9 Correct 75 ms 26020 KB Output is correct
10 Correct 109 ms 27812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23936 KB Output is correct
2 Correct 16 ms 23788 KB Output is correct
3 Correct 17 ms 23916 KB Output is correct
4 Correct 16 ms 23916 KB Output is correct
5 Correct 17 ms 23916 KB Output is correct
6 Correct 17 ms 23916 KB Output is correct
7 Correct 17 ms 23916 KB Output is correct
8 Correct 17 ms 23916 KB Output is correct
9 Correct 17 ms 23916 KB Output is correct
10 Correct 17 ms 23916 KB Output is correct
11 Correct 19 ms 24044 KB Output is correct
12 Correct 21 ms 24044 KB Output is correct
13 Correct 20 ms 24044 KB Output is correct
14 Correct 22 ms 24044 KB Output is correct
15 Correct 22 ms 24044 KB Output is correct
16 Correct 21 ms 24044 KB Output is correct
17 Correct 21 ms 24044 KB Output is correct
18 Correct 21 ms 24172 KB Output is correct
19 Correct 315 ms 31804 KB Output is correct
20 Correct 314 ms 31724 KB Output is correct
21 Correct 269 ms 31212 KB Output is correct
22 Correct 270 ms 31340 KB Output is correct
23 Correct 274 ms 31340 KB Output is correct
24 Correct 221 ms 29548 KB Output is correct
25 Correct 223 ms 29548 KB Output is correct
26 Correct 242 ms 29676 KB Output is correct
27 Correct 257 ms 29804 KB Output is correct
28 Correct 259 ms 29804 KB Output is correct
29 Correct 265 ms 30188 KB Output is correct
30 Correct 262 ms 30060 KB Output is correct
31 Correct 259 ms 30060 KB Output is correct
32 Correct 267 ms 30060 KB Output is correct
33 Correct 265 ms 30072 KB Output is correct
34 Correct 206 ms 29292 KB Output is correct
35 Correct 204 ms 29420 KB Output is correct
36 Correct 200 ms 29292 KB Output is correct
37 Correct 205 ms 29164 KB Output is correct
38 Correct 207 ms 29292 KB Output is correct
39 Correct 246 ms 30372 KB Output is correct
40 Correct 199 ms 29088 KB Output is correct
41 Correct 222 ms 31392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23936 KB Output is correct
2 Correct 16 ms 23788 KB Output is correct
3 Correct 17 ms 23916 KB Output is correct
4 Correct 16 ms 23916 KB Output is correct
5 Correct 17 ms 23916 KB Output is correct
6 Correct 17 ms 23916 KB Output is correct
7 Correct 17 ms 23916 KB Output is correct
8 Correct 17 ms 23916 KB Output is correct
9 Correct 17 ms 23916 KB Output is correct
10 Correct 17 ms 23916 KB Output is correct
11 Correct 19 ms 24044 KB Output is correct
12 Correct 21 ms 24044 KB Output is correct
13 Correct 20 ms 24044 KB Output is correct
14 Correct 22 ms 24044 KB Output is correct
15 Correct 22 ms 24044 KB Output is correct
16 Correct 21 ms 24044 KB Output is correct
17 Correct 21 ms 24044 KB Output is correct
18 Correct 21 ms 24172 KB Output is correct
19 Correct 1781 ms 63656 KB Output is correct
20 Correct 1792 ms 63960 KB Output is correct
21 Correct 1792 ms 63852 KB Output is correct
22 Correct 1784 ms 63896 KB Output is correct
23 Correct 1427 ms 55692 KB Output is correct
24 Correct 141 ms 27756 KB Output is correct
25 Correct 134 ms 27560 KB Output is correct
26 Correct 119 ms 26860 KB Output is correct
27 Correct 122 ms 26912 KB Output is correct
28 Correct 119 ms 26988 KB Output is correct
29 Correct 99 ms 26604 KB Output is correct
30 Correct 98 ms 26732 KB Output is correct
31 Correct 109 ms 27684 KB Output is correct
32 Correct 75 ms 26020 KB Output is correct
33 Correct 109 ms 27812 KB Output is correct
34 Correct 315 ms 31804 KB Output is correct
35 Correct 314 ms 31724 KB Output is correct
36 Correct 269 ms 31212 KB Output is correct
37 Correct 270 ms 31340 KB Output is correct
38 Correct 274 ms 31340 KB Output is correct
39 Correct 221 ms 29548 KB Output is correct
40 Correct 223 ms 29548 KB Output is correct
41 Correct 242 ms 29676 KB Output is correct
42 Correct 257 ms 29804 KB Output is correct
43 Correct 259 ms 29804 KB Output is correct
44 Correct 265 ms 30188 KB Output is correct
45 Correct 262 ms 30060 KB Output is correct
46 Correct 259 ms 30060 KB Output is correct
47 Correct 267 ms 30060 KB Output is correct
48 Correct 265 ms 30072 KB Output is correct
49 Correct 206 ms 29292 KB Output is correct
50 Correct 204 ms 29420 KB Output is correct
51 Correct 200 ms 29292 KB Output is correct
52 Correct 205 ms 29164 KB Output is correct
53 Correct 207 ms 29292 KB Output is correct
54 Correct 246 ms 30372 KB Output is correct
55 Correct 199 ms 29088 KB Output is correct
56 Correct 222 ms 31392 KB Output is correct
57 Correct 1770 ms 63280 KB Output is correct
58 Correct 1756 ms 63288 KB Output is correct
59 Correct 1688 ms 61908 KB Output is correct
60 Correct 1695 ms 61960 KB Output is correct
61 Correct 1709 ms 61840 KB Output is correct
62 Correct 1704 ms 61784 KB Output is correct
63 Correct 1139 ms 52200 KB Output is correct
64 Correct 1106 ms 52124 KB Output is correct
65 Correct 1383 ms 53612 KB Output is correct
66 Correct 1365 ms 53496 KB Output is correct
67 Correct 1385 ms 53548 KB Output is correct
68 Correct 1402 ms 55028 KB Output is correct
69 Correct 1406 ms 54988 KB Output is correct
70 Correct 1399 ms 54752 KB Output is correct
71 Correct 1461 ms 54864 KB Output is correct
72 Correct 1401 ms 54716 KB Output is correct
73 Correct 971 ms 49772 KB Output is correct
74 Correct 991 ms 49784 KB Output is correct
75 Correct 950 ms 49900 KB Output is correct
76 Correct 957 ms 50028 KB Output is correct
77 Correct 970 ms 49476 KB Output is correct
78 Correct 1301 ms 56184 KB Output is correct
79 Correct 987 ms 49384 KB Output is correct
80 Correct 1182 ms 61368 KB Output is correct