Submission #569714

# Submission time Handle Problem Language Result Execution time Memory
569714 2022-05-27T16:11:05 Z SSRS Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
2990 ms 147572 KB
#include <bits/stdc++.h>
using namespace std;
const long long INF1 = 1000000000000;
const long long INF2 = 100000000000000;
struct lazy_segment_tree{
  int N;
  vector<long long> ST, lazy;
  lazy_segment_tree(vector<long long> &A){
    int N2 = A.size();
    N = 1;
    while (N < N2){
      N *= 2;
    }
    ST = vector<long long>(N * 2 - 1, -INF2);
    for (int i = 0; i < N2; i++){
      ST[N - 1 + i] = A[i];
    }
    for (int i = N - 2; i >= 0; i--){
      ST[i] = max(ST[i * 2 + 1], ST[i * 2 + 2]);
    }
    lazy = vector<long long>(N * 2 - 1, 0);
  }
  void eval(int i){
    if (lazy[i] != 0){
      if (i < N - 1){
        lazy[i * 2 + 1] += lazy[i];
        lazy[i * 2 + 2] += lazy[i];
      }
      ST[i] += lazy[i];
      lazy[i] = 0;
    }
  }
  void range_add(int L, int R, long long x, int i, int l, int r){
    eval(i);
    if (r <= L || R <= l){
    } else if (L <= l && r <= R){
      lazy[i] += x;
      eval(i);
    } else {
      int m = (l + r) / 2;
      range_add(L, R, x, i * 2 + 1, l, m);
      range_add(L, R, x, i * 2 + 2, m, r);
      ST[i] = max(ST[i * 2 + 1], ST[i * 2 + 2]);
    }
  }
  void range_add(int L, int R, long long x){
    range_add(L, R, x, 0, 0, N);
  }
  long long range_max(int L, int R, int i, int l, int r){
    eval(i);
    if (r <= L || R <= l){
      return -INF2;
    } else if (L <= l && r <= R){
      return ST[i];
    } else {
      int m = (l + r) / 2;
      return max(range_max(L, R, i * 2 + 1, l, m), range_max(L, R, i * 2 + 2, m, r));
    }
  }
  long long range_max(int L, int R){
    return range_max(L, R, 0, 0, N);
  }
};
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  vector<long long> w(N);
  for (int i = 0; i < N; i++){
    cin >> w[i];
  }
  vector<int> l(M), r(M);
  vector<long long> k(M);
  for (int i = 0; i < M; i++){
    cin >> l[i] >> r[i] >> k[i];
    l[i]--;
  }
  vector<vector<int>> query(N);
  for (int i = 0; i < M; i++){
    query[l[i]].push_back(i);
  }
  lazy_segment_tree ST(w);
  stack<int> st;
  st.push(N);
  vector<long long> mx(M, 0);
  for (int i = N - 1; i >= 0; i--){
    while (st.top() != N){
      int p = st.top();
      if (w[i] <= w[p]){
        break;
      }
      st.pop();
      int q = st.top();
      ST.range_add(p, p + 1, INF1);
      ST.range_add(p + 1, q, -w[p]);
    }
    int p = st.top();
    ST.range_add(i, i + 1, -INF1);
    ST.range_add(i + 1, p, w[i]);
    st.push(i);
    for (int j : query[i]){
      mx[j] = ST.range_max(i, r[j]);
    }
  }
  for (int i = 0; i < M; i++){
    if (mx[i] <= k[i]){
      cout << 1 << "\n";
    } else {
      cout << 0 << "\n";
    }
  }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 7 ms 852 KB Output is correct
