Submission #779844

# Submission time Handle Problem Language Result Execution time Memory
779844 2023-07-12T01:18:04 Z khoquennguoiminhthuong Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
544 ms 57944 KB
#include <bits/stdc++.h>

using namespace std;
long long n,q;
long long a[1000005];
long long tree[1000005];
void upd(long long id,long long val) {
    while(id>0) {
        tree[id]=max(tree[id],val);
        id-=(id&(-id));
    }
}
long long get(long long id) {
    long long maxx=-2e9;
    while(id<=n) {
        maxx=max(maxx,tree[id]);
        id+=(id&(-id));
    }
    return maxx;
}
struct que {
    long long l,r,k,id;
} qu[1000005];
bool cmp(que a,que b) {
    return a.r<b.r;
}
int ans[1000005];
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>q;
    for(long long i=1; i<=n; i++)cin>>a[i];
    for(long long i=1; i<=q; i++) {
        long long l,r,k;
        cin>>l>>r>>k;
        qu[i]= {l,r,k,i};
    }
    sort(qu+1,qu+q+1,cmp);
    long long dd=0;
    stack<long long>st;
    for(long long i=1; i<=q; i++) {
        while(dd+1<=qu[i].r) {
            dd++;
            while(st.size()&&a[st.top()]<a[dd])st.pop();
            if(st.size()>0){upd(st.top(),a[st.top()]+a[dd]);}
            st.push(dd);
        }
        if(get(qu[i].l)>qu[i].k)ans[qu[i].id]=0;
        else ans[qu[i].id]=1;
    }
    for(long long i=1; i<=q; i++)cout<<ans[i]<<'\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Incorrect 1 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Incorrect 1 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 536 ms 53344 KB Output is correct
2 Correct 544 ms 57944 KB Output is correct
3 Correct 537 ms 57804 KB Output is correct
4 Correct 541 ms 57808 KB Output is correct
5 Incorrect 514 ms 57724 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 43 ms 5580 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Incorrect 1 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Incorrect 1 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -