#include <bits/stdc++.h>
using namespace std;
const long long MX=2e5+10;
vector < pair < long long , pair < long long , long long > > > zap[MX];
long long a[MX],ans[MX],fen[MX],n,q;
long long get_real_in(long long in)
{
return (n-in+1);
}
long long fget(long long in)
{
in=get_real_in(in);
long long ans=0;
while(in>0)
{
ans=max(ans,fen[in]);
in=(in&(in+1))-1;
}
return ans;
}
void upd(long long in,long long zn)
{
in=get_real_in(in);
while(in<=n)
{
fen[in]=max(fen[in],zn);
in=(in|(in+1));
}
}
int main()
{
cin>>n>>q;
for(long long i=1;i<=n;i++)
{
cin>>a[i];
}
for(long long i=1;i<=q;i++)
{
long long l,r,w;
cin>>l>>r>>w;
zap[r].push_back({l,{w,i}});
}
stack < long long > st; // pos
for(long long i=1;i<=n;i++)
{
while(!st.empty())
{
if(a[st.top()]<=a[i])
{
st.pop();
}
else
{
break;
}
}
if(!st.empty())
{
long long pos=st.top();
upd(pos,a[pos]+a[i]);
}
for(auto u:zap[i])
{
ans[u.second.second]=(fget(u.first)<=u.second.first);
}
st.push(i);
}
for(long long i=1;i<=q;i++)
{
cout<<ans[i]<<"\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
5144 KB |
Output is correct |
5 |
Correct |
3 ms |
5140 KB |
Output is correct |
6 |
Correct |
4 ms |
4952 KB |
Output is correct |
7 |
Correct |
3 ms |
4956 KB |
Output is correct |
8 |
Correct |
3 ms |
5144 KB |
Output is correct |
9 |
Correct |
3 ms |
4956 KB |
Output is correct |
10 |
Correct |
3 ms |
4956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
5144 KB |
Output is correct |
5 |
Correct |
3 ms |
5140 KB |
Output is correct |
6 |
Correct |
4 ms |
4952 KB |
Output is correct |
7 |
Correct |
3 ms |
4956 KB |
Output is correct |
8 |
Correct |
3 ms |
5144 KB |
Output is correct |
9 |
Correct |
3 ms |
4956 KB |
Output is correct |
10 |
Correct |
3 ms |
4956 KB |
Output is correct |
11 |
Correct |
4 ms |
5212 KB |
Output is correct |
12 |
Correct |
6 ms |
5408 KB |
Output is correct |
13 |
Correct |
6 ms |
5212 KB |
Output is correct |
14 |
Correct |
7 ms |
5404 KB |
Output is correct |
15 |
Correct |
7 ms |
5352 KB |
Output is correct |
16 |
Correct |
6 ms |
5468 KB |
Output is correct |
17 |
Correct |
6 ms |
5468 KB |
Output is correct |
18 |
Correct |
6 ms |
5468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
212 ms |
21172 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
119 ms |
12876 KB |
Output is correct |
2 |
Correct |
77 ms |
12884 KB |
Output is correct |
3 |
Correct |
76 ms |
12116 KB |
Output is correct |
4 |
Correct |
89 ms |
12112 KB |
Output is correct |
5 |
Correct |
131 ms |
12092 KB |
Output is correct |
6 |
Correct |
85 ms |
11948 KB |
Output is correct |
7 |
Correct |
79 ms |
11968 KB |
Output is correct |
8 |
Correct |
79 ms |
11484 KB |
Output is correct |
9 |
Correct |
55 ms |
10288 KB |
Output is correct |
10 |
Correct |
81 ms |
11476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
5144 KB |
Output is correct |
5 |
Correct |
3 ms |
5140 KB |
Output is correct |
6 |
Correct |
4 ms |
4952 KB |
Output is correct |
7 |
Correct |
3 ms |
4956 KB |
Output is correct |
8 |
Correct |
3 ms |
5144 KB |
Output is correct |
9 |
Correct |
3 ms |
4956 KB |
Output is correct |
10 |
Correct |
3 ms |
4956 KB |
Output is correct |
11 |
Correct |
4 ms |
5212 KB |
Output is correct |
12 |
Correct |
6 ms |
5408 KB |
Output is correct |
13 |
Correct |
6 ms |
5212 KB |
Output is correct |
14 |
Correct |
7 ms |
5404 KB |
Output is correct |
15 |
Correct |
7 ms |
5352 KB |
Output is correct |
16 |
Correct |
6 ms |
5468 KB |
Output is correct |
17 |
Correct |
6 ms |
5468 KB |
Output is correct |
18 |
Correct |
6 ms |
5468 KB |
Output is correct |
19 |
Correct |
245 ms |
23228 KB |
Output is correct |
20 |
Correct |
267 ms |
23244 KB |
Output is correct |
21 |
Correct |
214 ms |
23584 KB |
Output is correct |
22 |
Correct |
217 ms |
23544 KB |
Output is correct |
23 |
Correct |
238 ms |
23580 KB |
Output is correct |
24 |
Correct |
206 ms |
22020 KB |
Output is correct |
25 |
Correct |
203 ms |
22100 KB |
Output is correct |
26 |
Correct |
247 ms |
21940 KB |
Output is correct |
27 |
Correct |
239 ms |
21844 KB |
Output is correct |
28 |
Correct |
228 ms |
21796 KB |
Output is correct |
29 |
Correct |
235 ms |
21672 KB |
Output is correct |
30 |
Correct |
211 ms |
21588 KB |
Output is correct |
31 |
Correct |
213 ms |
21688 KB |
Output is correct |
32 |
Correct |
216 ms |
21588 KB |
Output is correct |
33 |
Correct |
218 ms |
21584 KB |
Output is correct |
34 |
Correct |
206 ms |
21584 KB |
Output is correct |
35 |
Correct |
182 ms |
21328 KB |
Output is correct |
36 |
Correct |
181 ms |
21308 KB |
Output is correct |
37 |
Correct |
193 ms |
21328 KB |
Output is correct |
38 |
Correct |
192 ms |
21332 KB |
Output is correct |
39 |
Correct |
176 ms |
20228 KB |
Output is correct |
40 |
Correct |
162 ms |
18240 KB |
Output is correct |
41 |
Correct |
168 ms |
19168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
2 ms |
5144 KB |
Output is correct |
5 |
Correct |
3 ms |
5140 KB |
Output is correct |
6 |
Correct |
4 ms |
4952 KB |
Output is correct |
7 |
Correct |
3 ms |
4956 KB |
Output is correct |
8 |
Correct |
3 ms |
5144 KB |
Output is correct |
9 |
Correct |
3 ms |
4956 KB |
Output is correct |
10 |
Correct |
3 ms |
4956 KB |
Output is correct |
11 |
Correct |
4 ms |
5212 KB |
Output is correct |
12 |
Correct |
6 ms |
5408 KB |
Output is correct |
13 |
Correct |
6 ms |
5212 KB |
Output is correct |
14 |
Correct |
7 ms |
5404 KB |
Output is correct |
15 |
Correct |
7 ms |
5352 KB |
Output is correct |
16 |
Correct |
6 ms |
5468 KB |
Output is correct |
17 |
Correct |
6 ms |
5468 KB |
Output is correct |
18 |
Correct |
6 ms |
5468 KB |
Output is correct |
19 |
Runtime error |
212 ms |
21172 KB |
Execution killed with signal 11 |
20 |
Halted |
0 ms |
0 KB |
- |