# include <bits/stdc++.h>
#define f first
#define int long long
#define s second
#define pb push_back
#define pii pair <int, int>
using namespace std;
const int N = 1e6 + 5;
stack<int> st;
int n,q,a[N],le[N],ri[N],x[N];
vector <pii> v;
int tree[4*N],l,r,xx,curle,ans[N];
void update(int node, int le, int ri , int idx, int val) {
if (le>idx || ri<idx) return ;
if (le==ri) {
tree[node]=max(tree[node],val);
return;
}
int mid=(le+ri)/2;
update(2*node , le, mid, idx, val);
update(2*node+1, mid+1, ri, idx,val);
tree[node]=max(tree[2*node], tree[2*node+1]);
}
int getans(int node, int le, int ri , int start, int end) {
if (le>end || ri<start) return 0;
if (le>=start && ri<=end) {
return tree[node];
}
int mid=(le+ri)/2;
return max(getans(2*node, le, mid ,start, end), getans(2*node+1, mid+1, ri , start, end));
}
void add(int idx) {
int num = a[idx];
while(st.size() && a[st.top()] < num) {
int x = st.top();
update(1,1,n,x,num + a[st.top()]);
st.pop();
}
st.push(idx);
}
main() {
cin>>n>>q;
for (int i = 1; i <= n ;i++) {
cin>>a[i];
}
for (int i = 1; i <= q; i++) {
cin>>le[i]>>ri[i]>>x[i];
v.pb({le[i],i});
}
sort(v.begin(),v.end());
reverse(v.begin(),v.end());
curle = n;
for (int i = 0; i < v.size(); i++) {
l = le[v[i].s];
r = ri[v[i].s];
xx = x[v[i].s];
while (curle >= l) {
add(curle);
curle--;
}
ans[v[i].s] = (getans(1,1,n,l,r) <= xx);
}
for (int i = 1; i <= q; i++) {
cout<<ans[i]<<" ";
}
}
Compilation message
sortbooks.cpp:41:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
41 | main() {
| ^~~~
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:53:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for (int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
7 ms |
576 KB |
Output is correct |
12 |
Correct |
8 ms |
680 KB |
Output is correct |
13 |
Correct |
7 ms |
748 KB |
Output is correct |
14 |
Correct |
12 ms |
992 KB |
Output is correct |
15 |
Correct |
13 ms |
956 KB |
Output is correct |
16 |
Correct |
7 ms |
844 KB |
Output is correct |
17 |
Correct |
6 ms |
844 KB |
Output is correct |
18 |
Correct |
6 ms |
844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2425 ms |
73600 KB |
Output is correct |
2 |
Correct |
2250 ms |
73560 KB |
Output is correct |
3 |
Correct |
2344 ms |
73552 KB |
Output is correct |
4 |
Correct |
2355 ms |
73632 KB |
Output is correct |
5 |
Correct |
2033 ms |
65332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
183 ms |
8152 KB |
Output is correct |
2 |
Correct |
160 ms |
10132 KB |
Output is correct |
3 |
Correct |
161 ms |
8776 KB |
Output is correct |
4 |
Correct |
150 ms |
8708 KB |
Output is correct |
5 |
Correct |
139 ms |
8796 KB |
Output is correct |
6 |
Correct |
128 ms |
8720 KB |
Output is correct |
7 |
Correct |
144 ms |
8888 KB |
Output is correct |
8 |
Correct |
137 ms |
9520 KB |
Output is correct |
9 |
Correct |
89 ms |
6592 KB |
Output is correct |
10 |
Correct |
132 ms |
9244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
7 ms |
576 KB |
Output is correct |
12 |
Correct |
8 ms |
680 KB |
Output is correct |
13 |
Correct |
7 ms |
748 KB |
Output is correct |
14 |
Correct |
12 ms |
992 KB |
Output is correct |
15 |
Correct |
13 ms |
956 KB |
Output is correct |
16 |
Correct |
7 ms |
844 KB |
Output is correct |
17 |
Correct |
6 ms |
844 KB |
Output is correct |
18 |
Correct |
6 ms |
844 KB |
Output is correct |
19 |
Correct |
480 ms |
22168 KB |
Output is correct |
20 |
Correct |
413 ms |
22476 KB |
Output is correct |
21 |
Correct |
435 ms |
22428 KB |
Output is correct |
22 |
Correct |
409 ms |
22244 KB |
Output is correct |
23 |
Correct |
392 ms |
22300 KB |
Output is correct |
24 |
Correct |
351 ms |
19684 KB |
Output is correct |
25 |
Correct |
367 ms |
19552 KB |
Output is correct |
26 |
Correct |
394 ms |
19724 KB |
Output is correct |
27 |
Correct |
361 ms |
19828 KB |
Output is correct |
28 |
Correct |
391 ms |
19752 KB |
Output is correct |
29 |
Correct |
360 ms |
19856 KB |
Output is correct |
30 |
Correct |
378 ms |
19916 KB |
Output is correct |
31 |
Correct |
406 ms |
19868 KB |
Output is correct |
32 |
Correct |
352 ms |
19844 KB |
Output is correct |
33 |
Correct |
370 ms |
19896 KB |
Output is correct |
34 |
Correct |
398 ms |
19508 KB |
Output is correct |
35 |
Correct |
358 ms |
19476 KB |
Output is correct |
36 |
Correct |
380 ms |
19388 KB |
Output is correct |
37 |
Correct |
393 ms |
19320 KB |
Output is correct |
38 |
Correct |
365 ms |
19624 KB |
Output is correct |
39 |
Correct |
370 ms |
19320 KB |
Output is correct |
40 |
Correct |
288 ms |
16896 KB |
Output is correct |
41 |
Correct |
350 ms |
19384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
7 ms |
576 KB |
Output is correct |
12 |
Correct |
8 ms |
680 KB |
Output is correct |
13 |
Correct |
7 ms |
748 KB |
Output is correct |
14 |
Correct |
12 ms |
992 KB |
Output is correct |
15 |
Correct |
13 ms |
956 KB |
Output is correct |
16 |
Correct |
7 ms |
844 KB |
Output is correct |
17 |
Correct |
6 ms |
844 KB |
Output is correct |
18 |
Correct |
6 ms |
844 KB |
Output is correct |
19 |
Correct |
2425 ms |
73600 KB |
Output is correct |
20 |
Correct |
2250 ms |
73560 KB |
Output is correct |
21 |
Correct |
2344 ms |
73552 KB |
Output is correct |
22 |
Correct |
2355 ms |
73632 KB |
Output is correct |
23 |
Correct |
2033 ms |
65332 KB |
Output is correct |
24 |
Correct |
183 ms |
8152 KB |
Output is correct |
25 |
Correct |
160 ms |
10132 KB |
Output is correct |
26 |
Correct |
161 ms |
8776 KB |
Output is correct |
27 |
Correct |
150 ms |
8708 KB |
Output is correct |
28 |
Correct |
139 ms |
8796 KB |
Output is correct |
29 |
Correct |
128 ms |
8720 KB |
Output is correct |
30 |
Correct |
144 ms |
8888 KB |
Output is correct |
31 |
Correct |
137 ms |
9520 KB |
Output is correct |
32 |
Correct |
89 ms |
6592 KB |
Output is correct |
33 |
Correct |
132 ms |
9244 KB |
Output is correct |
34 |
Correct |
480 ms |
22168 KB |
Output is correct |
35 |
Correct |
413 ms |
22476 KB |
Output is correct |
36 |
Correct |
435 ms |
22428 KB |
Output is correct |
37 |
Correct |
409 ms |
22244 KB |
Output is correct |
38 |
Correct |
392 ms |
22300 KB |
Output is correct |
39 |
Correct |
351 ms |
19684 KB |
Output is correct |
40 |
Correct |
367 ms |
19552 KB |
Output is correct |
41 |
Correct |
394 ms |
19724 KB |
Output is correct |
42 |
Correct |
361 ms |
19828 KB |
Output is correct |
43 |
Correct |
391 ms |
19752 KB |
Output is correct |
44 |
Correct |
360 ms |
19856 KB |
Output is correct |
45 |
Correct |
378 ms |
19916 KB |
Output is correct |
46 |
Correct |
406 ms |
19868 KB |
Output is correct |
47 |
Correct |
352 ms |
19844 KB |
Output is correct |
48 |
Correct |
370 ms |
19896 KB |
Output is correct |
49 |
Correct |
398 ms |
19508 KB |
Output is correct |
50 |
Correct |
358 ms |
19476 KB |
Output is correct |
51 |
Correct |
380 ms |
19388 KB |
Output is correct |
52 |
Correct |
393 ms |
19320 KB |
Output is correct |
53 |
Correct |
365 ms |
19624 KB |
Output is correct |
54 |
Correct |
370 ms |
19320 KB |
Output is correct |
55 |
Correct |
288 ms |
16896 KB |
Output is correct |
56 |
Correct |
350 ms |
19384 KB |
Output is correct |
57 |
Correct |
2309 ms |
107164 KB |
Output is correct |
58 |
Correct |
2545 ms |
90400 KB |
Output is correct |
59 |
Correct |
2630 ms |
90384 KB |
Output is correct |
60 |
Correct |
2465 ms |
90376 KB |
Output is correct |
61 |
Correct |
2322 ms |
90468 KB |
Output is correct |
62 |
Correct |
2296 ms |
90372 KB |
Output is correct |
63 |
Correct |
2055 ms |
85464 KB |
Output is correct |
64 |
Correct |
1970 ms |
85312 KB |
Output is correct |
65 |
Correct |
2089 ms |
82104 KB |
Output is correct |
66 |
Correct |
2067 ms |
98632 KB |
Output is correct |
67 |
Correct |
2005 ms |
74324 KB |
Output is correct |
68 |
Correct |
2108 ms |
78484 KB |
Output is correct |
69 |
Correct |
2079 ms |
98864 KB |
Output is correct |
70 |
Correct |
2062 ms |
98776 KB |
Output is correct |
71 |
Correct |
2081 ms |
79324 KB |
Output is correct |
72 |
Correct |
2083 ms |
90832 KB |
Output is correct |
73 |
Correct |
1912 ms |
95408 KB |
Output is correct |
74 |
Correct |
1866 ms |
79444 KB |
Output is correct |
75 |
Correct |
2150 ms |
76656 KB |
Output is correct |
76 |
Correct |
2219 ms |
74620 KB |
Output is correct |
77 |
Correct |
2156 ms |
74848 KB |
Output is correct |
78 |
Correct |
2251 ms |
77244 KB |
Output is correct |
79 |
Correct |
1930 ms |
81204 KB |
Output is correct |
80 |
Correct |
2481 ms |
81080 KB |
Output is correct |