#include<bits/stdc++.h>
/*
#pragma optimize ("g",on)
#pragma GCC optimize ("inline")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("03")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
*/
//01001101 01100001 01101011 01101000 01100001 01100111 01100001 01111001
using namespace std;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ll long long
#define pb push_back
#define sz(a) a.size()
#define nl '\n'
#define popb pop_back()
#define ld double
#define ull unsigned long long
#define ff first
#define ss second
#define fix fixed << setprecision
#define pii pair<int, int>
#define E exit (0)
#define int long long
const int inf = 1e15, N = 1e6 + 1, mod = 998244353;
vector<pii> dir = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
int t[N * 4];
void update(int u, int tl, int tr, int pos, int val) {
if (tl == tr) {
t[u] = max(t[u], val);
return;
}
int mid = (tl + tr) / 2;
if (pos <= mid) {
update(u * 2, tl, mid, pos, val);
}else {
update(u * 2 + 1, mid + 1, tr, pos, val);
}
t[u] = max(t[u * 2], t[u * 2 + 1]);
}
int get(int u, int tl, int tr, int l, int r) {
if (tl >= l && tr <= r) return t[u];
if (tl > r || tr < l) return 0;
int mid = (tl + tr) / 2;
return max(get(u * 2, tl, mid, l, r), get(u * 2 + 1, mid + 1, tr, l, r));
}
main() {
//freopen("triangles.in", "r", stdin);
//freopen("triangles.out", "w", stdout);
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
int n, m;
cin >> n >> m;
int a[n + 1], l[n + 1], ans[m + 1];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
stack<int> st;
st.push(1);
l[1] = 1;
for (int i = 2; i <= n; i++) {
l[i] = i;
while (!st.empty() && a[st.top()] <= a[i]) {
l[i] = l[st.top()];
st.pop();
}
st.push(i);
}
vector<pair<int, pii>> s[n + 1];
for (int i = 1; i <= m; i++) {
int l, r, k;
cin >> l >> r >> k;
s[r].pb({l, {i, k}});
}
for (int i = 1; i <= n; i++) {
if (l[i] > 1) update(1, 1, n, l[i] - 1, a[i] + a[l[i] - 1]);
for (auto e: s[i]) {
ans[e.ss.ff] = (e.ss.ss >= get(1, 1, n, e.ff, n));
}
}
for (int i = 1; i <= m; i++) cout << ans[i] << nl;
}
Compilation message
sortbooks.cpp:58:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
58 | main() {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 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 |
0 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 |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 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 |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
460 KB |
Output is correct |
12 |
Correct |
3 ms |
716 KB |
Output is correct |
13 |
Correct |
4 ms |
704 KB |
Output is correct |
14 |
Correct |
5 ms |
844 KB |
Output is correct |
15 |
Correct |
4 ms |
844 KB |
Output is correct |
16 |
Correct |
5 ms |
716 KB |
Output is correct |
17 |
Correct |
4 ms |
716 KB |
Output is correct |
18 |
Correct |
3 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1227 ms |
98172 KB |
Output is correct |
2 |
Correct |
1319 ms |
98180 KB |
Output is correct |
3 |
Correct |
1395 ms |
98176 KB |
Output is correct |
4 |
Correct |
1347 ms |
98056 KB |
Output is correct |
5 |
Correct |
1012 ms |
81928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
10592 KB |
Output is correct |
2 |
Correct |
78 ms |
10636 KB |
Output is correct |
3 |
Correct |
62 ms |
8500 KB |
Output is correct |
4 |
Correct |
59 ms |
8440 KB |
Output is correct |
5 |
Correct |
72 ms |
8396 KB |
Output is correct |
6 |
Correct |
71 ms |
8500 KB |
Output is correct |
7 |
Correct |
59 ms |
8516 KB |
Output is correct |
8 |
Correct |
59 ms |
8580 KB |
Output is correct |
9 |
Correct |
32 ms |
4212 KB |
Output is correct |
10 |
Correct |
58 ms |
8588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 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 |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
460 KB |
Output is correct |
12 |
Correct |
3 ms |
716 KB |
Output is correct |
13 |
Correct |
4 ms |
704 KB |
Output is correct |
14 |
Correct |
5 ms |
844 KB |
Output is correct |
15 |
Correct |
4 ms |
844 KB |
Output is correct |
16 |
Correct |
5 ms |
716 KB |
Output is correct |
17 |
Correct |
4 ms |
716 KB |
Output is correct |
18 |
Correct |
3 ms |
716 KB |
Output is correct |
19 |
Correct |
212 ms |
20708 KB |
Output is correct |
20 |
Correct |
211 ms |
20632 KB |
Output is correct |
21 |
Correct |
168 ms |
21252 KB |
Output is correct |
22 |
Correct |
173 ms |
21192 KB |
Output is correct |
23 |
Correct |
165 ms |
21228 KB |
Output is correct |
24 |
Correct |
134 ms |
17300 KB |
Output is correct |
25 |
Correct |
136 ms |
17252 KB |
Output is correct |
26 |
Correct |
144 ms |
16908 KB |
Output is correct |
27 |
Correct |
174 ms |
16956 KB |
Output is correct |
28 |
Correct |
148 ms |
16836 KB |
Output is correct |
29 |
Correct |
153 ms |
16580 KB |
Output is correct |
30 |
Correct |
155 ms |
16528 KB |
Output is correct |
31 |
Correct |
170 ms |
16540 KB |
Output is correct |
32 |
Correct |
156 ms |
16524 KB |
Output is correct |
33 |
Correct |
176 ms |
16656 KB |
Output is correct |
34 |
Correct |
139 ms |
16656 KB |
Output is correct |
35 |
Correct |
126 ms |
16828 KB |
Output is correct |
36 |
Correct |
121 ms |
16780 KB |
Output is correct |
37 |
Correct |
122 ms |
16824 KB |
Output is correct |
38 |
Correct |
132 ms |
16920 KB |
Output is correct |
39 |
Correct |
147 ms |
17548 KB |
Output is correct |
40 |
Correct |
113 ms |
12912 KB |
Output is correct |
41 |
Correct |
138 ms |
17040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 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 |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
460 KB |
Output is correct |
12 |
Correct |
3 ms |
716 KB |
Output is correct |
13 |
Correct |
4 ms |
704 KB |
Output is correct |
14 |
Correct |
5 ms |
844 KB |
Output is correct |
15 |
Correct |
4 ms |
844 KB |
Output is correct |
16 |
Correct |
5 ms |
716 KB |
Output is correct |
17 |
Correct |
4 ms |
716 KB |
Output is correct |
18 |
Correct |
3 ms |
716 KB |
Output is correct |
19 |
Correct |
1227 ms |
98172 KB |
Output is correct |
20 |
Correct |
1319 ms |
98180 KB |
Output is correct |
21 |
Correct |
1395 ms |
98176 KB |
Output is correct |
22 |
Correct |
1347 ms |
98056 KB |
Output is correct |
23 |
Correct |
1012 ms |
81928 KB |
Output is correct |
24 |
Correct |
96 ms |
10592 KB |
Output is correct |
25 |
Correct |
78 ms |
10636 KB |
Output is correct |
26 |
Correct |
62 ms |
8500 KB |
Output is correct |
27 |
Correct |
59 ms |
8440 KB |
Output is correct |
28 |
Correct |
72 ms |
8396 KB |
Output is correct |
29 |
Correct |
71 ms |
8500 KB |
Output is correct |
30 |
Correct |
59 ms |
8516 KB |
Output is correct |
31 |
Correct |
59 ms |
8580 KB |
Output is correct |
32 |
Correct |
32 ms |
4212 KB |
Output is correct |
33 |
Correct |
58 ms |
8588 KB |
Output is correct |
34 |
Correct |
212 ms |
20708 KB |
Output is correct |
35 |
Correct |
211 ms |
20632 KB |
Output is correct |
36 |
Correct |
168 ms |
21252 KB |
Output is correct |
37 |
Correct |
173 ms |
21192 KB |
Output is correct |
38 |
Correct |
165 ms |
21228 KB |
Output is correct |
39 |
Correct |
134 ms |
17300 KB |
Output is correct |
40 |
Correct |
136 ms |
17252 KB |
Output is correct |
41 |
Correct |
144 ms |
16908 KB |
Output is correct |
42 |
Correct |
174 ms |
16956 KB |
Output is correct |
43 |
Correct |
148 ms |
16836 KB |
Output is correct |
44 |
Correct |
153 ms |
16580 KB |
Output is correct |
45 |
Correct |
155 ms |
16528 KB |
Output is correct |
46 |
Correct |
170 ms |
16540 KB |
Output is correct |
47 |
Correct |
156 ms |
16524 KB |
Output is correct |
48 |
Correct |
176 ms |
16656 KB |
Output is correct |
49 |
Correct |
139 ms |
16656 KB |
Output is correct |
50 |
Correct |
126 ms |
16828 KB |
Output is correct |
51 |
Correct |
121 ms |
16780 KB |
Output is correct |
52 |
Correct |
122 ms |
16824 KB |
Output is correct |
53 |
Correct |
132 ms |
16920 KB |
Output is correct |
54 |
Correct |
147 ms |
17548 KB |
Output is correct |
55 |
Correct |
113 ms |
12912 KB |
Output is correct |
56 |
Correct |
138 ms |
17040 KB |
Output is correct |
57 |
Correct |
1278 ms |
98432 KB |
Output is correct |
58 |
Correct |
1311 ms |
98468 KB |
Output is correct |
59 |
Correct |
1170 ms |
99148 KB |
Output is correct |
60 |
Correct |
1144 ms |
99120 KB |
Output is correct |
61 |
Correct |
1156 ms |
99184 KB |
Output is correct |
62 |
Correct |
1232 ms |
99184 KB |
Output is correct |
63 |
Correct |
705 ms |
84560 KB |
Output is correct |
64 |
Correct |
703 ms |
84748 KB |
Output is correct |
65 |
Correct |
920 ms |
83040 KB |
Output is correct |
66 |
Correct |
906 ms |
82884 KB |
Output is correct |
67 |
Correct |
950 ms |
82772 KB |
Output is correct |
68 |
Correct |
938 ms |
81960 KB |
Output is correct |
69 |
Correct |
966 ms |
81912 KB |
Output is correct |
70 |
Correct |
943 ms |
82084 KB |
Output is correct |
71 |
Correct |
959 ms |
81968 KB |
Output is correct |
72 |
Correct |
968 ms |
82052 KB |
Output is correct |
73 |
Correct |
613 ms |
80048 KB |
Output is correct |
74 |
Correct |
667 ms |
80060 KB |
Output is correct |
75 |
Correct |
658 ms |
80156 KB |
Output is correct |
76 |
Correct |
678 ms |
80444 KB |
Output is correct |
77 |
Correct |
658 ms |
79904 KB |
Output is correct |
78 |
Correct |
870 ms |
84968 KB |
Output is correct |
79 |
Correct |
642 ms |
58504 KB |
Output is correct |
80 |
Correct |
856 ms |
78708 KB |
Output is correct |