13 Correct 9 ms 884 KB Output is correct
14 Correct 12 ms 852 KB Output is correct
15 Correct 9 ms 852 KB Output is correct
16 Correct 7 ms 852 KB Output is correct
17 Correct 5 ms 724 KB Output is correct
18 Correct 9 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2957 ms 107908 KB Output is correct
2 Correct 2990 ms 119976 KB Output is correct
3 Correct 2944 ms 119896 KB Output is correct
4 Correct 2850 ms 120032 KB Output is correct
5 Correct 2171 ms 124472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 215 ms 12096 KB Output is correct
2 Correct 182 ms 11044 KB Output is correct
3 Correct 166 ms 12148 KB Output is correct
4 Correct 143 ms 12408 KB Output is correct
5 Correct 137 ms 12412 KB Output is correct
6 Correct 117 ms 10956 KB Output is correct
7 Correct 142 ms 11004 KB Output is correct
8 Correct 165 ms 11540 KB Output is correct
9 Correct 44 ms 3344 KB Output is correct
10 Correct 176 ms 11532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 7 ms 852 KB Output is correct
13 Correct 9 ms 884 KB Output is correct
14 Correct 12 ms 852 KB Output is correct
15 Correct 9 ms 852 KB Output is correct
16 Correct 7 ms 852 KB Output is correct
17 Correct 5 ms 724 KB Output is correct
18 Correct 9 ms 852 KB Output is correct
19 Correct 516 ms 23852 KB Output is correct
20 Correct 515 ms 23856 KB Output is correct
21 Correct 396 ms 21528 KB Output is correct
22 Correct 412 ms 21520 KB Output is correct
23 Correct 395 ms 21512 KB Output is correct
24 Correct 279 ms 22192 KB Output is correct
25 Correct 267 ms 22200 KB Output is correct
26 Correct 328 ms 22948 KB Output is correct
27 Correct 326 ms 22972 KB Output is correct
28 Correct 337 ms 23480 KB Output is correct
29 Correct 423 ms 24600 KB Output is correct
30 Correct 407 ms 24600 KB Output is correct
31 Correct 364 ms 24596 KB Output is correct
32 Correct 367 ms 24600 KB Output is correct
33 Correct 389 ms 24528 KB Output is correct
34 Correct 258 ms 21768 KB Output is correct
35 Correct 282 ms 21744 KB Output is correct
36 Correct 295 ms 21736 KB Output is correct
37 Correct 298 ms 21780 KB Output is correct
38 Correct 271 ms 21708 KB Output is correct
39 Correct 351 ms 22824 KB Output is correct
40 Correct 243 ms 16208 KB Output is correct
41 Correct 337 ms 22768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 7 ms 852 KB Output is correct
13 Correct 9 ms 884 KB Output is correct
14 Correct 12 ms 852 KB Output is correct
15 Correct 9 ms 852 KB Output is correct
16 Correct 7 ms 852 KB Output is correct
17 Correct 5 ms 724 KB Output is correct
18 Correct 9 ms 852 KB Output is correct
19 Correct 2957 ms 107908 KB Output is correct
20 Correct 2990 ms 119976 KB Output is correct
21 Correct 2944 ms 119896 KB Output is correct
22 Correct 2850 ms 120032 KB Output is correct
23 Correct 2171 ms 124472 KB Output is correct
24 Correct 215 ms 12096 KB Output is correct
25 Correct 182 ms 11044 KB Output is correct
26 Correct 166 ms 12148 KB Output is correct
27 Correct 143 ms 12408 KB Output is correct
28 Correct 137 ms 12412 KB Output is correct
29 Correct 117 ms 10956 KB Output is correct
30 Correct 142 ms 11004 KB Output is correct
31 Correct 165 ms 11540 KB Output is correct
32 Correct 44 ms 3344 KB Output is correct
33 Correct 176 ms 11532 KB Output is correct
34 Correct 516 ms 23852 KB Output is correct
35 Correct 515 ms 23856 KB Output is correct
36 Correct 396 ms 21528 KB Output is correct
37 Correct 412 ms 21520 KB Output is correct
38 Correct 395 ms 21512 KB Output is correct
39 Correct 279 ms 22192 KB Output is correct
40 Correct 267 ms 22200 KB Output is correct
41 Correct 328 ms 22948 KB Output is correct
42 Correct 326 ms 22972 KB Output is correct
43 Correct 337 ms 23480 KB Output is correct
44 Correct 423 ms 24600 KB Output is correct
45 Correct 407 ms 24600 KB Output is correct
46 Correct 364 ms 24596 KB Output is correct
47 Correct 367 ms 24600 KB Output is correct
48 Correct 389 ms 24528 KB Output is correct
49 Correct 258 ms 21768 KB Output is correct
50 Correct 282 ms 21744 KB Output is correct
51 Correct 295 ms 21736 KB Output is correct
52 Correct 298 ms 21780 KB Output is correct
53 Correct 271 ms 21708 KB Output is correct
54 Correct 351 ms 22824 KB Output is correct
55 Correct 243 ms 16208 KB Output is correct
56 Correct 337 ms 22768 KB Output is correct
57 Correct 2982 ms 143352 KB Output is correct
58 Correct 2890 ms 143412 KB Output is correct
59 Correct 2652 ms 137788 KB Output is correct
60 Correct 2708 ms 137660 KB Output is correct
61 Correct 2428 ms 137676 KB Output is correct
62 Correct 2459 ms 137676 KB Output is correct
63 Correct 1395 ms 131372 KB Output is correct
64 Correct 1356 ms 131384 KB Output is correct
65 Correct 1768 ms 140956 KB Output is correct
66 Correct 1849 ms 141012 KB Output is correct
67 Correct 1789 ms 141540 KB Output is correct
68 Correct 1937 ms 147528 KB Output is correct
69 Correct 1941 ms 147572 KB Output is correct
70 Correct 1941 ms 146892 KB Output is correct
71 Correct 1961 ms 146572 KB Output is correct
72 Correct 1934 ms 146792 KB Output is correct
73 Correct 1289 ms 129220 KB Output is correct
74 Correct 1367 ms 130084 KB Output is correct
75 Correct 1376 ms 129144 KB Output is correct
76 Correct 1353 ms 129256 KB Output is correct
77 Correct 1369 ms 129180 KB Output is correct
78 Correct 1884 ms 132672 KB Output is correct
79 Correct 1160 ms 93196 KB Output is correct
80 Correct 2013 ms 129088 KB Output is correct