#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[1000005];
int tole[1000005];
int rez[1000005];
deque<int> dq;
vector<pair<pair<int,int>,int>> qrys[1000005];
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i];
while(!dq.empty() && a[dq.back()]<=a[i])
dq.pop_back();
if(dq.empty())
tole[i]=0;
else
tole[i]=dq.back();
dq.push_back(i);
}
int ql,qr,k;
for(int i=1;i<=m;i++)
{
cin>>ql>>qr>>k;
qrys[qr].push_back({{ql,k},i});
}
for(int i=1;i<=n;i++)
{
for(auto x:qrys[i])
{
int le=x.first.first;
int mxm=0;
for(int j=le;j<=i;j++)
if(tole[j]>=le)
mxm=max(mxm, a[j]+a[tole[j]]);
if(mxm<=x.first.second)
rez[x.second]=1;
else
rez[x.second]=0;
}
}
for(int i=1;i<=m;i++)
cout<<rez[i]<<"\n";
return 0;
}
/**
tole[i] = prima pozitie din stanga lui i > a[i]
max(a[j] + a[tole[j]]) pt j = le..ri && tole[j] >= le
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
29276 KB |
Output is correct |
2 |
Correct |
6 ms |
29276 KB |
Output is correct |
3 |
Correct |
6 ms |
29276 KB |
Output is correct |
4 |
Correct |
6 ms |
29364 KB |
Output is correct |
5 |
Correct |
6 ms |
29276 KB |
Output is correct |
6 |
Correct |
6 ms |
29372 KB |
Output is correct |
7 |
Correct |
6 ms |
29276 KB |
Output is correct |
8 |
Correct |
7 ms |
29276 KB |
Output is correct |
9 |
Correct |
6 ms |
29368 KB |
Output is correct |
10 |
Correct |
6 ms |
29340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
29276 KB |
Output is correct |
2 |
Correct |
6 ms |
29276 KB |
Output is correct |
3 |
Correct |
6 ms |
29276 KB |
Output is correct |
4 |
Correct |
6 ms |
29364 KB |
Output is correct |
5 |
Correct |
6 ms |
29276 KB |
Output is correct |
6 |
Correct |
6 ms |
29372 KB |
Output is correct |
7 |
Correct |
6 ms |
29276 KB |
Output is correct |
8 |
Correct |
7 ms |
29276 KB |
Output is correct |
9 |
Correct |
6 ms |
29368 KB |
Output is correct |
10 |
Correct |
6 ms |
29340 KB |
Output is correct |
11 |
Correct |
9 ms |
29272 KB |
Output is correct |
12 |
Correct |
12 ms |
29532 KB |
Output is correct |
13 |
Correct |
12 ms |
29556 KB |
Output is correct |
14 |
Correct |
15 ms |
29636 KB |
Output is correct |
15 |
Correct |
16 ms |
29640 KB |
Output is correct |
16 |
Correct |
21 ms |
29548 KB |
Output is correct |
17 |
Correct |
18 ms |
29532 KB |
Output is correct |
18 |
Correct |
20 ms |
29532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3068 ms |
86608 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2370 ms |
33468 KB |
Output is correct |
2 |
Execution timed out |
3093 ms |
33104 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
29276 KB |
Output is correct |
2 |
Correct |
6 ms |
29276 KB |
Output is correct |
3 |
Correct |
6 ms |
29276 KB |
Output is correct |
4 |
Correct |
6 ms |
29364 KB |
Output is correct |
5 |
Correct |
6 ms |
29276 KB |
Output is correct |
6 |
Correct |
6 ms |
29372 KB |
Output is correct |
7 |
Correct |
6 ms |
29276 KB |
Output is correct |
8 |
Correct |
7 ms |
29276 KB |
Output is correct |
9 |
Correct |
6 ms |
29368 KB |
Output is correct |
10 |
Correct |
6 ms |
29340 KB |
Output is correct |
11 |
Correct |
9 ms |
29272 KB |
Output is correct |
12 |
Correct |
12 ms |
29532 KB |
Output is correct |
13 |
Correct |
12 ms |
29556 KB |
Output is correct |
14 |
Correct |
15 ms |
29636 KB |
Output is correct |
15 |
Correct |
16 ms |
29640 KB |
Output is correct |
16 |
Correct |
21 ms |
29548 KB |
Output is correct |
17 |
Correct |
18 ms |
29532 KB |
Output is correct |
18 |
Correct |
20 ms |
29532 KB |
Output is correct |
19 |
Execution timed out |
3093 ms |
39504 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
29276 KB |
Output is correct |
2 |
Correct |
6 ms |
29276 KB |
Output is correct |
3 |
Correct |
6 ms |
29276 KB |
Output is correct |
4 |
Correct |
6 ms |
29364 KB |
Output is correct |
5 |
Correct |
6 ms |
29276 KB |
Output is correct |
6 |
Correct |
6 ms |
29372 KB |
Output is correct |
7 |
Correct |
6 ms |
29276 KB |
Output is correct |
8 |
Correct |
7 ms |
29276 KB |
Output is correct |
9 |
Correct |
6 ms |
29368 KB |
Output is correct |
10 |
Correct |
6 ms |
29340 KB |
Output is correct |
11 |
Correct |
9 ms |
29272 KB |
Output is correct |
12 |
Correct |
12 ms |
29532 KB |
Output is correct |
13 |
Correct |
12 ms |
29556 KB |
Output is correct |
14 |
Correct |
15 ms |
29636 KB |
Output is correct |
15 |
Correct |
16 ms |
29640 KB |
Output is correct |
16 |
Correct |
21 ms |
29548 KB |
Output is correct |
17 |
Correct |
18 ms |
29532 KB |
Output is correct |
18 |
Correct |
20 ms |
29532 KB |
Output is correct |
19 |
Execution timed out |
3068 ms |
86608 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |