#include <bits/stdc++.h>
using namespace std;
const long long MX=1e6+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 |
11 ms |
23900 KB |
Output is correct |
2 |
Correct |
10 ms |
23728 KB |
Output is correct |
3 |
Correct |
10 ms |
23900 KB |
Output is correct |
4 |
Correct |
14 ms |
23900 KB |
Output is correct |
5 |
Correct |
11 ms |
23900 KB |
Output is correct |
6 |
Correct |
10 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23900 KB |
Output is correct |
8 |
Correct |
10 ms |
23756 KB |
Output is correct |
9 |
Correct |
11 ms |
23900 KB |
Output is correct |
10 |
Correct |
11 ms |
23832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23900 KB |
Output is correct |
2 |
Correct |
10 ms |
23728 KB |
Output is correct |
3 |
Correct |
10 ms |
23900 KB |
Output is correct |
4 |
Correct |
14 ms |
23900 KB |
Output is correct |
5 |
Correct |
11 ms |
23900 KB |
Output is correct |
6 |
Correct |
10 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23900 KB |
Output is correct |
8 |
Correct |
10 ms |
23756 KB |
Output is correct |
9 |
Correct |
11 ms |
23900 KB |
Output is correct |
10 |
Correct |
11 ms |
23832 KB |
Output is correct |
11 |
Correct |
11 ms |
23900 KB |
Output is correct |
12 |
Correct |
13 ms |
23900 KB |
Output is correct |
13 |
Correct |
19 ms |
23900 KB |
Output is correct |
14 |
Correct |
16 ms |
24156 KB |
Output is correct |
15 |
Correct |
19 ms |
24152 KB |
Output is correct |
16 |
Correct |
12 ms |
24156 KB |
Output is correct |
17 |
Correct |
15 ms |
24152 KB |
Output is correct |
18 |
Correct |
15 ms |
24152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1366 ms |
105584 KB |
Output is correct |
2 |
Correct |
1338 ms |
114588 KB |
Output is correct |
3 |
Correct |
1381 ms |
114524 KB |
Output is correct |
4 |
Correct |
1234 ms |
114716 KB |
Output is correct |
5 |
Correct |
1267 ms |
106996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
29520 KB |
Output is correct |
2 |
Correct |
82 ms |
29896 KB |
Output is correct |
3 |
Correct |
79 ms |
29008 KB |
Output is correct |
4 |
Correct |
88 ms |
28756 KB |
Output is correct |
5 |
Correct |
91 ms |
28756 KB |
Output is correct |
6 |
Correct |
75 ms |
29012 KB |
Output is correct |
7 |
Correct |
78 ms |
29012 KB |
Output is correct |
8 |
Correct |
82 ms |
28600 KB |
Output is correct |
9 |
Correct |
58 ms |
27652 KB |
Output is correct |
10 |
Correct |
108 ms |
28424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23900 KB |
Output is correct |
2 |
Correct |
10 ms |
23728 KB |
Output is correct |
3 |
Correct |
10 ms |
23900 KB |
Output is correct |
4 |
Correct |
14 ms |
23900 KB |
Output is correct |
5 |
Correct |
11 ms |
23900 KB |
Output is correct |
6 |
Correct |
10 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23900 KB |
Output is correct |
8 |
Correct |
10 ms |
23756 KB |
Output is correct |
9 |
Correct |
11 ms |
23900 KB |
Output is correct |
10 |
Correct |
11 ms |
23832 KB |
Output is correct |
11 |
Correct |
11 ms |
23900 KB |
Output is correct |
12 |
Correct |
13 ms |
23900 KB |
Output is correct |
13 |
Correct |
19 ms |
23900 KB |
Output is correct |
14 |
Correct |
16 ms |
24156 KB |
Output is correct |
15 |
Correct |
19 ms |
24152 KB |
Output is correct |
16 |
Correct |
12 ms |
24156 KB |
Output is correct |
17 |
Correct |
15 ms |
24152 KB |
Output is correct |
18 |
Correct |
15 ms |
24152 KB |
Output is correct |
19 |
Correct |
225 ms |
35500 KB |
Output is correct |
20 |
Correct |
228 ms |
35508 KB |
Output is correct |
21 |
Correct |
207 ms |
35924 KB |
Output is correct |
22 |
Correct |
252 ms |
36104 KB |
Output is correct |
23 |
Correct |
201 ms |
36084 KB |
Output is correct |
24 |
Correct |
222 ms |
34644 KB |
Output is correct |
25 |
Correct |
203 ms |
34692 KB |
Output is correct |
26 |
Correct |
204 ms |
34128 KB |
Output is correct |
27 |
Correct |
204 ms |
34276 KB |
Output is correct |
28 |
Correct |
219 ms |
34132 KB |
Output is correct |
29 |
Correct |
217 ms |
33812 KB |
Output is correct |
30 |
Correct |
219 ms |
33900 KB |
Output is correct |
31 |
Correct |
242 ms |
33840 KB |
Output is correct |
32 |
Correct |
213 ms |
33872 KB |
Output is correct |
33 |
Correct |
213 ms |
33840 KB |
Output is correct |
34 |
Correct |
188 ms |
34132 KB |
Output is correct |
35 |
Correct |
194 ms |
33872 KB |
Output is correct |
36 |
Correct |
183 ms |
34132 KB |
Output is correct |
37 |
Correct |
191 ms |
34096 KB |
Output is correct |
38 |
Correct |
196 ms |
34132 KB |
Output is correct |
39 |
Correct |
179 ms |
33940 KB |
Output is correct |
40 |
Correct |
163 ms |
32460 KB |
Output is correct |
41 |
Correct |
196 ms |
33296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23900 KB |
Output is correct |
2 |
Correct |
10 ms |
23728 KB |
Output is correct |
3 |
Correct |
10 ms |
23900 KB |
Output is correct |
4 |
Correct |
14 ms |
23900 KB |
Output is correct |
5 |
Correct |
11 ms |
23900 KB |
Output is correct |
6 |
Correct |
10 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23900 KB |
Output is correct |
8 |
Correct |
10 ms |
23756 KB |
Output is correct |
9 |
Correct |
11 ms |
23900 KB |
Output is correct |
10 |
Correct |
11 ms |
23832 KB |
Output is correct |
11 |
Correct |
11 ms |
23900 KB |
Output is correct |
12 |
Correct |
13 ms |
23900 KB |
Output is correct |
13 |
Correct |
19 ms |
23900 KB |
Output is correct |
14 |
Correct |
16 ms |
24156 KB |
Output is correct |
15 |
Correct |
19 ms |
24152 KB |
Output is correct |
16 |
Correct |
12 ms |
24156 KB |
Output is correct |
17 |
Correct |
15 ms |
24152 KB |
Output is correct |
18 |
Correct |
15 ms |
24152 KB |
Output is correct |
19 |
Correct |
1366 ms |
105584 KB |
Output is correct |
20 |
Correct |
1338 ms |
114588 KB |
Output is correct |
21 |
Correct |
1381 ms |
114524 KB |
Output is correct |
22 |
Correct |
1234 ms |
114716 KB |
Output is correct |
23 |
Correct |
1267 ms |
106996 KB |
Output is correct |
24 |
Correct |
86 ms |
29520 KB |
Output is correct |
25 |
Correct |
82 ms |
29896 KB |
Output is correct |
26 |
Correct |
79 ms |
29008 KB |
Output is correct |
27 |
Correct |
88 ms |
28756 KB |
Output is correct |
28 |
Correct |
91 ms |
28756 KB |
Output is correct |
29 |
Correct |
75 ms |
29012 KB |
Output is correct |
30 |
Correct |
78 ms |
29012 KB |
Output is correct |
31 |
Correct |
82 ms |
28600 KB |
Output is correct |
32 |
Correct |
58 ms |
27652 KB |
Output is correct |
33 |
Correct |
108 ms |
28424 KB |
Output is correct |
34 |
Correct |
225 ms |
35500 KB |
Output is correct |
35 |
Correct |
228 ms |
35508 KB |
Output is correct |
36 |
Correct |
207 ms |
35924 KB |
Output is correct |
37 |
Correct |
252 ms |
36104 KB |
Output is correct |
38 |
Correct |
201 ms |
36084 KB |
Output is correct |
39 |
Correct |
222 ms |
34644 KB |
Output is correct |
40 |
Correct |
203 ms |
34692 KB |
Output is correct |
41 |
Correct |
204 ms |
34128 KB |
Output is correct |
42 |
Correct |
204 ms |
34276 KB |
Output is correct |
43 |
Correct |
219 ms |
34132 KB |
Output is correct |
44 |
Correct |
217 ms |
33812 KB |
Output is correct |
45 |
Correct |
219 ms |
33900 KB |
Output is correct |
46 |
Correct |
242 ms |
33840 KB |
Output is correct |
47 |
Correct |
213 ms |
33872 KB |
Output is correct |
48 |
Correct |
213 ms |
33840 KB |
Output is correct |
49 |
Correct |
188 ms |
34132 KB |
Output is correct |
50 |
Correct |
194 ms |
33872 KB |
Output is correct |
51 |
Correct |
183 ms |
34132 KB |
Output is correct |
52 |
Correct |
191 ms |
34096 KB |
Output is correct |
53 |
Correct |
196 ms |
34132 KB |
Output is correct |
54 |
Correct |
179 ms |
33940 KB |
Output is correct |
55 |
Correct |
163 ms |
32460 KB |
Output is correct |
56 |
Correct |
196 ms |
33296 KB |
Output is correct |
57 |
Correct |
1238 ms |
115476 KB |
Output is correct |
58 |
Correct |
1239 ms |
115576 KB |
Output is correct |
59 |
Correct |
1177 ms |
116392 KB |
Output is correct |
60 |
Correct |
1208 ms |
116220 KB |
Output is correct |
61 |
Correct |
1162 ms |
116304 KB |
Output is correct |
62 |
Correct |
1267 ms |
116252 KB |
Output is correct |
63 |
Correct |
1091 ms |
108464 KB |
Output is correct |
64 |
Correct |
1091 ms |
108604 KB |
Output is correct |
65 |
Correct |
1323 ms |
108628 KB |
Output is correct |
66 |
Correct |
1326 ms |
108560 KB |
Output is correct |
67 |
Correct |
1358 ms |
108384 KB |
Output is correct |
68 |
Correct |
1361 ms |
107604 KB |
Output is correct |
69 |
Correct |
1420 ms |
107748 KB |
Output is correct |
70 |
Correct |
1358 ms |
107860 KB |
Output is correct |
71 |
Correct |
1356 ms |
107908 KB |
Output is correct |
72 |
Correct |
1214 ms |
107856 KB |
Output is correct |
73 |
Correct |
933 ms |
102452 KB |
Output is correct |
74 |
Correct |
941 ms |
103248 KB |
Output is correct |
75 |
Correct |
964 ms |
102692 KB |
Output is correct |
76 |
Correct |
930 ms |
102872 KB |
Output is correct |
77 |
Correct |
953 ms |
102480 KB |
Output is correct |
78 |
Correct |
1152 ms |
101668 KB |
Output is correct |
79 |
Correct |
833 ms |
88292 KB |
Output is correct |
80 |
Correct |
924 ms |
95460 KB |
Output is correct |