답안 #869599

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
869599 2023-11-05T02:00:34 Z NeroZein Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
974 ms 83716 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif

const int N = 1e6 + 6;

int ans[N]; 
int seg[N * 2];

void upd(int nd, int l, int r, int p, int v) {
  if (l == r) {
    seg[nd] = max(seg[nd], v);
    return;
  }
  int mid = (l + r) >> 1;
  int rs = nd + ((mid - l + 1) << 1);
  if (p <= mid) {
    upd(nd + 1, l, mid, p, v);
  } else {
    upd(rs, mid + 1, r, p, v);
  }
  seg[nd] = max(seg[nd + 1], seg[rs]); 
}

int qry(int nd, int l, int r, int s, int e) {
  if (l >= s && r <= e) {
    return seg[nd]; 
  }
  int mid = (l + r) >> 1;
  int rs = nd + ((mid - l + 1) << 1);
  if (mid >= e) {
    return qry(nd + 1, l, mid, s, e); 
  } else {
    if (mid < s) {
      return qry(rs, mid + 1, r, s, e);
    } else {
      return max(qry(nd + 1, l, mid, s, e), qry(rs, mid + 1, r, s, e)); 
    }
  }
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, q;
  cin >> n >> q;
  vector<int> a(n); 
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  stack<int> stk;
  vector<array<int, 4>> ranges; 
  for (int i = 0; i < q; ++i) {
    int l, r, v;
    cin >> l >> r >> v; 
    --l, --r; 
    ranges.push_back({l, r, v, i});
  }
  for (int i = n - 1; i >= 0; --i) {
    while (!stk.empty() && a[stk.top()] < a[i]) {
      ranges.push_back({i, stk.top(), a[i] + a[stk.top()], -1});//ranges with higher value come later
      stk.pop();
    }
    stk.push(i); 
  }
  sort(ranges.begin(), ranges.end()); 
  reverse(ranges.begin(), ranges.end()); 
  for (auto [l, r, v, i] : ranges) {
    if (i == -1) {
      upd(0, 0, n - 1, r, v); 
    } else {
      int mx = qry(0, 0, n - 1, l, r);
      ans[i] = (mx <= v); 
    }
  }
  for (int i = 0; i < q; ++i) {
    cout << ans[i] << '\n'; 
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Incorrect 1 ms 2648 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Incorrect 1 ms 2648 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 974 ms 50096 KB Output is correct
2 Incorrect 898 ms 83716 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 82 ms 7356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Incorrect 1 ms 2648 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Incorrect 1 ms 2648 KB Output isn't correct
5 Halted 0 ms 0 KB -