#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e6 + 5;
const int M = 1e6 + 6;
const int B = 450;
struct Query {
ll l, mood, id;
};
ll n, m, a[N], pos[N];
vector <Query> g[N];
ll ans[N];
ll t[N * 4];
void upd(int pos, ll val, int v = 1, int tl = 1, int tr = n) {
if (tl == tr) {
t[v] = max(t[v], val);
return;
}
int tm = (tl + tr) / 2;
if (pos <= tm) upd(pos, val, v + v, tl, tm);
else upd(pos, val, v + v + 1, tm + 1, tr);
t[v] = max(t[v + v], t[v + v + 1]);
}
ll get(int l, int r, int v = 1, int tl = 1, int tr = n) {
if (r < tl || tr < l) return 0;
if (l <= tl && tr <= r) return t[v];
int tm = (tl + tr) / 2;
return max(get(l, r, v + v, tl, tm), get(l, r, v + v + 1, tm + 1, tr));
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; ++ i) {
cin >> a[i];
}
stack <int> st;
for (int i = 1; i <= n; ++ i) {
while (st.size() && a[st.top()] <= a[i]) st.pop();
if (st.size() > 0) pos[i] = st.top();
else pos[i] = 0;
st.push(i);
}
for (int i = 1; i <= m; ++ i) {
int l, r, mood;
cin >> l >> r >> mood;
g[r].push_back({l, mood, i});
}
for (int i = 1; i <= n; ++ i) {
if (pos[i] > 0) upd(pos[i], a[pos[i]] + a[i]);
for (auto [l, mood, id] : g[i]) {
if (get(l, i) <= mood) ans[id] = 1;
else ans[id] = 0;
}
}
for (int i = 1; i <= m; ++ i) cout << ans[i] << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
23900 KB |
Output is correct |
2 |
Correct |
9 ms |
23836 KB |
Output is correct |
3 |
Correct |
11 ms |
23900 KB |
Output is correct |
4 |
Correct |
11 ms |
23896 KB |
Output is correct |
5 |
Correct |
12 ms |
23944 KB |
Output is correct |
6 |
Correct |
11 ms |
23900 KB |
Output is correct |
7 |
Correct |
11 ms |
23900 KB |
Output is correct |
8 |
Correct |
11 ms |
23900 KB |
Output is correct |
9 |
Correct |
12 ms |
23900 KB |
Output is correct |
10 |
Correct |
10 ms |
23864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
23900 KB |
Output is correct |
2 |
Correct |
9 ms |
23836 KB |
Output is correct |
3 |
Correct |
11 ms |
23900 KB |
Output is correct |
4 |
Correct |
11 ms |
23896 KB |
Output is correct |
5 |
Correct |
12 ms |
23944 KB |
Output is correct |
6 |
Correct |
11 ms |
23900 KB |
Output is correct |
7 |
Correct |
11 ms |
23900 KB |
Output is correct |
8 |
Correct |
11 ms |
23900 KB |
Output is correct |
9 |
Correct |
12 ms |
23900 KB |
Output is correct |
10 |
Correct |
10 ms |
23864 KB |
Output is correct |
11 |
Correct |
11 ms |
24152 KB |
Output is correct |
12 |
Correct |
13 ms |
24156 KB |
Output is correct |
13 |
Correct |
11 ms |
24304 KB |
Output is correct |
14 |
Correct |
13 ms |
24192 KB |
Output is correct |
15 |
Correct |
14 ms |
24152 KB |
Output is correct |
16 |
Correct |
13 ms |
24156 KB |
Output is correct |
17 |
Correct |
11 ms |
24060 KB |
Output is correct |
18 |
Correct |
12 ms |
24076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
980 ms |
98132 KB |
Output is correct |
2 |
Correct |
1002 ms |
98224 KB |
Output is correct |
3 |
Correct |
1059 ms |
98108 KB |
Output is correct |
4 |
Correct |
1016 ms |
98124 KB |
Output is correct |
5 |
Correct |
931 ms |
81912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
88 ms |
31572 KB |
Output is correct |
2 |
Correct |
112 ms |
31824 KB |
Output is correct |
3 |
Correct |
77 ms |
29592 KB |
Output is correct |
4 |
Correct |
74 ms |
31544 KB |
Output is correct |
5 |
Correct |
71 ms |
31572 KB |
Output is correct |
6 |
Correct |
86 ms |
31520 KB |
Output is correct |
7 |
Correct |
62 ms |
31628 KB |
Output is correct |
8 |
Correct |
61 ms |
30984 KB |
Output is correct |
9 |
Correct |
40 ms |
29188 KB |
Output is correct |
10 |
Correct |
71 ms |
30980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
23900 KB |
Output is correct |
2 |
Correct |
9 ms |
23836 KB |
Output is correct |
3 |
Correct |
11 ms |
23900 KB |
Output is correct |
4 |
Correct |
11 ms |
23896 KB |
Output is correct |
5 |
Correct |
12 ms |
23944 KB |
Output is correct |
6 |
Correct |
11 ms |
23900 KB |
Output is correct |
7 |
Correct |
11 ms |
23900 KB |
Output is correct |
8 |
Correct |
11 ms |
23900 KB |
Output is correct |
9 |
Correct |
12 ms |
23900 KB |
Output is correct |
10 |
Correct |
10 ms |
23864 KB |
Output is correct |
11 |
Correct |
11 ms |
24152 KB |
Output is correct |
12 |
Correct |
13 ms |
24156 KB |
Output is correct |
13 |
Correct |
11 ms |
24304 KB |
Output is correct |
14 |
Correct |
13 ms |
24192 KB |
Output is correct |
15 |
Correct |
14 ms |
24152 KB |
Output is correct |
16 |
Correct |
13 ms |
24156 KB |
Output is correct |
17 |
Correct |
11 ms |
24060 KB |
Output is correct |
18 |
Correct |
12 ms |
24076 KB |
Output is correct |
19 |
Correct |
186 ms |
39508 KB |
Output is correct |
20 |
Correct |
192 ms |
39508 KB |
Output is correct |
21 |
Correct |
163 ms |
40112 KB |
Output is correct |
22 |
Correct |
172 ms |
40032 KB |
Output is correct |
23 |
Correct |
163 ms |
40004 KB |
Output is correct |
24 |
Correct |
127 ms |
36240 KB |
Output is correct |
25 |
Correct |
133 ms |
42704 KB |
Output is correct |
26 |
Correct |
152 ms |
42392 KB |
Output is correct |
27 |
Correct |
190 ms |
42324 KB |
Output is correct |
28 |
Correct |
159 ms |
42252 KB |
Output is correct |
29 |
Correct |
174 ms |
42020 KB |
Output is correct |
30 |
Correct |
167 ms |
42112 KB |
Output is correct |
31 |
Correct |
150 ms |
42064 KB |
Output is correct |
32 |
Correct |
167 ms |
42068 KB |
Output is correct |
33 |
Correct |
171 ms |
42064 KB |
Output is correct |
34 |
Correct |
123 ms |
41684 KB |
Output is correct |
35 |
Correct |
134 ms |
41892 KB |
Output is correct |
36 |
Correct |
120 ms |
41752 KB |
Output is correct |
37 |
Correct |
118 ms |
41664 KB |
Output is correct |
38 |
Correct |
124 ms |
41812 KB |
Output is correct |
39 |
Correct |
140 ms |
41476 KB |
Output is correct |
40 |
Correct |
102 ms |
37960 KB |
Output is correct |
41 |
Correct |
123 ms |
39676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
23900 KB |
Output is correct |
2 |
Correct |
9 ms |
23836 KB |
Output is correct |
3 |
Correct |
11 ms |
23900 KB |
Output is correct |
4 |
Correct |
11 ms |
23896 KB |
Output is correct |
5 |
Correct |
12 ms |
23944 KB |
Output is correct |
6 |
Correct |
11 ms |
23900 KB |
Output is correct |
7 |
Correct |
11 ms |
23900 KB |
Output is correct |
8 |
Correct |
11 ms |
23900 KB |
Output is correct |
9 |
Correct |
12 ms |
23900 KB |
Output is correct |
10 |
Correct |
10 ms |
23864 KB |
Output is correct |
11 |
Correct |
11 ms |
24152 KB |
Output is correct |
12 |
Correct |
13 ms |
24156 KB |
Output is correct |
13 |
Correct |
11 ms |
24304 KB |
Output is correct |
14 |
Correct |
13 ms |
24192 KB |
Output is correct |
15 |
Correct |
14 ms |
24152 KB |
Output is correct |
16 |
Correct |
13 ms |
24156 KB |
Output is correct |
17 |
Correct |
11 ms |
24060 KB |
Output is correct |
18 |
Correct |
12 ms |
24076 KB |
Output is correct |
19 |
Correct |
980 ms |
98132 KB |
Output is correct |
20 |
Correct |
1002 ms |
98224 KB |
Output is correct |
21 |
Correct |
1059 ms |
98108 KB |
Output is correct |
22 |
Correct |
1016 ms |
98124 KB |
Output is correct |
23 |
Correct |
931 ms |
81912 KB |
Output is correct |
24 |
Correct |
88 ms |
31572 KB |
Output is correct |
25 |
Correct |
112 ms |
31824 KB |
Output is correct |
26 |
Correct |
77 ms |
29592 KB |
Output is correct |
27 |
Correct |
74 ms |
31544 KB |
Output is correct |
28 |
Correct |
71 ms |
31572 KB |
Output is correct |
29 |
Correct |
86 ms |
31520 KB |
Output is correct |
30 |
Correct |
62 ms |
31628 KB |
Output is correct |
31 |
Correct |
61 ms |
30984 KB |
Output is correct |
32 |
Correct |
40 ms |
29188 KB |
Output is correct |
33 |
Correct |
71 ms |
30980 KB |
Output is correct |
34 |
Correct |
186 ms |
39508 KB |
Output is correct |
35 |
Correct |
192 ms |
39508 KB |
Output is correct |
36 |
Correct |
163 ms |
40112 KB |
Output is correct |
37 |
Correct |
172 ms |
40032 KB |
Output is correct |
38 |
Correct |
163 ms |
40004 KB |
Output is correct |
39 |
Correct |
127 ms |
36240 KB |
Output is correct |
40 |
Correct |
133 ms |
42704 KB |
Output is correct |
41 |
Correct |
152 ms |
42392 KB |
Output is correct |
42 |
Correct |
190 ms |
42324 KB |
Output is correct |
43 |
Correct |
159 ms |
42252 KB |
Output is correct |
44 |
Correct |
174 ms |
42020 KB |
Output is correct |
45 |
Correct |
167 ms |
42112 KB |
Output is correct |
46 |
Correct |
150 ms |
42064 KB |
Output is correct |
47 |
Correct |
167 ms |
42068 KB |
Output is correct |
48 |
Correct |
171 ms |
42064 KB |
Output is correct |
49 |
Correct |
123 ms |
41684 KB |
Output is correct |
50 |
Correct |
134 ms |
41892 KB |
Output is correct |
51 |
Correct |
120 ms |
41752 KB |
Output is correct |
52 |
Correct |
118 ms |
41664 KB |
Output is correct |
53 |
Correct |
124 ms |
41812 KB |
Output is correct |
54 |
Correct |
140 ms |
41476 KB |
Output is correct |
55 |
Correct |
102 ms |
37960 KB |
Output is correct |
56 |
Correct |
123 ms |
39676 KB |
Output is correct |
57 |
Correct |
1029 ms |
132088 KB |
Output is correct |
58 |
Correct |
1026 ms |
131920 KB |
Output is correct |
59 |
Correct |
976 ms |
132748 KB |
Output is correct |
60 |
Correct |
984 ms |
132700 KB |
Output is correct |
61 |
Correct |
934 ms |
132688 KB |
Output is correct |
62 |
Correct |
1030 ms |
132692 KB |
Output is correct |
63 |
Correct |
612 ms |
116308 KB |
Output is correct |
64 |
Correct |
623 ms |
116376 KB |
Output is correct |
65 |
Correct |
804 ms |
116452 KB |
Output is correct |
66 |
Correct |
806 ms |
116560 KB |
Output is correct |
67 |
Correct |
784 ms |
116304 KB |
Output is correct |
68 |
Correct |
847 ms |
115796 KB |
Output is correct |
69 |
Correct |
878 ms |
115560 KB |
Output is correct |
70 |
Correct |
835 ms |
115796 KB |
Output is correct |
71 |
Correct |
845 ms |
115756 KB |
Output is correct |
72 |
Correct |
916 ms |
115752 KB |
Output is correct |
73 |
Correct |
569 ms |
110192 KB |
Output is correct |
74 |
Correct |
579 ms |
111168 KB |
Output is correct |
75 |
Correct |
581 ms |
110388 KB |
Output is correct |
76 |
Correct |
560 ms |
110676 KB |
Output is correct |
77 |
Correct |
570 ms |
109984 KB |
Output is correct |
78 |
Correct |
753 ms |
112624 KB |
Output is correct |
79 |
Correct |
569 ms |
92444 KB |
Output is correct |
80 |
Correct |
731 ms |
103292 KB |
Output is correct |