답안 #898182

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
898182 2024-01-04T11:18:18 Z vjudge1 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
855 ms 119420 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, mnA, mxK, a[N], b[N], seg[N*4], lg[N], st[L][N];
vector<int> lf[N];
vector<tp3> q[N];
bitset<N> ans;

void build(int p=1, int l=0, int r=n-1) {
  if (l == r) {
    seg[p] = (b[l] == -1 ? 0 : (a[l] + a[b[l]]));
    return;
  }

  int mid = (l+r) >> 1;
  build(p*2, l, mid);
  build(p*2+1, mid+1, r); 

  seg[p] = max(seg[p*2], seg[p*2+1]);
}

void update(int x, int p=1, int l=0, int r=n-1) {
  if (l == r) {
    seg[p] = 0;
    return;
  }

  int mid = (l+r) >> 1;
  if (x <= mid) update(x, p*2, l, mid);
  else update(x, p*2+1, mid+1, r); 

  seg[p] = max(seg[p*2], seg[p*2+1]);
}

int query(int x, int y, int p=1, int l=0, int r=n-1) {
  if (x <= l && r <= y) {
    return seg[p];
  }

  int mid = (l+r) >> 1;
  if (y <= mid) {
    return query(x, y, p*2, l, mid);
  }
  else if(mid+1 <= x) {
    return query(x, y, p*2+1, mid+1, r);
  }
  else {
    return max(query(x, y, p*2, l, mid), query(x, y, p*2+1, mid+1, r));
  }
}

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);

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

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

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

  if (mxK < mnA) {
    vector<int> c;
    c.push_back(0);
    for (int i = 1; i < n; i++) {
      if (a[i] < a[i-1]) {
        c.push_back(i);
      }
    }

    for (int l = 0; l < n; l++) {
      for (auto& [r, k, idx] : q[l]) {
        int x = upper_bound(all(c), l) - c.begin();
        int y = upper_bound(all(c), r) - c.begin();
        ans[idx] = (x == y);
      }
    }
  }
  else {
    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;
      }
      b[i] = l;
      lf[l].push_back(i);
    }

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

      for (int& i : lf[l]) {
        update(i);
      }
    }

    for (int i = 0; i < m; i++) {
      cout << ans[i] << "\n";
    }
  }
}

/*
#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 24 ms 94880 KB Output is correct
2 Correct 18 ms 94920 KB Output is correct
3 Correct 16 ms 94808 KB Output is correct
4 Correct 19 ms 94812 KB Output is correct
5 Correct 16 ms 94812 KB Output is correct
6 Correct 19 ms 94812 KB Output is correct
7 Correct 17 ms 94808 KB Output is correct
8 Correct 17 ms 94812 KB Output is correct
9 Correct 16 ms 94812 KB Output is correct
10 Correct 16 ms 94812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 94880 KB Output is correct
2 Correct 18 ms 94920 KB Output is correct
3 Correct 16 ms 94808 KB Output is correct
4 Correct 19 ms 94812 KB Output is correct
5 Correct 16 ms 94812 KB Output is correct
6 Correct 19 ms 94812 KB Output is correct
7 Correct 17 ms 94808 KB Output is correct
8 Correct 17 ms 94812 KB Output is correct
9 Correct 16 ms 94812 KB Output is correct
10 Correct 16 ms 94812 KB Output is correct
11 Correct 18 ms 94812 KB Output is correct
12 Correct 18 ms 95068 KB Output is correct
13 Correct 22 ms 95064 KB Output is correct
14 Correct 20 ms 95068 KB Output is correct
15 Correct 23 ms 95068 KB Output is correct
16 Correct 19 ms 95068 KB Output is correct
17 Correct 18 ms 94960 KB Output is correct
18 Correct 19 ms 94944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 855 ms 84532 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 107084 KB Output is correct
2 Correct 130 ms 106568 KB Output is correct
3 Correct 80 ms 105752 KB Output is correct
4 Correct 88 ms 105928 KB Output is correct
5 Correct 85 ms 105936 KB Output is correct
6 Correct 74 ms 105344 KB Output is correct
7 Correct 72 ms 105320 KB Output is correct
8 Correct 84 ms 105504 KB Output is correct
9 Correct 57 ms 96624 KB Output is correct
10 Correct 97 ms 105700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 94880 KB Output is correct
2 Correct 18 ms 94920 KB Output is correct
3 Correct 16 ms 94808 KB Output is correct
4 Correct 19 ms 94812 KB Output is correct
5 Correct 16 ms 94812 KB Output is correct
6 Correct 19 ms 94812 KB Output is correct
7 Correct 17 ms 94808 KB Output is correct
8 Correct 17 ms 94812 KB Output is correct
9 Correct 16 ms 94812 KB Output is correct
10 Correct 16 ms 94812 KB Output is correct
11 Correct 18 ms 94812 KB Output is correct
12 Correct 18 ms 95068 KB Output is correct
13 Correct 22 ms 95064 KB Output is correct
14 Correct 20 ms 95068 KB Output is correct
15 Correct 23 ms 95068 KB Output is correct
16 Correct 19 ms 95068 KB Output is correct
17 Correct 18 ms 94960 KB Output is correct
18 Correct 19 ms 94944 KB Output is correct
19 Correct 264 ms 119420 KB Output is correct
20 Correct 250 ms 119336 KB Output is correct
21 Correct 196 ms 118432 KB Output is correct
22 Correct 191 ms 118344 KB Output is correct
23 Correct 226 ms 118356 KB Output is correct
24 Correct 176 ms 116524 KB Output is correct
25 Correct 146 ms 116492 KB Output is correct
26 Correct 177 ms 116676 KB Output is correct
27 Correct 205 ms 116708 KB Output is correct
28 Correct 191 ms 116676 KB Output is correct
29 Correct 199 ms 116936 KB Output is correct
30 Correct 203 ms 117136 KB Output is correct
31 Correct 170 ms 116972 KB Output is correct
32 Correct 180 ms 116932 KB Output is correct
33 Correct 182 ms 117080 KB Output is correct
34 Correct 183 ms 115872 KB Output is correct
35 Correct 160 ms 115912 KB Output is correct
36 Correct 134 ms 115908 KB Output is correct
37 Correct 150 ms 115908 KB Output is correct
38 Correct 170 ms 116008 KB Output is correct
39 Correct 163 ms 116996 KB Output is correct
40 Correct 134 ms 109860 KB Output is correct
41 Correct 163 ms 116412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 94880 KB Output is correct
2 Correct 18 ms 94920 KB Output is correct
3 Correct 16 ms 94808 KB Output is correct
4 Correct 19 ms 94812 KB Output is correct
5 Correct 16 ms 94812 KB Output is correct
6 Correct 19 ms 94812 KB Output is correct
7 Correct 17 ms 94808 KB Output is correct
8 Correct 17 ms 94812 KB Output is correct
9 Correct 16 ms 94812 KB Output is correct
10 Correct 16 ms 94812 KB Output is correct
11 Correct 18 ms 94812 KB Output is correct
12 Correct 18 ms 95068 KB Output is correct
13 Correct 22 ms 95064 KB Output is correct
14 Correct 20 ms 95068 KB Output is correct
15 Correct 23 ms 95068 KB Output is correct
16 Correct 19 ms 95068 KB Output is correct
17 Correct 18 ms 94960 KB Output is correct
18 Correct 19 ms 94944 KB Output is correct
19 Incorrect 855 ms 84532 KB Output isn't correct
20 Halted 0 ms 0 KB -