Submission #898382

# Submission time Handle Problem Language Result Execution time Memory
898382 2024-01-04T15:01:51 Z votranngocvy Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
0 / 100
1176 ms 119740 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define piii pair<int,pair<int,int>>
#define fi first
#define se second
const int N = 1e6 + 5;
int st[4 * N],a[N],ans[N],f[N];
vector<piii>vec[N];

void update(int id,int l,int r,int i,int val) {
    if (i < l || r < i) return;
    if (l == r) {
        st[id] = val;
        return;
    }
    int mid = (l + r) / 2;
    update(id * 2,l,mid,i,val);
    update(id * 2 + 1,mid + 1,r,i,val);
    st[id] = max(st[id * 2],st[id * 2 + 1]);
}

int get(int id,int l,int r,int u,int v) {
    if (v < l || r < u) return 0;
    if (u <= l && r <= v) return st[id];
    int mid = (l + r) / 2;
    return max(get(id * 2,l,mid,u,v),get(id * 2 + 1,mid + 1,r,u,v));
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n,m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= m; i++) {
        int l,r,k;
        cin >> l >> r >> k;
        vec[r].push_back({l,{i,k}});   
    }
    a[0] = 0;
    stack<int>st;
    for (int i = 1; i <= n; i++) {
        while (!st.empty() && a[st.top()] <= a[i]) st.pop();
        if (!st.empty()) f[i] = st.top();
        else f[i] = 0;
        st.push(i); 
    }
    for (int i = 1; i <= n; i++) update(1,1,n,i,a[f[i]] + a[i]);
    for (int r = 1; r <= n; r++) {
        for (auto x: vec[r]) {
            int l = x.fi,idx = x.se.fi,k = x.se.se;
            ans[idx] = (get(1,1,n,l,r) <= k);
        }
    }
    for (int i = 1; i <= m; i++) cout << ans[i] << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 31320 KB Output is correct
2 Correct 8 ms 31320 KB Output is correct
3 Incorrect 6 ms 31332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 31320 KB Output is correct
2 Correct 8 ms 31320 KB Output is correct
3 Incorrect 6 ms 31332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1176 ms 119740 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 88 ms 40788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 31320 KB Output is correct
2 Correct 8 ms 31320 KB Output is correct
3 Incorrect 6 ms 31332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 31320 KB Output is correct
2 Correct 8 ms 31320 KB Output is correct
3 Incorrect 6 ms 31332 KB Output isn't correct
4 Halted 0 ms 0 KB -