#include "bits/stdc++.h"
// @JASPER'S BOILERPLATE
using namespace std;
using ll = long long;
#ifdef JASPER
#include "debug.h"
#else
#define debug(...) 166
#endif
struct SegmentTree {
vector <ll> f;
int n;
ll NEUTRAL = numeric_limits <ll> :: min ();
SegmentTree(int _n) {
n = _n;
f.assign((n << 1) + 5, 0);
}
void upd(int x, ll val) {
f[x + n] = val;
for (x += n; x; x >>= 1)
f[x >> 1] = max(f[x], f[x ^ 1]);
}
ll qry(int l, int r) {
ll ql = NEUTRAL, qr = NEUTRAL;
for (l += n, r += n + 1; l < r; l >>= 1, r >>= 1) {
if (l & 1) ql = max(ql, f[l++]);
if (r & 1) qr = max(qr, f[--r]);
}
return max(ql, qr);
}
};
const int N = 1e6 + 5;
using Query = tuple <int, int, int>;
vector <Query> qs[N];
int n, m;
int w[N];
bool ans[N];
signed main() {
cin.tie(0) -> sync_with_stdio(0);
#ifdef JASPER
freopen("in1", "r", stdin);
#endif
cin >> n >> m;
for (int i = 1; i <= n; ++i) cin >> w[i];
for (int i = 1; i <= m; ++i) {
int l, r, k;
cin >> l >> r >> k;
qs[r].push_back({l, k, i});
}
stack <int> st;
SegmentTree seg(n);
for (int i = 1; i <= n; ++i) {
while (!st.empty() && w[st.top()] <= w[i]) st.pop();
if (!st.empty()) {
seg.upd(st.top(), w[st.top()] + w[i]);
}
for (auto& [l, k, id] : qs[i]) {
ll mx = seg.qry(l, i); // qry(x) : maximum inversion sum of (w(l), w(r)) (l < r <= n)
// debug(st, w[st.top()], w[i]);
// debug(mx, l, i);
ans[id] = (mx <= k);
}
// debug(seg.qry(1, 2));
st.push(i);
}
for (int i = 1; i <= m; ++i)
cout << ans[i] << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
26456 KB |
Output is correct |
2 |
Correct |
6 ms |
26460 KB |
Output is correct |
3 |
Correct |
6 ms |
26456 KB |
Output is correct |
4 |
Correct |
6 ms |
26460 KB |
Output is correct |
5 |
Correct |
6 ms |
26460 KB |
Output is correct |
6 |
Correct |
7 ms |
26460 KB |
Output is correct |
7 |
Correct |
6 ms |
26612 KB |
Output is correct |
8 |
Correct |
6 ms |
26460 KB |
Output is correct |
9 |
Correct |
6 ms |
26460 KB |
Output is correct |
10 |
Correct |
6 ms |
26460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
26456 KB |
Output is correct |
2 |
Correct |
6 ms |
26460 KB |
Output is correct |
3 |
Correct |
6 ms |
26456 KB |
Output is correct |
4 |
Correct |
6 ms |
26460 KB |
Output is correct |
5 |
Correct |
6 ms |
26460 KB |
Output is correct |
6 |
Correct |
7 ms |
26460 KB |
Output is correct |
7 |
Correct |
6 ms |
26612 KB |
Output is correct |
8 |
Correct |
6 ms |
26460 KB |
Output is correct |
9 |
Correct |
6 ms |
26460 KB |
Output is correct |
10 |
Correct |
6 ms |
26460 KB |
Output is correct |
11 |
Correct |
7 ms |
26612 KB |
Output is correct |
12 |
Correct |
7 ms |
26716 KB |
Output is correct |
13 |
Correct |
8 ms |
26712 KB |
Output is correct |
14 |
Correct |
9 ms |
26868 KB |
Output is correct |
15 |
Correct |
11 ms |
27068 KB |
Output is correct |
16 |
Correct |
8 ms |
26716 KB |
Output is correct |
17 |
Correct |
8 ms |
26700 KB |
Output is correct |
18 |
Correct |
8 ms |
26716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
817 ms |
99896 KB |
Output is correct |
2 |
Correct |
784 ms |
100912 KB |
Output is correct |
3 |
Correct |
816 ms |
100944 KB |
Output is correct |
4 |
Correct |
816 ms |
100976 KB |
Output is correct |
5 |
Correct |
752 ms |
101072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
32332 KB |
Output is correct |
2 |
Correct |
52 ms |
32128 KB |
Output is correct |
3 |
Correct |
60 ms |
32332 KB |
Output is correct |
4 |
Correct |
54 ms |
32340 KB |
Output is correct |
5 |
Correct |
55 ms |
32404 KB |
Output is correct |
6 |
Correct |
42 ms |
31832 KB |
Output is correct |
7 |
Correct |
42 ms |
31824 KB |
Output is correct |
8 |
Correct |
49 ms |
32056 KB |
Output is correct |
9 |
Correct |
32 ms |
29704 KB |
Output is correct |
10 |
Correct |
57 ms |
32008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
26456 KB |
Output is correct |
2 |
Correct |
6 ms |
26460 KB |
Output is correct |
3 |
Correct |
6 ms |
26456 KB |
Output is correct |
4 |
Correct |
6 ms |
26460 KB |
Output is correct |
5 |
Correct |
6 ms |
26460 KB |
Output is correct |
6 |
Correct |
7 ms |
26460 KB |
Output is correct |
7 |
Correct |
6 ms |
26612 KB |
Output is correct |
8 |
Correct |
6 ms |
26460 KB |
Output is correct |
9 |
Correct |
6 ms |
26460 KB |
Output is correct |
10 |
Correct |
6 ms |
26460 KB |
Output is correct |
11 |
Correct |
7 ms |
26612 KB |
Output is correct |
12 |
Correct |
7 ms |
26716 KB |
Output is correct |
13 |
Correct |
8 ms |
26712 KB |
Output is correct |
14 |
Correct |
9 ms |
26868 KB |
Output is correct |
15 |
Correct |
11 ms |
27068 KB |
Output is correct |
16 |
Correct |
8 ms |
26716 KB |
Output is correct |
17 |
Correct |
8 ms |
26700 KB |
Output is correct |
18 |
Correct |
8 ms |
26716 KB |
Output is correct |
19 |
Correct |
129 ms |
41120 KB |
Output is correct |
20 |
Correct |
125 ms |
41012 KB |
Output is correct |
21 |
Correct |
109 ms |
40412 KB |
Output is correct |
22 |
Correct |
112 ms |
40400 KB |
Output is correct |
23 |
Correct |
109 ms |
40272 KB |
Output is correct |
24 |
Correct |
97 ms |
40276 KB |
Output is correct |
25 |
Correct |
101 ms |
40308 KB |
Output is correct |
26 |
Correct |
115 ms |
40524 KB |
Output is correct |
27 |
Correct |
118 ms |
40528 KB |
Output is correct |
28 |
Correct |
113 ms |
40540 KB |
Output is correct |
29 |
Correct |
120 ms |
40912 KB |
Output is correct |
30 |
Correct |
133 ms |
41416 KB |
Output is correct |
31 |
Correct |
120 ms |
41040 KB |
Output is correct |
32 |
Correct |
119 ms |
40956 KB |
Output is correct |
33 |
Correct |
128 ms |
41044 KB |
Output is correct |
34 |
Correct |
88 ms |
39656 KB |
Output is correct |
35 |
Correct |
104 ms |
39740 KB |
Output is correct |
36 |
Correct |
89 ms |
39496 KB |
Output is correct |
37 |
Correct |
94 ms |
39780 KB |
Output is correct |
38 |
Correct |
90 ms |
39760 KB |
Output is correct |
39 |
Correct |
109 ms |
39296 KB |
Output is correct |
40 |
Correct |
89 ms |
37144 KB |
Output is correct |
41 |
Correct |
100 ms |
38776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
26456 KB |
Output is correct |
2 |
Correct |
6 ms |
26460 KB |
Output is correct |
3 |
Correct |
6 ms |
26456 KB |
Output is correct |
4 |
Correct |
6 ms |
26460 KB |
Output is correct |
5 |
Correct |
6 ms |
26460 KB |
Output is correct |
6 |
Correct |
7 ms |
26460 KB |
Output is correct |
7 |
Correct |
6 ms |
26612 KB |
Output is correct |
8 |
Correct |
6 ms |
26460 KB |
Output is correct |
9 |
Correct |
6 ms |
26460 KB |
Output is correct |
10 |
Correct |
6 ms |
26460 KB |
Output is correct |
11 |
Correct |
7 ms |
26612 KB |
Output is correct |
12 |
Correct |
7 ms |
26716 KB |
Output is correct |
13 |
Correct |
8 ms |
26712 KB |
Output is correct |
14 |
Correct |
9 ms |
26868 KB |
Output is correct |
15 |
Correct |
11 ms |
27068 KB |
Output is correct |
16 |
Correct |
8 ms |
26716 KB |
Output is correct |
17 |
Correct |
8 ms |
26700 KB |
Output is correct |
18 |
Correct |
8 ms |
26716 KB |
Output is correct |
19 |
Correct |
817 ms |
99896 KB |
Output is correct |
20 |
Correct |
784 ms |
100912 KB |
Output is correct |
21 |
Correct |
816 ms |
100944 KB |
Output is correct |
22 |
Correct |
816 ms |
100976 KB |
Output is correct |
23 |
Correct |
752 ms |
101072 KB |
Output is correct |
24 |
Correct |
56 ms |
32332 KB |
Output is correct |
25 |
Correct |
52 ms |
32128 KB |
Output is correct |
26 |
Correct |
60 ms |
32332 KB |
Output is correct |
27 |
Correct |
54 ms |
32340 KB |
Output is correct |
28 |
Correct |
55 ms |
32404 KB |
Output is correct |
29 |
Correct |
42 ms |
31832 KB |
Output is correct |
30 |
Correct |
42 ms |
31824 KB |
Output is correct |
31 |
Correct |
49 ms |
32056 KB |
Output is correct |
32 |
Correct |
32 ms |
29704 KB |
Output is correct |
33 |
Correct |
57 ms |
32008 KB |
Output is correct |
34 |
Correct |
129 ms |
41120 KB |
Output is correct |
35 |
Correct |
125 ms |
41012 KB |
Output is correct |
36 |
Correct |
109 ms |
40412 KB |
Output is correct |
37 |
Correct |
112 ms |
40400 KB |
Output is correct |
38 |
Correct |
109 ms |
40272 KB |
Output is correct |
39 |
Correct |
97 ms |
40276 KB |
Output is correct |
40 |
Correct |
101 ms |
40308 KB |
Output is correct |
41 |
Correct |
115 ms |
40524 KB |
Output is correct |
42 |
Correct |
118 ms |
40528 KB |
Output is correct |
43 |
Correct |
113 ms |
40540 KB |
Output is correct |
44 |
Correct |
120 ms |
40912 KB |
Output is correct |
45 |
Correct |
133 ms |
41416 KB |
Output is correct |
46 |
Correct |
120 ms |
41040 KB |
Output is correct |
47 |
Correct |
119 ms |
40956 KB |
Output is correct |
48 |
Correct |
128 ms |
41044 KB |
Output is correct |
49 |
Correct |
88 ms |
39656 KB |
Output is correct |
50 |
Correct |
104 ms |
39740 KB |
Output is correct |
51 |
Correct |
89 ms |
39496 KB |
Output is correct |
52 |
Correct |
94 ms |
39780 KB |
Output is correct |
53 |
Correct |
90 ms |
39760 KB |
Output is correct |
54 |
Correct |
109 ms |
39296 KB |
Output is correct |
55 |
Correct |
89 ms |
37144 KB |
Output is correct |
56 |
Correct |
100 ms |
38776 KB |
Output is correct |
57 |
Correct |
803 ms |
101100 KB |
Output is correct |
58 |
Correct |
784 ms |
101344 KB |
Output is correct |
59 |
Correct |
689 ms |
99676 KB |
Output is correct |
60 |
Correct |
692 ms |
99544 KB |
Output is correct |
61 |
Correct |
711 ms |
99660 KB |
Output is correct |
62 |
Correct |
748 ms |
99664 KB |
Output is correct |
63 |
Correct |
463 ms |
96348 KB |
Output is correct |
64 |
Correct |
458 ms |
96296 KB |
Output is correct |
65 |
Correct |
660 ms |
99400 KB |
Output is correct |
66 |
Correct |
662 ms |
99536 KB |
Output is correct |
67 |
Correct |
686 ms |
99876 KB |
Output is correct |
68 |
Correct |
740 ms |
101220 KB |
Output is correct |
69 |
Correct |
765 ms |
101224 KB |
Output is correct |
70 |
Correct |
740 ms |
100780 KB |
Output is correct |
71 |
Correct |
733 ms |
101168 KB |
Output is correct |
72 |
Correct |
743 ms |
100960 KB |
Output is correct |
73 |
Correct |
414 ms |
92576 KB |
Output is correct |
74 |
Correct |
426 ms |
93384 KB |
Output is correct |
75 |
Correct |
413 ms |
92236 KB |
Output is correct |
76 |
Correct |
417 ms |
93016 KB |
Output is correct |
77 |
Correct |
437 ms |
92048 KB |
Output is correct |
78 |
Correct |
639 ms |
93196 KB |
Output is correct |
79 |
Correct |
485 ms |
78836 KB |
Output is correct |
80 |
Correct |
619 ms |
91520 KB |
Output is correct |