#include <bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
typedef long long ll;
const int MAX = 1e6 + 10;
const int INF = 0x3f3f3f3f;
struct Q{
ll l, k, id;
Q(ll a = 0, ll b = 0, ll c = 0){
l = a, k = b, id = c;
}
};
ll n, m, a[MAX], seg[4 * MAX];
bool resp[MAX];
vector<Q> queries[MAX];
void update(ll i, ll x, ll p, ll l, ll r){
if(i < l || i > r) return;
if(l == r){
seg[p] = max(seg[p], x);
return;
}
ll m = (l + r) >> 1, e = 2 * p, d = e + 1;
update(i, x, e, l, m);
update(i, x, d, m + 1, r);
seg[p] = max(seg[e], seg[d]);
}
ll query(ll a, ll b, ll p, ll l, ll r){
if(a > r || b < l) return -INF;
if(a <= l && r <= b) return seg[p];
ll m = (l + r) >> 1, e = 2 * p, d = e + 1;
return max(query(a, b, e, l, m), query(a, b, d, m + 1, r));
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for(int i = 1; i <= n; i++)
cin >> a[i];
for(int i = 1; i <= m; i++){
ll l, r, k; cin >> l >> r >> k;
queries[r].emplace_back(l, k, i);
}
a[0] = INF;
stack<int> s; s.push(0);
for(int i = 1; i <= n; i++){
while(a[s.top()] <= a[i]) s.pop();
if(s.top() != 0){
int idx = s.top();
update(idx, a[idx] + a[i], 1, 1, n);
}
s.push(i);
for(auto q : queries[i]){
int l = q.l, k = q.k, idx = q.id;
resp[idx] = (query(l, i, 1, 1, n) <= k);
}
}
for(int i = 1; i <= m; i++)
cout << resp[i] << '\n';
exit(0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23768 KB |
Output is correct |
3 |
Correct |
12 ms |
23764 KB |
Output is correct |
4 |
Correct |
14 ms |
23764 KB |
Output is correct |
5 |
Correct |
13 ms |
23764 KB |
Output is correct |
6 |
Correct |
14 ms |
23868 KB |
Output is correct |
7 |
Correct |
14 ms |
23764 KB |
Output is correct |
8 |
Correct |
17 ms |
23780 KB |
Output is correct |
9 |
Correct |
13 ms |
23820 KB |
Output is correct |
10 |
Correct |
13 ms |
23820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23768 KB |
Output is correct |
3 |
Correct |
12 ms |
23764 KB |
Output is correct |
4 |
Correct |
14 ms |
23764 KB |
Output is correct |
5 |
Correct |
13 ms |
23764 KB |
Output is correct |
6 |
Correct |
14 ms |
23868 KB |
Output is correct |
7 |
Correct |
14 ms |
23764 KB |
Output is correct |
8 |
Correct |
17 ms |
23780 KB |
Output is correct |
9 |
Correct |
13 ms |
23820 KB |
Output is correct |
10 |
Correct |
13 ms |
23820 KB |
Output is correct |
11 |
Correct |
15 ms |
23948 KB |
Output is correct |
12 |
Correct |
17 ms |
24096 KB |
Output is correct |
13 |
Correct |
15 ms |
24148 KB |
Output is correct |
14 |
Correct |
18 ms |
24232 KB |
Output is correct |
15 |
Correct |
23 ms |
24276 KB |
Output is correct |
16 |
Correct |
18 ms |
24112 KB |
Output is correct |
17 |
Correct |
16 ms |
24084 KB |
Output is correct |
18 |
Correct |
18 ms |
24108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1345 ms |
85116 KB |
Output is correct |
2 |
Correct |
1319 ms |
85964 KB |
Output is correct |
3 |
Correct |
1278 ms |
85968 KB |
Output is correct |
4 |
Correct |
1275 ms |
85860 KB |
Output is correct |
5 |
Correct |
1085 ms |
69616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
96 ms |
32200 KB |
Output is correct |
2 |
Correct |
86 ms |
32280 KB |
Output is correct |
3 |
Correct |
81 ms |
30168 KB |
Output is correct |
4 |
Correct |
94 ms |
30156 KB |
Output is correct |
5 |
Correct |
97 ms |
30196 KB |
Output is correct |
6 |
Correct |
67 ms |
30028 KB |
Output is correct |
7 |
Correct |
68 ms |
30004 KB |
Output is correct |
8 |
Correct |
77 ms |
29908 KB |
Output is correct |
9 |
Correct |
52 ms |
28300 KB |
Output is correct |
10 |
Correct |
98 ms |
29808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23768 KB |
Output is correct |
3 |
Correct |
12 ms |
23764 KB |
Output is correct |
4 |
Correct |
14 ms |
23764 KB |
Output is correct |
5 |
Correct |
13 ms |
23764 KB |
Output is correct |
6 |
Correct |
14 ms |
23868 KB |
Output is correct |
7 |
Correct |
14 ms |
23764 KB |
Output is correct |
8 |
Correct |
17 ms |
23780 KB |
Output is correct |
9 |
Correct |
13 ms |
23820 KB |
Output is correct |
10 |
Correct |
13 ms |
23820 KB |
Output is correct |
11 |
Correct |
15 ms |
23948 KB |
Output is correct |
12 |
Correct |
17 ms |
24096 KB |
Output is correct |
13 |
Correct |
15 ms |
24148 KB |
Output is correct |
14 |
Correct |
18 ms |
24232 KB |
Output is correct |
15 |
Correct |
23 ms |
24276 KB |
Output is correct |
16 |
Correct |
18 ms |
24112 KB |
Output is correct |
17 |
Correct |
16 ms |
24084 KB |
Output is correct |
18 |
Correct |
18 ms |
24108 KB |
Output is correct |
19 |
Correct |
223 ms |
43264 KB |
Output is correct |
20 |
Correct |
226 ms |
43268 KB |
Output is correct |
21 |
Correct |
203 ms |
43580 KB |
Output is correct |
22 |
Correct |
178 ms |
43656 KB |
Output is correct |
23 |
Correct |
176 ms |
43572 KB |
Output is correct |
24 |
Correct |
149 ms |
39412 KB |
Output is correct |
25 |
Correct |
148 ms |
39524 KB |
Output is correct |
26 |
Correct |
173 ms |
39436 KB |
Output is correct |
27 |
Correct |
173 ms |
39288 KB |
Output is correct |
28 |
Correct |
179 ms |
39180 KB |
Output is correct |
29 |
Correct |
184 ms |
38980 KB |
Output is correct |
30 |
Correct |
210 ms |
39020 KB |
Output is correct |
31 |
Correct |
196 ms |
39068 KB |
Output is correct |
32 |
Correct |
198 ms |
38988 KB |
Output is correct |
33 |
Correct |
187 ms |
38988 KB |
Output is correct |
34 |
Correct |
136 ms |
38856 KB |
Output is correct |
35 |
Correct |
135 ms |
38808 KB |
Output is correct |
36 |
Correct |
147 ms |
38560 KB |
Output is correct |
37 |
Correct |
133 ms |
38688 KB |
Output is correct |
38 |
Correct |
142 ms |
38860 KB |
Output is correct |
39 |
Correct |
163 ms |
38584 KB |
Output is correct |
40 |
Correct |
139 ms |
35416 KB |
Output is correct |
41 |
Correct |
194 ms |
37364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23768 KB |
Output is correct |
3 |
Correct |
12 ms |
23764 KB |
Output is correct |
4 |
Correct |
14 ms |
23764 KB |
Output is correct |
5 |
Correct |
13 ms |
23764 KB |
Output is correct |
6 |
Correct |
14 ms |
23868 KB |
Output is correct |
7 |
Correct |
14 ms |
23764 KB |
Output is correct |
8 |
Correct |
17 ms |
23780 KB |
Output is correct |
9 |
Correct |
13 ms |
23820 KB |
Output is correct |
10 |
Correct |
13 ms |
23820 KB |
Output is correct |
11 |
Correct |
15 ms |
23948 KB |
Output is correct |
12 |
Correct |
17 ms |
24096 KB |
Output is correct |
13 |
Correct |
15 ms |
24148 KB |
Output is correct |
14 |
Correct |
18 ms |
24232 KB |
Output is correct |
15 |
Correct |
23 ms |
24276 KB |
Output is correct |
16 |
Correct |
18 ms |
24112 KB |
Output is correct |
17 |
Correct |
16 ms |
24084 KB |
Output is correct |
18 |
Correct |
18 ms |
24108 KB |
Output is correct |
19 |
Correct |
1345 ms |
85116 KB |
Output is correct |
20 |
Correct |
1319 ms |
85964 KB |
Output is correct |
21 |
Correct |
1278 ms |
85968 KB |
Output is correct |
22 |
Correct |
1275 ms |
85860 KB |
Output is correct |
23 |
Correct |
1085 ms |
69616 KB |
Output is correct |
24 |
Correct |
96 ms |
32200 KB |
Output is correct |
25 |
Correct |
86 ms |
32280 KB |
Output is correct |
26 |
Correct |
81 ms |
30168 KB |
Output is correct |
27 |
Correct |
94 ms |
30156 KB |
Output is correct |
28 |
Correct |
97 ms |
30196 KB |
Output is correct |
29 |
Correct |
67 ms |
30028 KB |
Output is correct |
30 |
Correct |
68 ms |
30004 KB |
Output is correct |
31 |
Correct |
77 ms |
29908 KB |
Output is correct |
32 |
Correct |
52 ms |
28300 KB |
Output is correct |
33 |
Correct |
98 ms |
29808 KB |
Output is correct |
34 |
Correct |
223 ms |
43264 KB |
Output is correct |
35 |
Correct |
226 ms |
43268 KB |
Output is correct |
36 |
Correct |
203 ms |
43580 KB |
Output is correct |
37 |
Correct |
178 ms |
43656 KB |
Output is correct |
38 |
Correct |
176 ms |
43572 KB |
Output is correct |
39 |
Correct |
149 ms |
39412 KB |
Output is correct |
40 |
Correct |
148 ms |
39524 KB |
Output is correct |
41 |
Correct |
173 ms |
39436 KB |
Output is correct |
42 |
Correct |
173 ms |
39288 KB |
Output is correct |
43 |
Correct |
179 ms |
39180 KB |
Output is correct |
44 |
Correct |
184 ms |
38980 KB |
Output is correct |
45 |
Correct |
210 ms |
39020 KB |
Output is correct |
46 |
Correct |
196 ms |
39068 KB |
Output is correct |
47 |
Correct |
198 ms |
38988 KB |
Output is correct |
48 |
Correct |
187 ms |
38988 KB |
Output is correct |
49 |
Correct |
136 ms |
38856 KB |
Output is correct |
50 |
Correct |
135 ms |
38808 KB |
Output is correct |
51 |
Correct |
147 ms |
38560 KB |
Output is correct |
52 |
Correct |
133 ms |
38688 KB |
Output is correct |
53 |
Correct |
142 ms |
38860 KB |
Output is correct |
54 |
Correct |
163 ms |
38584 KB |
Output is correct |
55 |
Correct |
139 ms |
35416 KB |
Output is correct |
56 |
Correct |
194 ms |
37364 KB |
Output is correct |
57 |
Correct |
1306 ms |
92912 KB |
Output is correct |
58 |
Correct |
1374 ms |
92860 KB |
Output is correct |
59 |
Correct |
1180 ms |
93824 KB |
Output is correct |
60 |
Correct |
1175 ms |
93744 KB |
Output is correct |
61 |
Correct |
1224 ms |
93816 KB |
Output is correct |
62 |
Correct |
1272 ms |
93764 KB |
Output is correct |
63 |
Correct |
851 ms |
93620 KB |
Output is correct |
64 |
Correct |
793 ms |
93532 KB |
Output is correct |
65 |
Correct |
982 ms |
77600 KB |
Output is correct |
66 |
Correct |
1046 ms |
77516 KB |
Output is correct |
67 |
Correct |
980 ms |
84608 KB |
Output is correct |
68 |
Correct |
1076 ms |
91604 KB |
Output is correct |
69 |
Correct |
1103 ms |
91664 KB |
Output is correct |
70 |
Correct |
1029 ms |
91624 KB |
Output is correct |
71 |
Correct |
1045 ms |
91156 KB |
Output is correct |
72 |
Correct |
1044 ms |
90672 KB |
Output is correct |
73 |
Correct |
734 ms |
87708 KB |
Output is correct |
74 |
Correct |
654 ms |
88192 KB |
Output is correct |
75 |
Correct |
655 ms |
87536 KB |
Output is correct |
76 |
Correct |
679 ms |
87524 KB |
Output is correct |
77 |
Correct |
621 ms |
86616 KB |
Output is correct |
78 |
Correct |
928 ms |
89920 KB |
Output is correct |
79 |
Correct |
682 ms |
75796 KB |
Output is correct |
80 |
Correct |
953 ms |
82808 KB |
Output is correct |