#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
const int N=1e6+10;
using namespace std;
int n,m,a[N],res[N];
struct query
{
int id,l,r,lim;
bool operator<(const query &x)const
{
return l>x.l;
}
};
int bit[N];
void update(int id,int val)
{
while(id<=n)
{
bit[id]=max(bit[id],val);
id+=id&-id;
}
}
int get(int id)
{
int kq=0;
while(id>0)
{
kq=max(kq,bit[id]);
id-=id&-id;
}
return kq;
}
vector<query>q;
stack<int>st;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
q.resize(m);
for(int i=1; i<=n; i++) cin>>a[i];
for(int i=0; i<=m-1; i++)
{
cin>>q[i].l>>q[i].r>>q[i].lim;
q[i].id=i;
}
sort(q.begin(),q.end());
int now=n+1;
for(auto [id,l,r,lim]:q)
{
while(now>l)
{
now--;
while(st.size()&&a[st.top()]<a[now])
{
int x=st.top();
update(x,a[now]+a[x]);
st.pop();
}
while(st.size()&&a[st.top()]==a[now]) st.pop();
st.push(now);
}
res[id]=(get(r)<=lim);
}
for(int i=0; i<=m-1; i++) cout<<res[i]<<endl;
}
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:52:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
52 | for(auto [id,l,r,lim]:q)
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
464 KB |
Output is correct |
13 |
Correct |
5 ms |
468 KB |
Output is correct |
14 |
Correct |
7 ms |
596 KB |
Output is correct |
15 |
Correct |
7 ms |
528 KB |
Output is correct |
16 |
Correct |
7 ms |
596 KB |
Output is correct |
17 |
Correct |
9 ms |
468 KB |
Output is correct |
18 |
Correct |
7 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1388 ms |
29796 KB |
Output is correct |
2 |
Correct |
1387 ms |
29624 KB |
Output is correct |
3 |
Correct |
1379 ms |
29756 KB |
Output is correct |
4 |
Correct |
1396 ms |
29748 KB |
Output is correct |
5 |
Correct |
1359 ms |
29904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
131 ms |
3192 KB |
Output is correct |
2 |
Correct |
134 ms |
5172 KB |
Output is correct |
3 |
Correct |
131 ms |
4844 KB |
Output is correct |
4 |
Correct |
132 ms |
4868 KB |
Output is correct |
5 |
Correct |
129 ms |
4832 KB |
Output is correct |
6 |
Correct |
125 ms |
4680 KB |
Output is correct |
7 |
Correct |
124 ms |
4752 KB |
Output is correct |
8 |
Correct |
134 ms |
4844 KB |
Output is correct |
9 |
Correct |
119 ms |
3788 KB |
Output is correct |
10 |
Correct |
125 ms |
4472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
464 KB |
Output is correct |
13 |
Correct |
5 ms |
468 KB |
Output is correct |
14 |
Correct |
7 ms |
596 KB |
Output is correct |
15 |
Correct |
7 ms |
528 KB |
Output is correct |
16 |
Correct |
7 ms |
596 KB |
Output is correct |
17 |
Correct |
9 ms |
468 KB |
Output is correct |
18 |
Correct |
7 ms |
468 KB |
Output is correct |
19 |
Correct |
282 ms |
12800 KB |
Output is correct |
20 |
Correct |
273 ms |
12804 KB |
Output is correct |
21 |
Correct |
271 ms |
12624 KB |
Output is correct |
22 |
Correct |
272 ms |
12620 KB |
Output is correct |
23 |
Correct |
269 ms |
12552 KB |
Output is correct |
24 |
Correct |
269 ms |
12600 KB |
Output is correct |
25 |
Correct |
265 ms |
12564 KB |
Output is correct |
26 |
Correct |
274 ms |
12888 KB |
Output is correct |
27 |
Correct |
270 ms |
12748 KB |
Output is correct |
28 |
Correct |
269 ms |
12688 KB |
Output is correct |
29 |
Correct |
284 ms |
12832 KB |
Output is correct |
30 |
Correct |
272 ms |
12748 KB |
Output is correct |
31 |
Correct |
279 ms |
12772 KB |
Output is correct |
32 |
Correct |
278 ms |
12828 KB |
Output is correct |
33 |
Correct |
272 ms |
12836 KB |
Output is correct |
34 |
Correct |
262 ms |
12476 KB |
Output is correct |
35 |
Correct |
259 ms |
12588 KB |
Output is correct |
36 |
Correct |
265 ms |
12372 KB |
Output is correct |
37 |
Correct |
264 ms |
12268 KB |
Output is correct |
38 |
Correct |
261 ms |
12448 KB |
Output is correct |
39 |
Correct |
261 ms |
11400 KB |
Output is correct |
40 |
Correct |
249 ms |
10100 KB |
Output is correct |
41 |
Correct |
263 ms |
10124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
464 KB |
Output is correct |
13 |
Correct |
5 ms |
468 KB |
Output is correct |
14 |
Correct |
7 ms |
596 KB |
Output is correct |
15 |
Correct |
7 ms |
528 KB |
Output is correct |
16 |
Correct |
7 ms |
596 KB |
Output is correct |
17 |
Correct |
9 ms |
468 KB |
Output is correct |
18 |
Correct |
7 ms |
468 KB |
Output is correct |
19 |
Correct |
1388 ms |
29796 KB |
Output is correct |
20 |
Correct |
1387 ms |
29624 KB |
Output is correct |
21 |
Correct |
1379 ms |
29756 KB |
Output is correct |
22 |
Correct |
1396 ms |
29748 KB |
Output is correct |
23 |
Correct |
1359 ms |
29904 KB |
Output is correct |
24 |
Correct |
131 ms |
3192 KB |
Output is correct |
25 |
Correct |
134 ms |
5172 KB |
Output is correct |
26 |
Correct |
131 ms |
4844 KB |
Output is correct |
27 |
Correct |
132 ms |
4868 KB |
Output is correct |
28 |
Correct |
129 ms |
4832 KB |
Output is correct |
29 |
Correct |
125 ms |
4680 KB |
Output is correct |
30 |
Correct |
124 ms |
4752 KB |
Output is correct |
31 |
Correct |
134 ms |
4844 KB |
Output is correct |
32 |
Correct |
119 ms |
3788 KB |
Output is correct |
33 |
Correct |
125 ms |
4472 KB |
Output is correct |
34 |
Correct |
282 ms |
12800 KB |
Output is correct |
35 |
Correct |
273 ms |
12804 KB |
Output is correct |
36 |
Correct |
271 ms |
12624 KB |
Output is correct |
37 |
Correct |
272 ms |
12620 KB |
Output is correct |
38 |
Correct |
269 ms |
12552 KB |
Output is correct |
39 |
Correct |
269 ms |
12600 KB |
Output is correct |
40 |
Correct |
265 ms |
12564 KB |
Output is correct |
41 |
Correct |
274 ms |
12888 KB |
Output is correct |
42 |
Correct |
270 ms |
12748 KB |
Output is correct |
43 |
Correct |
269 ms |
12688 KB |
Output is correct |
44 |
Correct |
284 ms |
12832 KB |
Output is correct |
45 |
Correct |
272 ms |
12748 KB |
Output is correct |
46 |
Correct |
279 ms |
12772 KB |
Output is correct |
47 |
Correct |
278 ms |
12828 KB |
Output is correct |
48 |
Correct |
272 ms |
12836 KB |
Output is correct |
49 |
Correct |
262 ms |
12476 KB |
Output is correct |
50 |
Correct |
259 ms |
12588 KB |
Output is correct |
51 |
Correct |
265 ms |
12372 KB |
Output is correct |
52 |
Correct |
264 ms |
12268 KB |
Output is correct |
53 |
Correct |
261 ms |
12448 KB |
Output is correct |
54 |
Correct |
261 ms |
11400 KB |
Output is correct |
55 |
Correct |
249 ms |
10100 KB |
Output is correct |
56 |
Correct |
263 ms |
10124 KB |
Output is correct |
57 |
Correct |
1390 ms |
63284 KB |
Output is correct |
58 |
Correct |
1406 ms |
63328 KB |
Output is correct |
59 |
Correct |
1413 ms |
63324 KB |
Output is correct |
60 |
Correct |
1389 ms |
63248 KB |
Output is correct |
61 |
Correct |
1421 ms |
63176 KB |
Output is correct |
62 |
Correct |
1401 ms |
63244 KB |
Output is correct |
63 |
Correct |
1331 ms |
61468 KB |
Output is correct |
64 |
Correct |
1338 ms |
61484 KB |
Output is correct |
65 |
Correct |
1387 ms |
63340 KB |
Output is correct |
66 |
Correct |
1355 ms |
63420 KB |
Output is correct |
67 |
Correct |
1366 ms |
63436 KB |
Output is correct |
68 |
Correct |
1372 ms |
63588 KB |
Output is correct |
69 |
Correct |
1367 ms |
63468 KB |
Output is correct |
70 |
Correct |
1364 ms |
63512 KB |
Output is correct |
71 |
Correct |
1400 ms |
63472 KB |
Output is correct |
72 |
Correct |
1418 ms |
63544 KB |
Output is correct |
73 |
Correct |
1345 ms |
59960 KB |
Output is correct |
74 |
Correct |
1333 ms |
61288 KB |
Output is correct |
75 |
Correct |
1327 ms |
60024 KB |
Output is correct |
76 |
Correct |
1347 ms |
60052 KB |
Output is correct |
77 |
Correct |
1336 ms |
60224 KB |
Output is correct |
78 |
Correct |
1351 ms |
57408 KB |
Output is correct |
79 |
Correct |
1285 ms |
48688 KB |
Output is correct |
80 |
Correct |
1310 ms |
50516 KB |
Output is correct |