#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 |
1 |
Correct |
10 ms |
51288 KB |
Output is correct |
2 |
Correct |
10 ms |
51360 KB |
Output is correct |
3 |
Incorrect |
10 ms |
51288 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
51288 KB |
Output is correct |
2 |
Correct |
10 ms |
51360 KB |
Output is correct |
3 |
Incorrect |
10 ms |
51288 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
968 ms |
85096 KB |
Output is correct |
2 |
Correct |
910 ms |
86020 KB |
Output is correct |
3 |
Correct |
891 ms |
86036 KB |
Output is correct |
4 |
Correct |
898 ms |
86188 KB |
Output is correct |
5 |
Correct |
849 ms |
86276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
68 ms |
53376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
51288 KB |
Output is correct |
2 |
Correct |
10 ms |
51360 KB |
Output is correct |
3 |
Incorrect |
10 ms |
51288 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
51288 KB |
Output is correct |
2 |
Correct |
10 ms |
51360 KB |
Output is correct |
3 |
Incorrect |
10 ms |
51288 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |