# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
321551 | tushar_2658 | Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) | C++14 | 66 ms | 364 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
const int maxn = 5005;
using ll = long long;
ll a[maxn];
bool get(int l, int r, ll k){
bool good = 1;
stack<int> st;
for(int i = r; i >= l; --i){
while(!st.empty() && a[st.top()] < a[i]){
if(a[i] + a[st.top()] > k){
good = 0;
break;
}
st.pop();
}
if(!good)break;
st.push(i);
}
return good;
}
int main(int argc, char const *argv[])
{
int n, q;
scanf("%d %d", &n, &q);
for(int i = 1; i <= n; ++i){
scanf("%lld", &a[i]);
}
while(q--){
int l, r;
ll k;
scanf("%d %d %lld", &l, &r, &k);
bool ans = get(l, r, k);
printf("%d\n", ans);
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |