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;
vector<int> haha(1000001);
vector<pair<int,int>> seg(4000001);
vector<int> wow(4000001);
int d = 0;
void build(int l, int r, int x) {
if(l == r) {
seg[x] = {haha[l],haha[l]};
return;
}
int m = (l+r)/2;
build(l,m,x*2+1);
build(m+1,r,x*2+2);
pair<int,int> a = seg[x*2+1],b = seg[x*2+2];
seg[x] = {max(a.first,b.first),min(a.second,b.second)};
wow[x] = max(wow[x*2+1],wow[x*2+2]);
if(a.first > b.second) {
wow[x] = max(wow[x],a.first+b.second);
}
}
pair<int,int> calc(int l, int r, int ql, int qr, int x) {
if(ql == l && qr == r) {
d = max(d,wow[x]);
return seg[x];
}
int m = (l+r)/2;
if(qr <= m) {
return calc(l,m,ql,qr,x*2+1);
}
else if(ql > m) {
return calc(m+1,r,ql,qr,x*2+2);
}
else {
pair<int,int> a = calc(l,m,ql,m,x*2+1);
pair<int,int> b = calc(m+1,r,m+1,qr,x*2+2);
if(a.first > b.second) {
d = max(d,a.first+b.second);
}
return {max(a.first,b.first),min(a.second,b.second)};
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,m,l,r,k;
cin >> n >> m;
for(int i = 1; i <= n; i++) {
cin >> haha[i];
}
build(1,n,0);
for(int i = 0; i < m; i++) {
cin >> l >> r >> k;
d = 0;
calc(1,n,l,r,0);
if(d > k) {
cout << 0 << "\n";
}
else {
cout << 1 << "\n";
}
}
return 0;
}
# | 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... |