#include <bits/stdc++.h>
using namespace std;
int N=1<<19;
vector<int> bin(2*N, 0);
vector<set<int>> T(2*N);
int ans=0;
int query(int id, int l, int r, int a, int b, int mx)
{
if(l>=b||r<=a)
return -1e9;
if(a<=l&&r<=b)
{
ans=max(ans, bin[id]);
if(T[id].lower_bound(mx)!=T[id].begin())
{
int en=*(--T[id].lower_bound(mx));
ans=max(ans, mx+en);
}
return *(--T[id].end());
}
int mid=(l+r)/2;
mx=max(mx, query(id*2, l, mid, a, b, mx));
mx=max(mx, query(id*2+1, mid+1, r, a, b, mx));
return mx;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, q;
cin >> n >> q;
for (int i=0; i<n; i++)
{
int a;
cin >> a;
T[i+N].insert(a);
}
for(int i=n; i<N; i++)
T[i+N].insert(1e9);
for(int i=N-1; i>0; i--)
{
for (int x:T[i*2])
T[i].insert(x);
for (int x:T[i*2+1])
T[i].insert(x);
bin[i]=max(bin[i*2], bin[i*2+1]);
int mx=*(--T[i*2].end());
if (T[i*2+1].lower_bound(mx)!=T[i*2+1].begin())
bin[i]=max(bin[i], mx+*(--T[i*2+1].lower_bound(mx)));
}
while(q--)
{
int l, r, mood;
cin >> l >> r >> mood;
l--;
ans=0;
query(1, 0, N, l, r, -1e9);
if(ans<=mood)
cout << "1\n";
else
cout << "0\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
102996 KB |
Output is correct |
2 |
Correct |
65 ms |
102824 KB |
Output is correct |
3 |
Incorrect |
81 ms |
102996 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
102996 KB |
Output is correct |
2 |
Correct |
65 ms |
102824 KB |
Output is correct |
3 |
Incorrect |
81 ms |
102996 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
119 ms |
163924 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
370 ms |
148024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
102996 KB |
Output is correct |
2 |
Correct |
65 ms |
102824 KB |
Output is correct |
3 |
Incorrect |
81 ms |
102996 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
102996 KB |
Output is correct |
2 |
Correct |
65 ms |
102824 KB |
Output is correct |
3 |
Incorrect |
81 ms |
102996 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |