#include <bits/stdc++.h>
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
#define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
#define per(i,r,l) for(int i = (r); i >= (l); i--)
#define rep(i,l,r) for(int i = (l); i < (r); i++)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ss second
#define ff first
void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 1e6 + 5, lg = 22, lng = 26, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}
int fen[maxn], n;
void upd(int i, int k){
for(i++; i <= n; i += i&-i) fen[i] = max(fen[i], k);
}
int get(int i){
int res = -1;
for(; i; i -= i&-i) res = max(res, fen[i]);
return res;
}
int main(){
cin.tie(0) -> sync_with_stdio(0);
int q; cin >> n >> q;
vector<int> w(n);
rep(i,0,n){
cin >> w[i];
}
struct tr{
int r, id, k;
};
vector<vector<tr>> query(n);
rep(i,0,q){
int l, r, k; cin >> l >> r >> k; l--;
query[l].pb({r, i, k});
}
fill(fen, fen+n+1, -1);
vector<int> st;
vector<bool> ans(q);
per(i,n-1,0){
while(sz(st) && w[st.back()] < w[i]){
upd(st.back(), w[st.back()] + w[i]);
st.pop_back();
}
st.pb(i);
for(auto[r, id, k]: query[i]){
ans[id] = get(r) <= k;
}
}
for(auto c: ans) cout << c << '\n';
return 0;
}
/*
5 2
3 5 1 8 2
1 3 6
2 5 3
*/
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:54:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
54 | for(auto[r, id, k]: query[i]){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 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 |
348 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 |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 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 |
348 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 |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
480 KB |
Output is correct |
12 |
Correct |
2 ms |
596 KB |
Output is correct |
13 |
Correct |
2 ms |
596 KB |
Output is correct |
14 |
Correct |
3 ms |
692 KB |
Output is correct |
15 |
Correct |
5 ms |
648 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
3 ms |
596 KB |
Output is correct |
18 |
Correct |
3 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
787 ms |
55892 KB |
Output is correct |
2 |
Correct |
798 ms |
56460 KB |
Output is correct |
3 |
Correct |
800 ms |
56340 KB |
Output is correct |
4 |
Correct |
794 ms |
56296 KB |
Output is correct |
5 |
Correct |
765 ms |
60596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
6112 KB |
Output is correct |
2 |
Correct |
52 ms |
6184 KB |
Output is correct |
3 |
Correct |
56 ms |
6872 KB |
Output is correct |
4 |
Correct |
58 ms |
6908 KB |
Output is correct |
5 |
Correct |
49 ms |
6860 KB |
Output is correct |
6 |
Correct |
40 ms |
6352 KB |
Output is correct |
7 |
Correct |
41 ms |
6376 KB |
Output is correct |
8 |
Correct |
51 ms |
6440 KB |
Output is correct |
9 |
Correct |
29 ms |
2484 KB |
Output is correct |
10 |
Correct |
46 ms |
6560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 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 |
348 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 |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
480 KB |
Output is correct |
12 |
Correct |
2 ms |
596 KB |
Output is correct |
13 |
Correct |
2 ms |
596 KB |
Output is correct |
14 |
Correct |
3 ms |
692 KB |
Output is correct |
15 |
Correct |
5 ms |
648 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
3 ms |
596 KB |
Output is correct |
18 |
Correct |
3 ms |
724 KB |
Output is correct |
19 |
Correct |
138 ms |
12492 KB |
Output is correct |
20 |
Correct |
133 ms |
12516 KB |
Output is correct |
21 |
Correct |
123 ms |
11976 KB |
Output is correct |
22 |
Correct |
114 ms |
12068 KB |
Output is correct |
23 |
Correct |
119 ms |
12172 KB |
Output is correct |
24 |
Correct |
103 ms |
12876 KB |
Output is correct |
25 |
Correct |
111 ms |
12840 KB |
Output is correct |
26 |
Correct |
122 ms |
12948 KB |
Output is correct |
27 |
Correct |
124 ms |
13000 KB |
Output is correct |
28 |
Correct |
118 ms |
13068 KB |
Output is correct |
29 |
Correct |
127 ms |
13380 KB |
Output is correct |
30 |
Correct |
147 ms |
13396 KB |
Output is correct |
31 |
Correct |
136 ms |
13376 KB |
Output is correct |
32 |
Correct |
139 ms |
13404 KB |
Output is correct |
33 |
Correct |
124 ms |
13296 KB |
Output is correct |
34 |
Correct |
97 ms |
12296 KB |
Output is correct |
35 |
Correct |
100 ms |
12240 KB |
Output is correct |
36 |
Correct |
93 ms |
12176 KB |
Output is correct |
37 |
Correct |
92 ms |
12224 KB |
Output is correct |
38 |
Correct |
100 ms |
12236 KB |
Output is correct |
39 |
Correct |
108 ms |
12800 KB |
Output is correct |
40 |
Correct |
95 ms |
10092 KB |
Output is correct |
41 |
Correct |
121 ms |
12500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 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 |
348 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 |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
480 KB |
Output is correct |
12 |
Correct |
2 ms |
596 KB |
Output is correct |
13 |
Correct |
2 ms |
596 KB |
Output is correct |
14 |
Correct |
3 ms |
692 KB |
Output is correct |
15 |
Correct |
5 ms |
648 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
3 ms |
596 KB |
Output is correct |
18 |
Correct |
3 ms |
724 KB |
Output is correct |
19 |
Correct |
787 ms |
55892 KB |
Output is correct |
20 |
Correct |
798 ms |
56460 KB |
Output is correct |
21 |
Correct |
800 ms |
56340 KB |
Output is correct |
22 |
Correct |
794 ms |
56296 KB |
Output is correct |
23 |
Correct |
765 ms |
60596 KB |
Output is correct |
24 |
Correct |
52 ms |
6112 KB |
Output is correct |
25 |
Correct |
52 ms |
6184 KB |
Output is correct |
26 |
Correct |
56 ms |
6872 KB |
Output is correct |
27 |
Correct |
58 ms |
6908 KB |
Output is correct |
28 |
Correct |
49 ms |
6860 KB |
Output is correct |
29 |
Correct |
40 ms |
6352 KB |
Output is correct |
30 |
Correct |
41 ms |
6376 KB |
Output is correct |
31 |
Correct |
51 ms |
6440 KB |
Output is correct |
32 |
Correct |
29 ms |
2484 KB |
Output is correct |
33 |
Correct |
46 ms |
6560 KB |
Output is correct |
34 |
Correct |
138 ms |
12492 KB |
Output is correct |
35 |
Correct |
133 ms |
12516 KB |
Output is correct |
36 |
Correct |
123 ms |
11976 KB |
Output is correct |
37 |
Correct |
114 ms |
12068 KB |
Output is correct |
38 |
Correct |
119 ms |
12172 KB |
Output is correct |
39 |
Correct |
103 ms |
12876 KB |
Output is correct |
40 |
Correct |
111 ms |
12840 KB |
Output is correct |
41 |
Correct |
122 ms |
12948 KB |
Output is correct |
42 |
Correct |
124 ms |
13000 KB |
Output is correct |
43 |
Correct |
118 ms |
13068 KB |
Output is correct |
44 |
Correct |
127 ms |
13380 KB |
Output is correct |
45 |
Correct |
147 ms |
13396 KB |
Output is correct |
46 |
Correct |
136 ms |
13376 KB |
Output is correct |
47 |
Correct |
139 ms |
13404 KB |
Output is correct |
48 |
Correct |
124 ms |
13296 KB |
Output is correct |
49 |
Correct |
97 ms |
12296 KB |
Output is correct |
50 |
Correct |
100 ms |
12240 KB |
Output is correct |
51 |
Correct |
93 ms |
12176 KB |
Output is correct |
52 |
Correct |
92 ms |
12224 KB |
Output is correct |
53 |
Correct |
100 ms |
12236 KB |
Output is correct |
54 |
Correct |
108 ms |
12800 KB |
Output is correct |
55 |
Correct |
95 ms |
10092 KB |
Output is correct |
56 |
Correct |
121 ms |
12500 KB |
Output is correct |
57 |
Correct |
823 ms |
57224 KB |
Output is correct |
58 |
Correct |
802 ms |
57232 KB |
Output is correct |
59 |
Correct |
759 ms |
55372 KB |
Output is correct |
60 |
Correct |
756 ms |
55380 KB |
Output is correct |
61 |
Correct |
763 ms |
55220 KB |
Output is correct |
62 |
Correct |
759 ms |
55340 KB |
Output is correct |
63 |
Correct |
493 ms |
55604 KB |
Output is correct |
64 |
Correct |
499 ms |
55400 KB |
Output is correct |
65 |
Correct |
728 ms |
59180 KB |
Output is correct |
66 |
Correct |
768 ms |
59188 KB |
Output is correct |
67 |
Correct |
731 ms |
59128 KB |
Output is correct |
68 |
Correct |
774 ms |
61108 KB |
Output is correct |
69 |
Correct |
778 ms |
61252 KB |
Output is correct |
70 |
Correct |
775 ms |
60512 KB |
Output is correct |
71 |
Correct |
768 ms |
60596 KB |
Output is correct |
72 |
Correct |
775 ms |
60748 KB |
Output is correct |
73 |
Correct |
457 ms |
54432 KB |
Output is correct |
74 |
Correct |
487 ms |
54360 KB |
Output is correct |
75 |
Correct |
453 ms |
54428 KB |
Output is correct |
76 |
Correct |
451 ms |
53940 KB |
Output is correct |
77 |
Correct |
457 ms |
54288 KB |
Output is correct |
78 |
Correct |
636 ms |
57424 KB |
Output is correct |
79 |
Correct |
501 ms |
39556 KB |
Output is correct |
80 |
Correct |
632 ms |
56416 KB |
Output is correct |