// Nurstan Duisengaliev(REALBOY)
// не, не надо меня узнавать
/*#pragma GCC target ("avx2")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")*/
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define all(x) x.begin(), x.end()
#define in insert
#define mp make_pair
#define F first
#define S second
#define ppf pop_front
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair <int, int>
#define pll pair <ll, ll>
#define boost() ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) (int)x.size()
using namespace std;
//using namespace __gnu_pbds;
//template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = (int)1e6 + 123;
const int mod = (int)1e9 + 7;
const ll INF = (ll)1e18 + 1;
int n, Q;
int a[N], ans[N];
struct st {
int l, k, id;
};
vector <st> q[N];
int d[N * 4];
void update (int v, int l, int r, int pos, int x) {
if (l == r) {
d[v] = max (d[v], x);
return;
}
int mid = l + r >> 1;
if (pos <= mid) update (v * 2, l, mid, pos, x);
else update (v * 2 + 1, mid + 1, r, pos, x);
d[v] = max (d[v * 2], d[v * 2 + 1]);
}
int get (int v, int l, int r, int nl, int nr) {
if (nl > r || l > nr) return 0;
if (nl <= l && r <= nr) return d[v];
int mid = l + r >> 1;
return max (get (v * 2, l, mid, nl, nr), get (v * 2 + 1, mid + 1, r, nl, nr));
}
void solve () {
cin >> n >> Q;
for (int i = 1; i <= n; i ++) cin >> a[i];
for (int i = 1; i <= Q; i ++) {
int l, r, k;
cin >> l >> r >> k;
q[r].pb ({l, k, i});
}
stack <int> s;
for (int i = 1; i <= n; i ++) {
while (sz (s) && a[s.top()] <= a[i]) s.pop();
if (sz (s) != 0) {
update (1, 1, n, s.top(), a[s.top()] + a[i]);
}
s.push (i);
for (auto it : q[i]) {
if (get (1, 1, n, it.l, i) > it.k) ans[it.id] = 0;
else ans[it.id] = 1;
}
}
for (int i = 1; i <= Q; i ++) {
cout << ans[i] << '\n';
}
}
main () {
// freopen (".in", "r", stdin);
// freopen (".out", "w", stdout);
boost ();
int TT = 1;
// cin >> TT;
while (TT --) {
solve ();
}
return 0;
}
Compilation message
sortbooks.cpp: In function 'void update(int, int, int, int, int)':
sortbooks.cpp:48:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
48 | int mid = l + r >> 1;
| ~~^~~
sortbooks.cpp: In function 'int get(int, int, int, int, int)':
sortbooks.cpp:56:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
56 | int mid = l + r >> 1;
| ~~^~~
sortbooks.cpp: At global scope:
sortbooks.cpp:84:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
84 | main () {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
17 ms |
23916 KB |
Output is correct |
4 |
Correct |
16 ms |
23916 KB |
Output is correct |
5 |
Correct |
17 ms |
23936 KB |
Output is correct |
6 |
Correct |
17 ms |
23916 KB |
Output is correct |
7 |
Correct |
19 ms |
23916 KB |
Output is correct |
8 |
Correct |
20 ms |
23916 KB |
Output is correct |
9 |
Correct |
17 ms |
23916 KB |
Output is correct |
10 |
Correct |
17 ms |
23916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
17 ms |
23916 KB |
Output is correct |
4 |
Correct |
16 ms |
23916 KB |
Output is correct |
5 |
Correct |
17 ms |
23936 KB |
Output is correct |
6 |
Correct |
17 ms |
23916 KB |
Output is correct |
7 |
Correct |
19 ms |
23916 KB |
Output is correct |
8 |
Correct |
20 ms |
23916 KB |
Output is correct |
9 |
Correct |
17 ms |
23916 KB |
Output is correct |
10 |
Correct |
17 ms |
23916 KB |
Output is correct |
11 |
Correct |
19 ms |
24060 KB |
Output is correct |
12 |
Correct |
20 ms |
24044 KB |
Output is correct |
13 |
Correct |
20 ms |
24172 KB |
Output is correct |
14 |
Correct |
22 ms |
24172 KB |
Output is correct |
15 |
Correct |
22 ms |
24172 KB |
Output is correct |
16 |
Correct |
21 ms |
24172 KB |
Output is correct |
17 |
Correct |
20 ms |
24172 KB |
Output is correct |
18 |
Correct |
22 ms |
24044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1774 ms |
76568 KB |
Output is correct |
2 |
Correct |
1810 ms |
92744 KB |
Output is correct |
3 |
Correct |
1798 ms |
78152 KB |
Output is correct |
4 |
Correct |
1817 ms |
96476 KB |
Output is correct |
5 |
Correct |
1409 ms |
88300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
142 ms |
29036 KB |
Output is correct |
2 |
Correct |
126 ms |
29804 KB |
Output is correct |
3 |
Correct |
113 ms |
28908 KB |
Output is correct |
4 |
Correct |
119 ms |
29072 KB |
Output is correct |
5 |
Correct |
113 ms |
28908 KB |
Output is correct |
6 |
Correct |
92 ms |
28396 KB |
Output is correct |
7 |
Correct |
96 ms |
28396 KB |
Output is correct |
8 |
Correct |
103 ms |
28472 KB |
Output is correct |
9 |
Correct |
59 ms |
27300 KB |
Output is correct |
10 |
Correct |
101 ms |
28452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
17 ms |
23916 KB |
Output is correct |
4 |
Correct |
16 ms |
23916 KB |
Output is correct |
5 |
Correct |
17 ms |
23936 KB |
Output is correct |
6 |
Correct |
17 ms |
23916 KB |
Output is correct |
7 |
Correct |
19 ms |
23916 KB |
Output is correct |
8 |
Correct |
20 ms |
23916 KB |
Output is correct |
9 |
Correct |
17 ms |
23916 KB |
Output is correct |
10 |
Correct |
17 ms |
23916 KB |
Output is correct |
11 |
Correct |
19 ms |
24060 KB |
Output is correct |
12 |
Correct |
20 ms |
24044 KB |
Output is correct |
13 |
Correct |
20 ms |
24172 KB |
Output is correct |
14 |
Correct |
22 ms |
24172 KB |
Output is correct |
15 |
Correct |
22 ms |
24172 KB |
Output is correct |
16 |
Correct |
21 ms |
24172 KB |
Output is correct |
17 |
Correct |
20 ms |
24172 KB |
Output is correct |
18 |
Correct |
22 ms |
24044 KB |
Output is correct |
19 |
Correct |
313 ms |
38764 KB |
Output is correct |
20 |
Correct |
313 ms |
38816 KB |
Output is correct |
21 |
Correct |
251 ms |
37996 KB |
Output is correct |
22 |
Correct |
264 ms |
38124 KB |
Output is correct |
23 |
Correct |
265 ms |
37996 KB |
Output is correct |
24 |
Correct |
214 ms |
35820 KB |
Output is correct |
25 |
Correct |
211 ms |
35948 KB |
Output is correct |
26 |
Correct |
233 ms |
36332 KB |
Output is correct |
27 |
Correct |
251 ms |
36372 KB |
Output is correct |
28 |
Correct |
252 ms |
36460 KB |
Output is correct |
29 |
Correct |
254 ms |
36920 KB |
Output is correct |
30 |
Correct |
254 ms |
36716 KB |
Output is correct |
31 |
Correct |
253 ms |
36588 KB |
Output is correct |
32 |
Correct |
250 ms |
36716 KB |
Output is correct |
33 |
Correct |
260 ms |
36588 KB |
Output is correct |
34 |
Correct |
201 ms |
35436 KB |
Output is correct |
35 |
Correct |
200 ms |
35476 KB |
Output is correct |
36 |
Correct |
186 ms |
35308 KB |
Output is correct |
37 |
Correct |
193 ms |
35436 KB |
Output is correct |
38 |
Correct |
195 ms |
35436 KB |
Output is correct |
39 |
Correct |
239 ms |
35544 KB |
Output is correct |
40 |
Correct |
170 ms |
33568 KB |
Output is correct |
41 |
Correct |
224 ms |
34580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
17 ms |
23916 KB |
Output is correct |
4 |
Correct |
16 ms |
23916 KB |
Output is correct |
5 |
Correct |
17 ms |
23936 KB |
Output is correct |
6 |
Correct |
17 ms |
23916 KB |
Output is correct |
7 |
Correct |
19 ms |
23916 KB |
Output is correct |
8 |
Correct |
20 ms |
23916 KB |
Output is correct |
9 |
Correct |
17 ms |
23916 KB |
Output is correct |
10 |
Correct |
17 ms |
23916 KB |
Output is correct |
11 |
Correct |
19 ms |
24060 KB |
Output is correct |
12 |
Correct |
20 ms |
24044 KB |
Output is correct |
13 |
Correct |
20 ms |
24172 KB |
Output is correct |
14 |
Correct |
22 ms |
24172 KB |
Output is correct |
15 |
Correct |
22 ms |
24172 KB |
Output is correct |
16 |
Correct |
21 ms |
24172 KB |
Output is correct |
17 |
Correct |
20 ms |
24172 KB |
Output is correct |
18 |
Correct |
22 ms |
24044 KB |
Output is correct |
19 |
Correct |
1774 ms |
76568 KB |
Output is correct |
20 |
Correct |
1810 ms |
92744 KB |
Output is correct |
21 |
Correct |
1798 ms |
78152 KB |
Output is correct |
22 |
Correct |
1817 ms |
96476 KB |
Output is correct |
23 |
Correct |
1409 ms |
88300 KB |
Output is correct |
24 |
Correct |
142 ms |
29036 KB |
Output is correct |
25 |
Correct |
126 ms |
29804 KB |
Output is correct |
26 |
Correct |
113 ms |
28908 KB |
Output is correct |
27 |
Correct |
119 ms |
29072 KB |
Output is correct |
28 |
Correct |
113 ms |
28908 KB |
Output is correct |
29 |
Correct |
92 ms |
28396 KB |
Output is correct |
30 |
Correct |
96 ms |
28396 KB |
Output is correct |
31 |
Correct |
103 ms |
28472 KB |
Output is correct |
32 |
Correct |
59 ms |
27300 KB |
Output is correct |
33 |
Correct |
101 ms |
28452 KB |
Output is correct |
34 |
Correct |
313 ms |
38764 KB |
Output is correct |
35 |
Correct |
313 ms |
38816 KB |
Output is correct |
36 |
Correct |
251 ms |
37996 KB |
Output is correct |
37 |
Correct |
264 ms |
38124 KB |
Output is correct |
38 |
Correct |
265 ms |
37996 KB |
Output is correct |
39 |
Correct |
214 ms |
35820 KB |
Output is correct |
40 |
Correct |
211 ms |
35948 KB |
Output is correct |
41 |
Correct |
233 ms |
36332 KB |
Output is correct |
42 |
Correct |
251 ms |
36372 KB |
Output is correct |
43 |
Correct |
252 ms |
36460 KB |
Output is correct |
44 |
Correct |
254 ms |
36920 KB |
Output is correct |
45 |
Correct |
254 ms |
36716 KB |
Output is correct |
46 |
Correct |
253 ms |
36588 KB |
Output is correct |
47 |
Correct |
250 ms |
36716 KB |
Output is correct |
48 |
Correct |
260 ms |
36588 KB |
Output is correct |
49 |
Correct |
201 ms |
35436 KB |
Output is correct |
50 |
Correct |
200 ms |
35476 KB |
Output is correct |
51 |
Correct |
186 ms |
35308 KB |
Output is correct |
52 |
Correct |
193 ms |
35436 KB |
Output is correct |
53 |
Correct |
195 ms |
35436 KB |
Output is correct |
54 |
Correct |
239 ms |
35544 KB |
Output is correct |
55 |
Correct |
170 ms |
33568 KB |
Output is correct |
56 |
Correct |
224 ms |
34580 KB |
Output is correct |
57 |
Correct |
1760 ms |
69568 KB |
Output is correct |
58 |
Correct |
1757 ms |
87720 KB |
Output is correct |
59 |
Correct |
1692 ms |
87416 KB |
Output is correct |
60 |
Correct |
1665 ms |
87348 KB |
Output is correct |
61 |
Correct |
1677 ms |
87428 KB |
Output is correct |
62 |
Correct |
1707 ms |
87376 KB |
Output is correct |
63 |
Correct |
1070 ms |
63980 KB |
Output is correct |
64 |
Correct |
1120 ms |
63872 KB |
Output is correct |
65 |
Correct |
1358 ms |
79596 KB |
Output is correct |
66 |
Correct |
1389 ms |
79340 KB |
Output is correct |
67 |
Correct |
1366 ms |
79260 KB |
Output is correct |
68 |
Correct |
1413 ms |
79180 KB |
Output is correct |
69 |
Correct |
1398 ms |
79340 KB |
Output is correct |
70 |
Correct |
1416 ms |
79084 KB |
Output is correct |
71 |
Correct |
1391 ms |
79100 KB |
Output is correct |
72 |
Correct |
1406 ms |
79100 KB |
Output is correct |
73 |
Correct |
948 ms |
61276 KB |
Output is correct |
74 |
Correct |
1004 ms |
61804 KB |
Output is correct |
75 |
Correct |
940 ms |
61804 KB |
Output is correct |
76 |
Correct |
945 ms |
61576 KB |
Output is correct |
77 |
Correct |
937 ms |
61292 KB |
Output is correct |
78 |
Correct |
1256 ms |
83304 KB |
Output is correct |
79 |
Correct |
887 ms |
71600 KB |
Output is correct |
80 |
Correct |
1242 ms |
77964 KB |
Output is correct |