Submission #899108

# Submission time Handle Problem Language Result Execution time Memory
899108 2024-01-05T13:29:25 Z d4xn Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
Compilation error
0 ms 0 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], b[N], mxL[N], seg[N*4];
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));
  }
}
 
signed main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
 
  cin >> n >> m;
  stack<pair<int, int>> st;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    
    while (!st.empty() && st.top().first <= a[i]) st.pop();
    
    b[i] = (st.empty() ? -1 : st.top().second);
    lf[st.top().second].push_back(i);
    
    st.push(make_pair(a[i], 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))]);
      }
    }
 
    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";
    }
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:81:11: error: no match for 'operator[]' (operand types are 'std::stack<std::pair<int, int> >' and 'int')
   81 |         st[j][i] = max(st[j-1][i], st[j-1][i + (1 << (j-1))]);
      |           ^
sortbooks.cpp:81:26: error: no match for 'operator[]' (operand types are 'std::stack<std::pair<int, int> >' and 'int')
   81 |         st[j][i] = max(st[j-1][i], st[j-1][i + (1 << (j-1))]);
      |                          ^
sortbooks.cpp:81:38: error: no match for 'operator[]' (operand types are 'std::stack<std::pair<int, int> >' and 'int')
   81 |         st[j][i] = max(st[j-1][i], st[j-1][i + (1 << (j-1))]);
      |                                      ^