#include <bits/stdc++.h>
#define fr(i, a, b) for(int i = (a); i <= (b); ++i)
#define rf(i, a, b) for(int i = (a); i >= (b); --i)
#define fe(x, y) for(auto& x : y)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pw(x) (1LL << (x))
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fbo find_by_order
#define ook order_of_key
template<typename T>
bool umn(T& a, T b) { return (a > b ? (a = b, 1) : 0); }
template<typename T>
bool umx(T& a, T b) { return (a < b ? (a = b, 1) : 0); }
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename T>
using ve = vector<T>;
const int N = 1e6 + 5;
int n, m;
int a[N];
int nxt[N], prv[N];
ve<array<int, 4>> Q;
int ans[N];
int t[4 * N];
void build(int v, int tl, int tr) {
t[v] = 1e9;
if(tl == tr) {
return;
}
int tm = (tl + tr) >> 1;
build(v << 1, tl, tm);
build(v << 1 | 1, tm + 1, tr);
}
void upd(int v, int tl, int tr, int pos, int x) {
if(tl == tr) {
umx(t[v], x);
return;
}
int tm = (tl + tr) >> 1;
if(pos <= tm) {
upd(v << 1, tl, tm, pos, x);
} else {
upd(v << 1 | 1, tm + 1, tr, pos, x);
}
t[v] = max(t[v << 1], t[v << 1 | 1]);
}
void upd(int pos, int x) {
upd(1, 1, n, pos, x);
}
int get(int v, int tl, int tr, int l, int r) {
if(l > r) return -1e9;
if(tl == l && tr == r) {
return t[v];
}
int tm = (tl + tr) >> 1;
return max(get(v << 1, tl, tm, l, min(r, tm)), get(v << 1 | 1, tm + 1, tr, max(tm + 1, l), r));
}
int get(int l, int r) {
return get(1, 1, n, l, r);
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
#else
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
#endif
cin >> n >> m;
fr(i, 1, n) cin >> a[i];
fr(i, 1, n) {
nxt[i] = -1;
prv[i] = -1;
}
ve<pii> st;
rf(i, n, 1) {
while(sz(st) && st.back().fi < a[i]) {
prv[st.back().se] = i;
st.pop_back();
}
st.pb({a[i], i});
}
fr(i, 1, m) {
int l, r, k;
cin >> l >> r >> k;
Q.pb(array<int, 4>{l, r, k, i});
}
sort(all(Q), [](array<int, 4> a, array<int, 4> b) {
return a[1] < b[1];
});
int ptr = 0;
fr(i, 1, n) {
if(prv[i] != -1) {
upd(prv[i], a[i] + a[prv[i]]);
}
while(ptr < sz(Q) && Q[ptr][1] == i) {
ans[Q[ptr][3]] = get(Q[ptr][0], i) > Q[ptr][2] ? 0 : 1;
ptr++;
}
}
fr(i, 1, m) {
cout << ans[i] << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
3 ms |
588 KB |
Output is correct |
12 |
Correct |
5 ms |
584 KB |
Output is correct |
13 |
Correct |
4 ms |
712 KB |
Output is correct |
14 |
Correct |
5 ms |
844 KB |
Output is correct |
15 |
Correct |
5 ms |
860 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
4 ms |
728 KB |
Output is correct |
18 |
Correct |
5 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1205 ms |
42712 KB |
Output is correct |
2 |
Correct |
1165 ms |
58360 KB |
Output is correct |
3 |
Correct |
1195 ms |
65116 KB |
Output is correct |
4 |
Correct |
1120 ms |
58956 KB |
Output is correct |
5 |
Correct |
920 ms |
63548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
5796 KB |
Output is correct |
2 |
Correct |
82 ms |
6356 KB |
Output is correct |
3 |
Correct |
68 ms |
6464 KB |
Output is correct |
4 |
Correct |
71 ms |
6576 KB |
Output is correct |
5 |
Correct |
72 ms |
6516 KB |
Output is correct |
6 |
Correct |
76 ms |
6328 KB |
Output is correct |
7 |
Correct |
69 ms |
6312 KB |
Output is correct |
8 |
Correct |
66 ms |
5836 KB |
Output is correct |
9 |
Correct |
37 ms |
3900 KB |
Output is correct |
10 |
Correct |
67 ms |
5884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
3 ms |
588 KB |
Output is correct |
12 |
Correct |
5 ms |
584 KB |
Output is correct |
13 |
Correct |
4 ms |
712 KB |
Output is correct |
14 |
Correct |
5 ms |
844 KB |
Output is correct |
15 |
Correct |
5 ms |
860 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
4 ms |
728 KB |
Output is correct |
18 |
Correct |
5 ms |
768 KB |
Output is correct |
19 |
Correct |
188 ms |
10624 KB |
Output is correct |
20 |
Correct |
202 ms |
15660 KB |
Output is correct |
21 |
Correct |
180 ms |
15580 KB |
Output is correct |
22 |
Correct |
219 ms |
15672 KB |
Output is correct |
23 |
Correct |
180 ms |
15604 KB |
Output is correct |
24 |
Correct |
156 ms |
14956 KB |
Output is correct |
25 |
Correct |
159 ms |
15028 KB |
Output is correct |
26 |
Correct |
170 ms |
15240 KB |
Output is correct |
27 |
Correct |
163 ms |
15224 KB |
Output is correct |
28 |
Correct |
169 ms |
15156 KB |
Output is correct |
29 |
Correct |
166 ms |
15280 KB |
Output is correct |
30 |
Correct |
176 ms |
15284 KB |
Output is correct |
31 |
Correct |
168 ms |
15384 KB |
Output is correct |
32 |
Correct |
168 ms |
15288 KB |
Output is correct |
33 |
Correct |
159 ms |
15284 KB |
Output is correct |
34 |
Correct |
182 ms |
14940 KB |
Output is correct |
35 |
Correct |
147 ms |
14900 KB |
Output is correct |
36 |
Correct |
162 ms |
14752 KB |
Output is correct |
37 |
Correct |
141 ms |
14768 KB |
Output is correct |
38 |
Correct |
161 ms |
14828 KB |
Output is correct |
39 |
Correct |
150 ms |
14124 KB |
Output is correct |
40 |
Correct |
117 ms |
11568 KB |
Output is correct |
41 |
Correct |
152 ms |
12528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
3 ms |
588 KB |
Output is correct |
12 |
Correct |
5 ms |
584 KB |
Output is correct |
13 |
Correct |
4 ms |
712 KB |
Output is correct |
14 |
Correct |
5 ms |
844 KB |
Output is correct |
15 |
Correct |
5 ms |
860 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
4 ms |
728 KB |
Output is correct |
18 |
Correct |
5 ms |
768 KB |
Output is correct |
19 |
Correct |
1205 ms |
42712 KB |
Output is correct |
20 |
Correct |
1165 ms |
58360 KB |
Output is correct |
21 |
Correct |
1195 ms |
65116 KB |
Output is correct |
22 |
Correct |
1120 ms |
58956 KB |
Output is correct |
23 |
Correct |
920 ms |
63548 KB |
Output is correct |
24 |
Correct |
80 ms |
5796 KB |
Output is correct |
25 |
Correct |
82 ms |
6356 KB |
Output is correct |
26 |
Correct |
68 ms |
6464 KB |
Output is correct |
27 |
Correct |
71 ms |
6576 KB |
Output is correct |
28 |
Correct |
72 ms |
6516 KB |
Output is correct |
29 |
Correct |
76 ms |
6328 KB |
Output is correct |
30 |
Correct |
69 ms |
6312 KB |
Output is correct |
31 |
Correct |
66 ms |
5836 KB |
Output is correct |
32 |
Correct |
37 ms |
3900 KB |
Output is correct |
33 |
Correct |
67 ms |
5884 KB |
Output is correct |
34 |
Correct |
188 ms |
10624 KB |
Output is correct |
35 |
Correct |
202 ms |
15660 KB |
Output is correct |
36 |
Correct |
180 ms |
15580 KB |
Output is correct |
37 |
Correct |
219 ms |
15672 KB |
Output is correct |
38 |
Correct |
180 ms |
15604 KB |
Output is correct |
39 |
Correct |
156 ms |
14956 KB |
Output is correct |
40 |
Correct |
159 ms |
15028 KB |
Output is correct |
41 |
Correct |
170 ms |
15240 KB |
Output is correct |
42 |
Correct |
163 ms |
15224 KB |
Output is correct |
43 |
Correct |
169 ms |
15156 KB |
Output is correct |
44 |
Correct |
166 ms |
15280 KB |
Output is correct |
45 |
Correct |
176 ms |
15284 KB |
Output is correct |
46 |
Correct |
168 ms |
15384 KB |
Output is correct |
47 |
Correct |
168 ms |
15288 KB |
Output is correct |
48 |
Correct |
159 ms |
15284 KB |
Output is correct |
49 |
Correct |
182 ms |
14940 KB |
Output is correct |
50 |
Correct |
147 ms |
14900 KB |
Output is correct |
51 |
Correct |
162 ms |
14752 KB |
Output is correct |
52 |
Correct |
141 ms |
14768 KB |
Output is correct |
53 |
Correct |
161 ms |
14828 KB |
Output is correct |
54 |
Correct |
150 ms |
14124 KB |
Output is correct |
55 |
Correct |
117 ms |
11568 KB |
Output is correct |
56 |
Correct |
152 ms |
12528 KB |
Output is correct |
57 |
Correct |
1128 ms |
50160 KB |
Output is correct |
58 |
Correct |
1108 ms |
50360 KB |
Output is correct |
59 |
Correct |
1047 ms |
50488 KB |
Output is correct |
60 |
Correct |
1172 ms |
50312 KB |
Output is correct |
61 |
Correct |
1010 ms |
50272 KB |
Output is correct |
62 |
Correct |
1008 ms |
50412 KB |
Output is correct |
63 |
Correct |
802 ms |
49404 KB |
Output is correct |
64 |
Correct |
836 ms |
49400 KB |
Output is correct |
65 |
Correct |
903 ms |
49980 KB |
Output is correct |
66 |
Correct |
894 ms |
51796 KB |
Output is correct |
67 |
Correct |
878 ms |
44524 KB |
Output is correct |
68 |
Correct |
956 ms |
51860 KB |
Output is correct |
69 |
Correct |
956 ms |
51832 KB |
Output is correct |
70 |
Correct |
891 ms |
54944 KB |
Output is correct |
71 |
Correct |
873 ms |
54956 KB |
Output is correct |
72 |
Correct |
887 ms |
51676 KB |
Output is correct |
73 |
Correct |
788 ms |
52856 KB |
Output is correct |
74 |
Correct |
867 ms |
64368 KB |
Output is correct |
75 |
Correct |
975 ms |
63464 KB |
Output is correct |
76 |
Correct |
936 ms |
53876 KB |
Output is correct |
77 |
Correct |
886 ms |
53652 KB |
Output is correct |
78 |
Correct |
880 ms |
50868 KB |
Output is correct |
79 |
Correct |
620 ms |
53880 KB |
Output is correct |
80 |
Correct |
800 ms |
57224 KB |
Output is correct |