답안 #898169

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
898169 2024-01-04T11:09:30 Z vjudge1 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
796 ms 177716 KB
#include <bits/stdc++.h>
using namespace std;

#define all(x) x.begin(), x.end()
#define tp3 tuple<int, int, int>

const int N = 1e6, L = 20, inf = INT_MAX;

int n, m, a[N], bit[N], lg[N], st[L][N];
vector<int> lf[N];
vector<tp3> q[N];
bitset<N> ans;

void update(int i, int x) {
  for (; i < n; i = i | (i + 1)) {
    bit[i] += x;
  }
}

int query(int r) {
  int x = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) {
    x = max(x, bit[r]);
  }
  return x;
}

int querySt(int l, int r) {
  int x = lg[r-l+1];
  return max(st[x][l], st[x][r - (1 << x) + 1]);
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  memset(bit, 0, sizeof(bit));

  lg[1] = 0;
  for (int i = 2; i < N; i++) {
    lg[i] = lg[i >> 1] + 1;
  }

  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    st[0][i] = a[i];
  }

  for (int i = 0; i < m; i++) {
    int l, r, k;
    cin >> l >> r >> k;
    l--; r--;
    q[l].push_back(make_tuple(r, k, i));
  }

  for (int j = 1; j < L; j++) {
    for (int i = 0; i < n; i++) {
      st[j][i] = max(st[j-1][i], st[j-1][i + (1 << (j-1))]);
    }
  }

  for (int i = 0; i < n; i++) {
    int l = -1;
    int r = i-1;
    while (l < r) {
      int mid = (l+r+1)/2;

      int x = querySt(mid, i-1);
      if (x > a[i]) l = mid;
      else r = mid-1;
    }
    lf[l].push_back(i);
    if (l != -1) update(i, a[i]+a[l]);
  }

  for (int l = 0; l < n; l++) {
    for (auto& [r, k, idx] : q[l]) {
      ans[idx] = (query(r) <= k);
    }

    for (int& i : lf[l]) {
      update(i, -(a[i]+a[l]));
    }
  }

  for (int i = 0; i < m; i++) {
    cout << ans[i] << "\n";
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 94800 KB Output is correct
2 Correct 17 ms 94808 KB Output is correct
3 Incorrect 16 ms 94812 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 94800 KB Output is correct
2 Correct 17 ms 94808 KB Output is correct
3 Incorrect 16 ms 94812 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 796 ms 177716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 70 ms 107092 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 94800 KB Output is correct
2 Correct 17 ms 94808 KB Output is correct
3 Incorrect 16 ms 94812 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 94800 KB Output is correct
2 Correct 17 ms 94808 KB Output is correct
3 Incorrect 16 ms 94812 KB Output isn't correct
4 Halted 0 ms 0 KB -