#include <bits/stdc++.h>
using namespace std;
vector<int>w;
vector<int>st;
vector<vector<int>>v;
void build(int i, int j, int p) {
if(i == j) {
st[p] = 0;
v[p] = {w[i]};
return;
}
int mid = (i+j)/2;
build(i, mid, 2*p),
build(mid+1, j, 2*p+1);
const int n = (int)v[2*p].size(),
m = (int)v[2*p+1].size();
int pp = 0;
st[p] = max(st[2*p], st[2*p+1]);
for(int ii = 0 ; ii < n ; ii++) {
while(pp < m && v[2*p+1][pp] < v[2*p][ii]) {
st[p] = max(st[p], v[2*p].back() + v[2*p+1][pp]);
v[p].push_back(v[2*p+1][pp]);
pp++;
}
v[p].push_back(v[2*p][ii]);
}
while(pp < m)
v[p].push_back(v[2*p+1][pp++]);
cout << i <<" " << j << " " << st[p] << "\n";
}
int ans;
int l,r;
int query(int i, int j, int p, int mx, bool r_) {
if(i > r || j < l)
return -1;
if(i >= l && j <= r) {
ans = max(ans, st[p]);
if(r_) {
const int n = (int)v[p].size();
int le = 0, re = n-1, ret = -1;
while(le <= re) {
int mi = (le+re)/2;
if(v[p][mi] < mx) {
ret = mi;
le = mi+1;
} else re = mi-1;
}
ans = max(ans, (ret == -1 ? 0 : mx + v[p][ret]));
}
return v[p].back();
}
int mid = (i+j)/2;
mx = max(mx, query(i, mid, 2*p, mx, 0));
mx = max(mx, query(mid+1, j, 2*p+1, mx, 1));
return mx;
}
signed main() {
int n,q; cin>>n>>q;
w.resize(n);
st.resize(8 * n);
v.resize(8 * n);
for(auto &z : w)
cin>>z;
build(0, n-1, 1);
while(q--) {
int k; cin>>l>>r>>k;
l--,r--;
ans = 0;
query(0,n-1,1,-1,0);
cout << (ans <= k) << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
686 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
467 ms |
37700 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |