#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define F first
#define S second
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forbn(i, b, n) for(int i = b; i < n; ++i)
#define sz(v) (int)v.size()
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
typedef complex<double> cd; // !!! long double slow
template <class T> inline void mineq(T &a, T b) { a = min(a, b); }
template <class T> inline void maxeq(T &a, T b) { a = max(a, b); }
int n, Q;
const int INF = 1000 * 1000 * 1000 + 10;
const int MX = 1000 * 1000;
int ls[MX], ks[MX];
struct Seg {
int n;
vi mx;
Seg(int n): n(n) {
mx.assign(2 * n, -1);
}
void upd(int p, int v) {
for(maxeq(mx[p += n], v); p > 1; p >>= 1)
mx[p >> 1] = max(mx[p], mx[p ^ 1]);
}
int query(int l, int r) {
int res = -1;
for(l += n, r += n + 1; l < r; l >>= 1, r >>= 1) {
if(l & 1) maxeq(res, mx[l++]);
if(r & 1) maxeq(res, mx[--r]);
}
return res;
}
};
void solve() {
cin >> n >> Q;
vi a(n + 1, INF);
forbn(i, 1, n + 1)
cin >> a[i];
vi qs[n + 1];
forn(q, Q) {
int r;
cin >> ls[q] >> r >> ks[q];
qs[r].eb(q);
}
Seg seg(n + 1);
vi st(1), ans(Q);
forbn(i, 1, n + 1) {
while(a[st.back()] <= a[i])
st.pop_back();
seg.upd(st.back(), a[st.back()] + a[i]);
st.push_back(i);
for(int q: qs[i]) {
ans[q] = seg.query(ls[q], n) <= ks[q];
}
}
for(int el: ans)
cout << el << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
// freopen("boards.in", "r", stdin);
// freopen("boards.out", "w", stdout);
int t = 1;
// cin >> t;
while(t--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 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 |
340 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 |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 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 |
340 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 |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
596 KB |
Output is correct |
13 |
Correct |
4 ms |
596 KB |
Output is correct |
14 |
Correct |
4 ms |
596 KB |
Output is correct |
15 |
Correct |
3 ms |
596 KB |
Output is correct |
16 |
Correct |
3 ms |
596 KB |
Output is correct |
17 |
Correct |
3 ms |
596 KB |
Output is correct |
18 |
Correct |
3 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1041 ms |
67444 KB |
Output is correct |
2 |
Correct |
1053 ms |
67280 KB |
Output is correct |
3 |
Correct |
1076 ms |
67300 KB |
Output is correct |
4 |
Correct |
1067 ms |
67372 KB |
Output is correct |
5 |
Correct |
1059 ms |
74296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
6752 KB |
Output is correct |
2 |
Correct |
62 ms |
6048 KB |
Output is correct |
3 |
Correct |
77 ms |
6616 KB |
Output is correct |
4 |
Correct |
56 ms |
6732 KB |
Output is correct |
5 |
Correct |
57 ms |
6752 KB |
Output is correct |
6 |
Correct |
47 ms |
5764 KB |
Output is correct |
7 |
Correct |
49 ms |
5836 KB |
Output is correct |
8 |
Correct |
56 ms |
6728 KB |
Output is correct |
9 |
Correct |
35 ms |
2168 KB |
Output is correct |
10 |
Correct |
56 ms |
6720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 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 |
340 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 |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
596 KB |
Output is correct |
13 |
Correct |
4 ms |
596 KB |
Output is correct |
14 |
Correct |
4 ms |
596 KB |
Output is correct |
15 |
Correct |
3 ms |
596 KB |
Output is correct |
16 |
Correct |
3 ms |
596 KB |
Output is correct |
17 |
Correct |
3 ms |
596 KB |
Output is correct |
18 |
Correct |
3 ms |
596 KB |
Output is correct |
19 |
Correct |
165 ms |
13312 KB |
Output is correct |
20 |
Correct |
163 ms |
13352 KB |
Output is correct |
21 |
Correct |
146 ms |
11596 KB |
Output is correct |
22 |
Correct |
164 ms |
11564 KB |
Output is correct |
23 |
Correct |
138 ms |
11636 KB |
Output is correct |
24 |
Correct |
141 ms |
11460 KB |
Output is correct |
25 |
Correct |
133 ms |
11420 KB |
Output is correct |
26 |
Correct |
130 ms |
12088 KB |
Output is correct |
27 |
Correct |
136 ms |
12164 KB |
Output is correct |
28 |
Correct |
149 ms |
12508 KB |
Output is correct |
29 |
Correct |
193 ms |
13336 KB |
Output is correct |
30 |
Correct |
174 ms |
13552 KB |
Output is correct |
31 |
Correct |
176 ms |
13184 KB |
Output is correct |
32 |
Correct |
180 ms |
13288 KB |
Output is correct |
33 |
Correct |
192 ms |
13176 KB |
Output is correct |
34 |
Correct |
128 ms |
11240 KB |
Output is correct |
35 |
Correct |
122 ms |
11228 KB |
Output is correct |
36 |
Correct |
134 ms |
11232 KB |
Output is correct |
37 |
Correct |
122 ms |
11232 KB |
Output is correct |
38 |
Correct |
129 ms |
11228 KB |
Output is correct |
39 |
Correct |
170 ms |
12900 KB |
Output is correct |
40 |
Correct |
135 ms |
10232 KB |
Output is correct |
41 |
Correct |
145 ms |
13116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 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 |
340 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 |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
596 KB |
Output is correct |
13 |
Correct |
4 ms |
596 KB |
Output is correct |
14 |
Correct |
4 ms |
596 KB |
Output is correct |
15 |
Correct |
3 ms |
596 KB |
Output is correct |
16 |
Correct |
3 ms |
596 KB |
Output is correct |
17 |
Correct |
3 ms |
596 KB |
Output is correct |
18 |
Correct |
3 ms |
596 KB |
Output is correct |
19 |
Correct |
1041 ms |
67444 KB |
Output is correct |
20 |
Correct |
1053 ms |
67280 KB |
Output is correct |
21 |
Correct |
1076 ms |
67300 KB |
Output is correct |
22 |
Correct |
1067 ms |
67372 KB |
Output is correct |
23 |
Correct |
1059 ms |
74296 KB |
Output is correct |
24 |
Correct |
62 ms |
6752 KB |
Output is correct |
25 |
Correct |
62 ms |
6048 KB |
Output is correct |
26 |
Correct |
77 ms |
6616 KB |
Output is correct |
27 |
Correct |
56 ms |
6732 KB |
Output is correct |
28 |
Correct |
57 ms |
6752 KB |
Output is correct |
29 |
Correct |
47 ms |
5764 KB |
Output is correct |
30 |
Correct |
49 ms |
5836 KB |
Output is correct |
31 |
Correct |
56 ms |
6728 KB |
Output is correct |
32 |
Correct |
35 ms |
2168 KB |
Output is correct |
33 |
Correct |
56 ms |
6720 KB |
Output is correct |
34 |
Correct |
165 ms |
13312 KB |
Output is correct |
35 |
Correct |
163 ms |
13352 KB |
Output is correct |
36 |
Correct |
146 ms |
11596 KB |
Output is correct |
37 |
Correct |
164 ms |
11564 KB |
Output is correct |
38 |
Correct |
138 ms |
11636 KB |
Output is correct |
39 |
Correct |
141 ms |
11460 KB |
Output is correct |
40 |
Correct |
133 ms |
11420 KB |
Output is correct |
41 |
Correct |
130 ms |
12088 KB |
Output is correct |
42 |
Correct |
136 ms |
12164 KB |
Output is correct |
43 |
Correct |
149 ms |
12508 KB |
Output is correct |
44 |
Correct |
193 ms |
13336 KB |
Output is correct |
45 |
Correct |
174 ms |
13552 KB |
Output is correct |
46 |
Correct |
176 ms |
13184 KB |
Output is correct |
47 |
Correct |
180 ms |
13288 KB |
Output is correct |
48 |
Correct |
192 ms |
13176 KB |
Output is correct |
49 |
Correct |
128 ms |
11240 KB |
Output is correct |
50 |
Correct |
122 ms |
11228 KB |
Output is correct |
51 |
Correct |
134 ms |
11232 KB |
Output is correct |
52 |
Correct |
122 ms |
11232 KB |
Output is correct |
53 |
Correct |
129 ms |
11228 KB |
Output is correct |
54 |
Correct |
170 ms |
12900 KB |
Output is correct |
55 |
Correct |
135 ms |
10232 KB |
Output is correct |
56 |
Correct |
145 ms |
13116 KB |
Output is correct |
57 |
Correct |
1208 ms |
99064 KB |
Output is correct |
58 |
Correct |
1085 ms |
99024 KB |
Output is correct |
59 |
Correct |
1056 ms |
94832 KB |
Output is correct |
60 |
Correct |
1050 ms |
94824 KB |
Output is correct |
61 |
Correct |
1100 ms |
94836 KB |
Output is correct |
62 |
Correct |
1026 ms |
94896 KB |
Output is correct |
63 |
Correct |
709 ms |
87156 KB |
Output is correct |
64 |
Correct |
710 ms |
87176 KB |
Output is correct |
65 |
Correct |
981 ms |
94432 KB |
Output is correct |
66 |
Correct |
977 ms |
94260 KB |
Output is correct |
67 |
Correct |
997 ms |
94668 KB |
Output is correct |
68 |
Correct |
1076 ms |
98976 KB |
Output is correct |
69 |
Correct |
1137 ms |
98972 KB |
Output is correct |
70 |
Correct |
1071 ms |
96280 KB |
Output is correct |
71 |
Correct |
1088 ms |
98292 KB |
Output is correct |
72 |
Correct |
1086 ms |
98332 KB |
Output is correct |
73 |
Correct |
678 ms |
85132 KB |
Output is correct |
74 |
Correct |
659 ms |
86040 KB |
Output is correct |
75 |
Correct |
652 ms |
85224 KB |
Output is correct |
76 |
Correct |
649 ms |
84968 KB |
Output is correct |
77 |
Correct |
652 ms |
84568 KB |
Output is correct |
78 |
Correct |
921 ms |
91056 KB |
Output is correct |
79 |
Correct |
685 ms |
67240 KB |
Output is correct |
80 |
Correct |
892 ms |
88616 KB |
Output is correct |