#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <array>
#include <stack>
#include <queue>
#include <random>
#include <numeric>
#include <functional>
#include <chrono>
#include <utility>
#include <iomanip>
#include <assert.h>
using namespace std;
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#define rng_init mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define rng_seed(x) mt19937 rng(x)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
#define int long long
template<typename T>
struct segment_tree {
int n;
vector<T> a, tree;
T identity;
function<T(const T&, const T&)> merge;
void init(const vector<T> &a, T identity, const function<T(const T&, const T&)> &merge) {
n = (int) a.size();
tree.resize(4 * n);
this->a = a;
this->identity = identity;
this->merge = merge;
build(1, 0, n - 1);
}
void init(int n, T identity, const function<T(const T&, const T&)> &merge) {
this->n = n;
this->identity = identity;
this->merge = merge;
tree.assign(4 * n, identity);
}
void build(int i, int l, int r) {
if (l == r) {
tree[i] = a[l];
return;
}
int mid = (l + r) / 2;
build(2 * i, l, mid);
build(2 * i + 1, mid + 1, r);
tree[i] = merge(tree[2 * i], tree[2 * i + 1]);
}
void identity_modify(int i, int l, int r, int pos, T val) {
if (l == r) {
tree[i] = merge(tree[i], val);
return;
}
int mid = (l + r) / 2;
if (pos <= mid) identity_modify(2 * i, l, mid, pos, val);
else identity_modify(2 * i + 1, mid + 1, r, pos, val);
tree[i] = merge(tree[2 * i], tree[2 * i + 1]);
}
void increment(int i, int l, int r, int pos, T val) {
if (l == r) {
tree[i] += val;
return;
}
int mid = (l + r) / 2;
if (pos <= mid) increment(2 * i, l, mid, pos, val);
else increment(2 * i + 1, mid + 1, r, pos, val);
tree[i] = merge(tree[2 * i], tree[2 * i + 1]);
}
T query(int i, int l, int r, int ql, int qr) {
if (l > qr || r < ql) return identity;
if (l >= ql && r <= qr) return tree[i];
int mid = (l + r) / 2;
T resL = query(2 * i, l, mid, ql, qr);
T resR = query(2 * i + 1, mid + 1, r, ql, qr);
return merge(resL, resR);
}
void identity_modify(int pos, T val) { identity_modify(1, 0, n - 1, pos, val); }
void increment(int pos, T val) { increment(1, 0, n - 1, pos, val); }
T query(int pos) { return query(1, 0, n - 1, pos, pos); }
T query(int l, int r) { return query(1, 0, n - 1, l, r); }
};
const int MXN = 1e5 + 5, INF = 1e17;
void solve() {
int N, M;
cin >> N >> M;
vector<int> A(N);
for (auto &x : A)
cin >> x;
vector<array<int, 3>> queries[N];
for (int i = 0; i < M; i++) {
int l, r, k;
cin >> l >> r >> k;
l--, r--;
queries[r].emplace_back(array<int, 3>{l, k, i});
}
stack<int> greater;
segment_tree<int> tree;
tree.init(N, -INF, [&](const int &x, const int &y) { return max(x, y); });
vector<int> ans(M, 0);
for (int r = 0; r < N; r++) {
while (!greater.empty() && A[greater.top()] <= A[r])
greater.pop();
if (!greater.empty()) {
int greater_idx = greater.top();
tree.identity_modify(greater_idx, A[greater_idx] + A[r]);
}
for (const auto &[l, k, idx] : queries[r])
ans[idx] |= (tree.query(l, r) <= k);
greater.push(r);
}
for (const auto &x : ans)
cout << x << "\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int TC = 1;
// cin >> TC;
while (TC--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
4 ms |
620 KB |
Output is correct |
12 |
Correct |
4 ms |
876 KB |
Output is correct |
13 |
Correct |
5 ms |
876 KB |
Output is correct |
14 |
Correct |
6 ms |
1004 KB |
Output is correct |
15 |
Correct |
9 ms |
1004 KB |
Output is correct |
16 |
Correct |
5 ms |
1152 KB |
Output is correct |
17 |
Correct |
4 ms |
876 KB |
Output is correct |
18 |
Correct |
5 ms |
876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1932 ms |
105376 KB |
Output is correct |
2 |
Correct |
1936 ms |
105580 KB |
Output is correct |
3 |
Correct |
1910 ms |
105320 KB |
Output is correct |
4 |
Correct |
1898 ms |
105488 KB |
Output is correct |
5 |
Correct |
1564 ms |
105528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
130 ms |
10860 KB |
Output is correct |
2 |
Correct |
116 ms |
11372 KB |
Output is correct |
3 |
Correct |
104 ms |
11116 KB |
Output is correct |
4 |
Correct |
103 ms |
11116 KB |
Output is correct |
5 |
Correct |
103 ms |
11116 KB |
Output is correct |
6 |
Correct |
87 ms |
11136 KB |
Output is correct |
7 |
Correct |
83 ms |
11244 KB |
Output is correct |
8 |
Correct |
101 ms |
10996 KB |
Output is correct |
9 |
Correct |
45 ms |
4512 KB |
Output is correct |
10 |
Correct |
102 ms |
10784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
4 ms |
620 KB |
Output is correct |
12 |
Correct |
4 ms |
876 KB |
Output is correct |
13 |
Correct |
5 ms |
876 KB |
Output is correct |
14 |
Correct |
6 ms |
1004 KB |
Output is correct |
15 |
Correct |
9 ms |
1004 KB |
Output is correct |
16 |
Correct |
5 ms |
1152 KB |
Output is correct |
17 |
Correct |
4 ms |
876 KB |
Output is correct |
18 |
Correct |
5 ms |
876 KB |
Output is correct |
19 |
Correct |
317 ms |
21860 KB |
Output is correct |
20 |
Correct |
312 ms |
21868 KB |
Output is correct |
21 |
Correct |
268 ms |
22384 KB |
Output is correct |
22 |
Correct |
259 ms |
22380 KB |
Output is correct |
23 |
Correct |
260 ms |
22380 KB |
Output is correct |
24 |
Correct |
199 ms |
22508 KB |
Output is correct |
25 |
Correct |
205 ms |
22508 KB |
Output is correct |
26 |
Correct |
236 ms |
22260 KB |
Output is correct |
27 |
Correct |
233 ms |
22124 KB |
Output is correct |
28 |
Correct |
241 ms |
22016 KB |
Output is correct |
29 |
Correct |
257 ms |
21868 KB |
Output is correct |
30 |
Correct |
255 ms |
21868 KB |
Output is correct |
31 |
Correct |
261 ms |
21868 KB |
Output is correct |
32 |
Correct |
258 ms |
21868 KB |
Output is correct |
33 |
Correct |
260 ms |
22012 KB |
Output is correct |
34 |
Correct |
186 ms |
21996 KB |
Output is correct |
35 |
Correct |
191 ms |
22124 KB |
Output is correct |
36 |
Correct |
184 ms |
21996 KB |
Output is correct |
37 |
Correct |
182 ms |
21996 KB |
Output is correct |
38 |
Correct |
185 ms |
22124 KB |
Output is correct |
39 |
Correct |
226 ms |
21408 KB |
Output is correct |
40 |
Correct |
175 ms |
16536 KB |
Output is correct |
41 |
Correct |
237 ms |
21148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
4 ms |
620 KB |
Output is correct |
12 |
Correct |
4 ms |
876 KB |
Output is correct |
13 |
Correct |
5 ms |
876 KB |
Output is correct |
14 |
Correct |
6 ms |
1004 KB |
Output is correct |
15 |
Correct |
9 ms |
1004 KB |
Output is correct |
16 |
Correct |
5 ms |
1152 KB |
Output is correct |
17 |
Correct |
4 ms |
876 KB |
Output is correct |
18 |
Correct |
5 ms |
876 KB |
Output is correct |
19 |
Correct |
1932 ms |
105376 KB |
Output is correct |
20 |
Correct |
1936 ms |
105580 KB |
Output is correct |
21 |
Correct |
1910 ms |
105320 KB |
Output is correct |
22 |
Correct |
1898 ms |
105488 KB |
Output is correct |
23 |
Correct |
1564 ms |
105528 KB |
Output is correct |
24 |
Correct |
130 ms |
10860 KB |
Output is correct |
25 |
Correct |
116 ms |
11372 KB |
Output is correct |
26 |
Correct |
104 ms |
11116 KB |
Output is correct |
27 |
Correct |
103 ms |
11116 KB |
Output is correct |
28 |
Correct |
103 ms |
11116 KB |
Output is correct |
29 |
Correct |
87 ms |
11136 KB |
Output is correct |
30 |
Correct |
83 ms |
11244 KB |
Output is correct |
31 |
Correct |
101 ms |
10996 KB |
Output is correct |
32 |
Correct |
45 ms |
4512 KB |
Output is correct |
33 |
Correct |
102 ms |
10784 KB |
Output is correct |
34 |
Correct |
317 ms |
21860 KB |
Output is correct |
35 |
Correct |
312 ms |
21868 KB |
Output is correct |
36 |
Correct |
268 ms |
22384 KB |
Output is correct |
37 |
Correct |
259 ms |
22380 KB |
Output is correct |
38 |
Correct |
260 ms |
22380 KB |
Output is correct |
39 |
Correct |
199 ms |
22508 KB |
Output is correct |
40 |
Correct |
205 ms |
22508 KB |
Output is correct |
41 |
Correct |
236 ms |
22260 KB |
Output is correct |
42 |
Correct |
233 ms |
22124 KB |
Output is correct |
43 |
Correct |
241 ms |
22016 KB |
Output is correct |
44 |
Correct |
257 ms |
21868 KB |
Output is correct |
45 |
Correct |
255 ms |
21868 KB |
Output is correct |
46 |
Correct |
261 ms |
21868 KB |
Output is correct |
47 |
Correct |
258 ms |
21868 KB |
Output is correct |
48 |
Correct |
260 ms |
22012 KB |
Output is correct |
49 |
Correct |
186 ms |
21996 KB |
Output is correct |
50 |
Correct |
191 ms |
22124 KB |
Output is correct |
51 |
Correct |
184 ms |
21996 KB |
Output is correct |
52 |
Correct |
182 ms |
21996 KB |
Output is correct |
53 |
Correct |
185 ms |
22124 KB |
Output is correct |
54 |
Correct |
226 ms |
21408 KB |
Output is correct |
55 |
Correct |
175 ms |
16536 KB |
Output is correct |
56 |
Correct |
237 ms |
21148 KB |
Output is correct |
57 |
Correct |
1883 ms |
105952 KB |
Output is correct |
58 |
Correct |
1885 ms |
105828 KB |
Output is correct |
59 |
Correct |
1824 ms |
106788 KB |
Output is correct |
60 |
Correct |
1817 ms |
106860 KB |
Output is correct |
61 |
Correct |
1814 ms |
106636 KB |
Output is correct |
62 |
Correct |
1786 ms |
106648 KB |
Output is correct |
63 |
Correct |
1097 ms |
108780 KB |
Output is correct |
64 |
Correct |
1143 ms |
108940 KB |
Output is correct |
65 |
Correct |
1457 ms |
107116 KB |
Output is correct |
66 |
Correct |
1488 ms |
106904 KB |
Output is correct |
67 |
Correct |
1485 ms |
106780 KB |
Output is correct |
68 |
Correct |
1542 ms |
106008 KB |
Output is correct |
69 |
Correct |
1530 ms |
106092 KB |
Output is correct |
70 |
Correct |
1555 ms |
106092 KB |
Output is correct |
71 |
Correct |
1541 ms |
105928 KB |
Output is correct |
72 |
Correct |
1533 ms |
106092 KB |
Output is correct |
73 |
Correct |
998 ms |
104244 KB |
Output is correct |
74 |
Correct |
1024 ms |
104172 KB |
Output is correct |
75 |
Correct |
1000 ms |
104428 KB |
Output is correct |
76 |
Correct |
994 ms |
105068 KB |
Output is correct |
77 |
Correct |
1004 ms |
104220 KB |
Output is correct |
78 |
Correct |
1353 ms |
103568 KB |
Output is correct |
79 |
Correct |
958 ms |
71184 KB |
Output is correct |
80 |
Correct |
1435 ms |
103056 KB |
Output is correct |