답안 #569706

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
569706 2022-05-27T16:07:18 Z SSRS Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
64 / 100
3000 ms 107816 KB
#include <bits/stdc++.h>
using namespace std;
const long long INF1 = 1000000000000;
const long long INF2 = 100000000000000;
//RAQ+RMQ
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 (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";
    }
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 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 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 372 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 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 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 372 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 4 ms 468 KB Output is correct
12 Correct 9 ms 876 KB Output is correct
13 Correct 9 ms 852 KB Output is correct
14 Correct 10 ms 852 KB Output is correct
15 Correct 9 ms 956 KB Output is correct
16 Correct 8 ms 852 KB Output is correct
17 Correct 5 ms 784 KB Output is correct
18 Correct 8 ms 952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3042 ms 107816 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 250 ms 12024 KB Output is correct
2 Correct 213 ms 11044 KB Output is correct
3 Correct 160 ms 12108 KB Output is correct
4 Correct 160 ms 12300 KB Output is correct
5 Correct 161 ms 12512 KB Output is correct
6 Correct 154 ms 10996 KB Output is correct
7 Correct 147 ms 10956 KB Output is correct
8 Correct 196 ms 11500 KB Output is correct
9 Correct 49 ms 3304 KB Output is correct
10 Correct 182 ms 11508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 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 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 372 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 4 ms 468 KB Output is correct
12 Correct 9 ms 876 KB Output is correct
13 Correct 9 ms 852 KB Output is correct
14 Correct 10 ms 852 KB Output is correct
15 Correct 9 ms 956 KB Output is correct
16 Correct 8 ms 852 KB Output is correct
17 Correct 5 ms 784 KB Output is correct
18 Correct 8 ms 952 KB Output is correct
19 Correct 550 ms 23848 KB Output is correct
20 Correct 535 ms 23840 KB Output is correct
21 Correct 470 ms 21496 KB Output is correct
22 Correct 485 ms 21532 KB Output is correct
23 Correct 501 ms 21512 KB Output is correct
24 Correct 336 ms 22188 KB Output is correct
25 Correct 318 ms 22180 KB Output is correct
26 Correct 352 ms 22960 KB Output is correct
27 Correct 343 ms 22936 KB Output is correct
28 Correct 368 ms 23492 KB Output is correct
29 Correct 382 ms 24596 KB Output is correct
30 Correct 386 ms 24792 KB Output is correct
31 Correct 372 ms 24572 KB Output is correct
32 Correct 375 ms 24520 KB Output is correct
33 Correct 378 ms 24608 KB Output is correct
34 Correct 326 ms 21696 KB Output is correct
35 Correct 315 ms 21668 KB Output is correct
36 Correct 309 ms 21784 KB Output is correct
37 Correct 310 ms 21696 KB Output is correct
38 Correct 337 ms 21828 KB Output is correct
39 Correct 368 ms 22948 KB Output is correct
40 Correct 251 ms 16132 KB Output is correct
41 Correct 387 ms 22812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 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 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 372 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 4 ms 468 KB Output is correct
12 Correct 9 ms 876 KB Output is correct
13 Correct 9 ms 852 KB Output is correct
14 Correct 10 ms 852 KB Output is correct
15 Correct 9 ms 956 KB Output is correct
16 Correct 8 ms 852 KB Output is correct
17 Correct 5 ms 784 KB Output is correct
18 Correct 8 ms 952 KB Output is correct
19 Execution timed out 3042 ms 107816 KB Time limit exceeded
20 Halted 0 ms 0 KB -