#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <stack>
#include <queue>
#include <deque>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
// template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define show(a) cerr << #a <<" -> "<< a <<" "
#define nl cerr <<"\n"
//#define int ll
const int N = (1 << 20) - 1;
int n, m, a[N], ans[N], t[N*2];
vector < pair <int, pii> > que[N];
stack <int> st;
void upd(int pos, int x) {
pos += N;
t[pos] = max(t[pos], x);
while ((pos /= 2) >= 1) {
t[pos] = max(t[pos*2], t[pos*2+1]);
}
}
int get(int l, int r) {
int res = 0;
for (l += N, r += N; l <= r; l /= 2, r /= 2) {
if (l % 2 == 1) { res = max(res, t[l++]); }
if (r % 2 == 0) { res = max(res, t[r--]); }
if (l > r) { break; }
}
return res;
}
void solve() {
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int i = 1; i <= m; ++i) {
int l, r, k;
cin >> l >> r >> k;
que[r].pb({l, {k, i}});
}
for (int i = 1; i <= n; ++i) {
while (sz(st) && a[st.top()] <= a[i]) { st.pop(); }
if (sz(st)) { upd(st.top(), a[st.top()] + a[i]); }
st.push(i);
for (int j = 0; j < sz(que[i]); ++j) {
int l = que[i][j].F, k = que[i][j].S.F, id = que[i][j].S.S;
ans[id] = (get(l, i) <= k);
}
}
for (int i = 1; i <= m; ++i) { cout << ans[i] <<"\n"; }
}
main () {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tests = 1;
//cin >> tests;
while (tests --) {
solve();
}
return 0;
}
/*
Just Chalish!
*/
Compilation message
sortbooks.cpp:85:8: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
85 | main () {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
25068 KB |
Output is correct |
2 |
Correct |
15 ms |
24940 KB |
Output is correct |
3 |
Correct |
15 ms |
25068 KB |
Output is correct |
4 |
Correct |
15 ms |
25068 KB |
Output is correct |
5 |
Correct |
16 ms |
25072 KB |
Output is correct |
6 |
Correct |
15 ms |
25068 KB |
Output is correct |
7 |
Correct |
15 ms |
25068 KB |
Output is correct |
8 |
Correct |
16 ms |
25068 KB |
Output is correct |
9 |
Correct |
16 ms |
25068 KB |
Output is correct |
10 |
Correct |
16 ms |
25088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
25068 KB |
Output is correct |
2 |
Correct |
15 ms |
24940 KB |
Output is correct |
3 |
Correct |
15 ms |
25068 KB |
Output is correct |
4 |
Correct |
15 ms |
25068 KB |
Output is correct |
5 |
Correct |
16 ms |
25072 KB |
Output is correct |
6 |
Correct |
15 ms |
25068 KB |
Output is correct |
7 |
Correct |
15 ms |
25068 KB |
Output is correct |
8 |
Correct |
16 ms |
25068 KB |
Output is correct |
9 |
Correct |
16 ms |
25068 KB |
Output is correct |
10 |
Correct |
16 ms |
25088 KB |
Output is correct |
11 |
Correct |
17 ms |
25196 KB |
Output is correct |
12 |
Correct |
18 ms |
25472 KB |
Output is correct |
13 |
Correct |
18 ms |
25324 KB |
Output is correct |
14 |
Correct |
20 ms |
25452 KB |
Output is correct |
15 |
Correct |
20 ms |
25452 KB |
Output is correct |
16 |
Correct |
19 ms |
25356 KB |
Output is correct |
17 |
Correct |
18 ms |
25324 KB |
Output is correct |
18 |
Correct |
18 ms |
25324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1231 ms |
64876 KB |
Output is correct |
2 |
Correct |
1232 ms |
65004 KB |
Output is correct |
3 |
Correct |
1290 ms |
64876 KB |
Output is correct |
4 |
Correct |
1262 ms |
65100 KB |
Output is correct |
5 |
Correct |
1097 ms |
57196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
30316 KB |
Output is correct |
2 |
Correct |
92 ms |
30716 KB |
Output is correct |
3 |
Correct |
91 ms |
30060 KB |
Output is correct |
4 |
Correct |
91 ms |
30060 KB |
Output is correct |
5 |
Correct |
96 ms |
30108 KB |
Output is correct |
6 |
Correct |
84 ms |
29612 KB |
Output is correct |
7 |
Correct |
76 ms |
29548 KB |
Output is correct |
8 |
Correct |
91 ms |
29732 KB |
Output is correct |
9 |
Correct |
56 ms |
28452 KB |
Output is correct |
10 |
Correct |
91 ms |
29732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
25068 KB |
Output is correct |
2 |
Correct |
15 ms |
24940 KB |
Output is correct |
3 |
Correct |
15 ms |
25068 KB |
Output is correct |
4 |
Correct |
15 ms |
25068 KB |
Output is correct |
5 |
Correct |
16 ms |
25072 KB |
Output is correct |
6 |
Correct |
15 ms |
25068 KB |
Output is correct |
7 |
Correct |
15 ms |
25068 KB |
Output is correct |
8 |
Correct |
16 ms |
25068 KB |
Output is correct |
9 |
Correct |
16 ms |
25068 KB |
Output is correct |
10 |
Correct |
16 ms |
25088 KB |
Output is correct |
11 |
Correct |
17 ms |
25196 KB |
Output is correct |
12 |
Correct |
18 ms |
25472 KB |
Output is correct |
13 |
Correct |
18 ms |
25324 KB |
Output is correct |
14 |
Correct |
20 ms |
25452 KB |
Output is correct |
15 |
Correct |
20 ms |
25452 KB |
Output is correct |
16 |
Correct |
19 ms |
25356 KB |
Output is correct |
17 |
Correct |
18 ms |
25324 KB |
Output is correct |
18 |
Correct |
18 ms |
25324 KB |
Output is correct |
19 |
Correct |
231 ms |
39532 KB |
Output is correct |
20 |
Correct |
221 ms |
39404 KB |
Output is correct |
21 |
Correct |
190 ms |
38764 KB |
Output is correct |
22 |
Correct |
196 ms |
38892 KB |
Output is correct |
23 |
Correct |
237 ms |
38764 KB |
Output is correct |
24 |
Correct |
163 ms |
37128 KB |
Output is correct |
25 |
Correct |
161 ms |
36972 KB |
Output is correct |
26 |
Correct |
194 ms |
37356 KB |
Output is correct |
27 |
Correct |
193 ms |
37356 KB |
Output is correct |
28 |
Correct |
223 ms |
37484 KB |
Output is correct |
29 |
Correct |
201 ms |
37868 KB |
Output is correct |
30 |
Correct |
202 ms |
37868 KB |
Output is correct |
31 |
Correct |
208 ms |
37740 KB |
Output is correct |
32 |
Correct |
207 ms |
37868 KB |
Output is correct |
33 |
Correct |
212 ms |
37740 KB |
Output is correct |
34 |
Correct |
158 ms |
36588 KB |
Output is correct |
35 |
Correct |
158 ms |
36716 KB |
Output is correct |
36 |
Correct |
148 ms |
36460 KB |
Output is correct |
37 |
Correct |
148 ms |
36460 KB |
Output is correct |
38 |
Correct |
154 ms |
36588 KB |
Output is correct |
39 |
Correct |
191 ms |
36564 KB |
Output is correct |
40 |
Correct |
150 ms |
34872 KB |
Output is correct |
41 |
Correct |
181 ms |
35616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
25068 KB |
Output is correct |
2 |
Correct |
15 ms |
24940 KB |
Output is correct |
3 |
Correct |
15 ms |
25068 KB |
Output is correct |
4 |
Correct |
15 ms |
25068 KB |
Output is correct |
5 |
Correct |
16 ms |
25072 KB |
Output is correct |
6 |
Correct |
15 ms |
25068 KB |
Output is correct |
7 |
Correct |
15 ms |
25068 KB |
Output is correct |
8 |
Correct |
16 ms |
25068 KB |
Output is correct |
9 |
Correct |
16 ms |
25068 KB |
Output is correct |
10 |
Correct |
16 ms |
25088 KB |
Output is correct |
11 |
Correct |
17 ms |
25196 KB |
Output is correct |
12 |
Correct |
18 ms |
25472 KB |
Output is correct |
13 |
Correct |
18 ms |
25324 KB |
Output is correct |
14 |
Correct |
20 ms |
25452 KB |
Output is correct |
15 |
Correct |
20 ms |
25452 KB |
Output is correct |
16 |
Correct |
19 ms |
25356 KB |
Output is correct |
17 |
Correct |
18 ms |
25324 KB |
Output is correct |
18 |
Correct |
18 ms |
25324 KB |
Output is correct |
19 |
Correct |
1231 ms |
64876 KB |
Output is correct |
20 |
Correct |
1232 ms |
65004 KB |
Output is correct |
21 |
Correct |
1290 ms |
64876 KB |
Output is correct |
22 |
Correct |
1262 ms |
65100 KB |
Output is correct |
23 |
Correct |
1097 ms |
57196 KB |
Output is correct |
24 |
Correct |
100 ms |
30316 KB |
Output is correct |
25 |
Correct |
92 ms |
30716 KB |
Output is correct |
26 |
Correct |
91 ms |
30060 KB |
Output is correct |
27 |
Correct |
91 ms |
30060 KB |
Output is correct |
28 |
Correct |
96 ms |
30108 KB |
Output is correct |
29 |
Correct |
84 ms |
29612 KB |
Output is correct |
30 |
Correct |
76 ms |
29548 KB |
Output is correct |
31 |
Correct |
91 ms |
29732 KB |
Output is correct |
32 |
Correct |
56 ms |
28452 KB |
Output is correct |
33 |
Correct |
91 ms |
29732 KB |
Output is correct |
34 |
Correct |
231 ms |
39532 KB |
Output is correct |
35 |
Correct |
221 ms |
39404 KB |
Output is correct |
36 |
Correct |
190 ms |
38764 KB |
Output is correct |
37 |
Correct |
196 ms |
38892 KB |
Output is correct |
38 |
Correct |
237 ms |
38764 KB |
Output is correct |
39 |
Correct |
163 ms |
37128 KB |
Output is correct |
40 |
Correct |
161 ms |
36972 KB |
Output is correct |
41 |
Correct |
194 ms |
37356 KB |
Output is correct |
42 |
Correct |
193 ms |
37356 KB |
Output is correct |
43 |
Correct |
223 ms |
37484 KB |
Output is correct |
44 |
Correct |
201 ms |
37868 KB |
Output is correct |
45 |
Correct |
202 ms |
37868 KB |
Output is correct |
46 |
Correct |
208 ms |
37740 KB |
Output is correct |
47 |
Correct |
207 ms |
37868 KB |
Output is correct |
48 |
Correct |
212 ms |
37740 KB |
Output is correct |
49 |
Correct |
158 ms |
36588 KB |
Output is correct |
50 |
Correct |
158 ms |
36716 KB |
Output is correct |
51 |
Correct |
148 ms |
36460 KB |
Output is correct |
52 |
Correct |
148 ms |
36460 KB |
Output is correct |
53 |
Correct |
154 ms |
36588 KB |
Output is correct |
54 |
Correct |
191 ms |
36564 KB |
Output is correct |
55 |
Correct |
150 ms |
34872 KB |
Output is correct |
56 |
Correct |
181 ms |
35616 KB |
Output is correct |
57 |
Correct |
1234 ms |
64876 KB |
Output is correct |
58 |
Correct |
1236 ms |
65004 KB |
Output is correct |
59 |
Correct |
1168 ms |
63336 KB |
Output is correct |
60 |
Correct |
1192 ms |
63476 KB |
Output is correct |
61 |
Correct |
1173 ms |
63444 KB |
Output is correct |
62 |
Correct |
1175 ms |
63668 KB |
Output is correct |
63 |
Correct |
736 ms |
53848 KB |
Output is correct |
64 |
Correct |
790 ms |
53740 KB |
Output is correct |
65 |
Correct |
1020 ms |
55560 KB |
Output is correct |
66 |
Correct |
1031 ms |
55436 KB |
Output is correct |
67 |
Correct |
1008 ms |
55404 KB |
Output is correct |
68 |
Correct |
1060 ms |
57068 KB |
Output is correct |
69 |
Correct |
1066 ms |
57068 KB |
Output is correct |
70 |
Correct |
1076 ms |
56760 KB |
Output is correct |
71 |
Correct |
1061 ms |
56684 KB |
Output is correct |
72 |
Correct |
1067 ms |
56844 KB |
Output is correct |
73 |
Correct |
662 ms |
51436 KB |
Output is correct |
74 |
Correct |
711 ms |
51180 KB |
Output is correct |
75 |
Correct |
661 ms |
51564 KB |
Output is correct |
76 |
Correct |
655 ms |
51564 KB |
Output is correct |
77 |
Correct |
672 ms |
51480 KB |
Output is correct |
78 |
Correct |
957 ms |
57500 KB |
Output is correct |
79 |
Correct |
743 ms |
51184 KB |
Output is correct |
80 |
Correct |
1004 ms |
54792 KB |
Output is correct |