//Challenge: Accepted
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <map>
#define ll long long
#define ff first
#define ss second
#define maxn 1000005
using namespace std;
struct segtree{
int seg[4 * maxn];
void modify(int cur, int l, int r, int ind, int val) {
if (r <= l) return;
if (r - l == 1) {
seg[cur] = max(seg[cur], val);
//cout << l << " " << r << " " << val << endl;
return;
}
int mid = (l + r) / 2;
if (ind < mid) modify(cur * 2, l, mid, ind, val);
else modify(cur * 2 + 1, mid, r, ind, val);
seg[cur] = max(seg[cur * 2], seg[cur * 2 + 1]);
}
int query(int cur, int l, int r, int ql, int qr) {
if (r <= l || ql >= r || qr <= l) return 0;
if (ql <= l && qr >= r) return seg[cur];
int mid = (l + r) / 2;
return max(query(cur * 2, l, mid, ql, qr), query(cur * 2 + 1, mid, r, ql, qr));
}
}ans, id;
struct query{
int l = 0, r = 0, k = 0, id = 0;
} que[maxn];
inline bool cmp(query a, query b) {
return a.r < b.r;
}
inline bool cmp2 (pair<int, int> a, pair<int, int> b) {
return a.ss < b.ss;
}
int w[maxn];
vector<int> nums;
pair<int, int> mp[maxn];
bool ret[maxn];
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1;i <= n;i++) {
cin >> w[i];
mp[i] = make_pair(w[i], i);
}
sort(mp + 1, mp + 1 + n);
mp[1].ff = 1;
int cur = 1;
for (int i = 2;i <= n;i++) {
if (w[mp[i].ss] > w[mp[i - 1].ss]) cur++;
mp[i].ff = cur;
}
sort(mp + 1, mp + 1 + n, cmp2);
for (int i = 0;i < m;i++) {
cin >> que[i].l >> que[i].r >> que[i].k;
que[i].id = i;
que[i].r++;
}
sort(que, que + m, cmp);
cur = 1;
for (int i = 0;i < m;i++) {
while (cur < que[i].r) {
int upd = id.query(1, 0, n + 1, mp[cur].ff + 1, n + 1);
ans.modify(1, 0, n + 1, upd, w[upd] + w[cur]);
//cout << cur << " " << upd << " " << w[upd] + w[cur] << "\n";
id.modify(1, 0, n + 1, mp[cur].ff, cur);
//cout << cur << " " << mp[w[cur]] << endl;
cur++;
}
int x = ans.query(1, 0, n + 1, que[i].l, que[i].r);
//cerr << que[i].id << " " << x << endl;
ret[que[i].id] = x <= que[i].k ? 1 : 0;
}
for (int i = 0;i < m;i++) cout << (ret[i] ? 1 : 0) << "\n";
}
/*
5 2
3 5 1 8 2
1 3 6
2 5 3
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
492 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 |
364 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 |
492 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 |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
3 ms |
492 KB |
Output is correct |
12 |
Correct |
5 ms |
620 KB |
Output is correct |
13 |
Correct |
6 ms |
620 KB |
Output is correct |
14 |
Correct |
7 ms |
620 KB |
Output is correct |
15 |
Correct |
7 ms |
620 KB |
Output is correct |
16 |
Correct |
6 ms |
620 KB |
Output is correct |
17 |
Correct |
5 ms |
620 KB |
Output is correct |
18 |
Correct |
5 ms |
620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2280 ms |
47212 KB |
Output is correct |
2 |
Correct |
2257 ms |
47360 KB |
Output is correct |
3 |
Correct |
2272 ms |
47212 KB |
Output is correct |
4 |
Correct |
2274 ms |
47340 KB |
Output is correct |
5 |
Correct |
1538 ms |
39020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
143 ms |
4460 KB |
Output is correct |
2 |
Correct |
140 ms |
4460 KB |
Output is correct |
3 |
Correct |
115 ms |
3436 KB |
Output is correct |
4 |
Correct |
115 ms |
3564 KB |
Output is correct |
5 |
Correct |
116 ms |
3436 KB |
Output is correct |
6 |
Correct |
107 ms |
3564 KB |
Output is correct |
7 |
Correct |
105 ms |
3564 KB |
Output is correct |
8 |
Correct |
117 ms |
3564 KB |
Output is correct |
9 |
Correct |
48 ms |
2284 KB |
Output is correct |
10 |
Correct |
114 ms |
3564 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 |
492 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 |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
3 ms |
492 KB |
Output is correct |
12 |
Correct |
5 ms |
620 KB |
Output is correct |
13 |
Correct |
6 ms |
620 KB |
Output is correct |
14 |
Correct |
7 ms |
620 KB |
Output is correct |
15 |
Correct |
7 ms |
620 KB |
Output is correct |
16 |
Correct |
6 ms |
620 KB |
Output is correct |
17 |
Correct |
5 ms |
620 KB |
Output is correct |
18 |
Correct |
5 ms |
620 KB |
Output is correct |
19 |
Correct |
370 ms |
10604 KB |
Output is correct |
20 |
Correct |
371 ms |
10732 KB |
Output is correct |
21 |
Correct |
339 ms |
10604 KB |
Output is correct |
22 |
Correct |
341 ms |
10732 KB |
Output is correct |
23 |
Correct |
342 ms |
10644 KB |
Output is correct |
24 |
Correct |
261 ms |
8556 KB |
Output is correct |
25 |
Correct |
259 ms |
8556 KB |
Output is correct |
26 |
Correct |
275 ms |
8556 KB |
Output is correct |
27 |
Correct |
270 ms |
8556 KB |
Output is correct |
28 |
Correct |
275 ms |
8556 KB |
Output is correct |
29 |
Correct |
280 ms |
8556 KB |
Output is correct |
30 |
Correct |
278 ms |
8556 KB |
Output is correct |
31 |
Correct |
290 ms |
8556 KB |
Output is correct |
32 |
Correct |
280 ms |
8684 KB |
Output is correct |
33 |
Correct |
276 ms |
8556 KB |
Output is correct |
34 |
Correct |
253 ms |
8556 KB |
Output is correct |
35 |
Correct |
258 ms |
8556 KB |
Output is correct |
36 |
Correct |
247 ms |
8556 KB |
Output is correct |
37 |
Correct |
250 ms |
8556 KB |
Output is correct |
38 |
Correct |
254 ms |
8684 KB |
Output is correct |
39 |
Correct |
271 ms |
9324 KB |
Output is correct |
40 |
Correct |
203 ms |
6764 KB |
Output is correct |
41 |
Correct |
249 ms |
6636 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 |
492 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 |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
3 ms |
492 KB |
Output is correct |
12 |
Correct |
5 ms |
620 KB |
Output is correct |
13 |
Correct |
6 ms |
620 KB |
Output is correct |
14 |
Correct |
7 ms |
620 KB |
Output is correct |
15 |
Correct |
7 ms |
620 KB |
Output is correct |
16 |
Correct |
6 ms |
620 KB |
Output is correct |
17 |
Correct |
5 ms |
620 KB |
Output is correct |
18 |
Correct |
5 ms |
620 KB |
Output is correct |
19 |
Correct |
2280 ms |
47212 KB |
Output is correct |
20 |
Correct |
2257 ms |
47360 KB |
Output is correct |
21 |
Correct |
2272 ms |
47212 KB |
Output is correct |
22 |
Correct |
2274 ms |
47340 KB |
Output is correct |
23 |
Correct |
1538 ms |
39020 KB |
Output is correct |
24 |
Correct |
143 ms |
4460 KB |
Output is correct |
25 |
Correct |
140 ms |
4460 KB |
Output is correct |
26 |
Correct |
115 ms |
3436 KB |
Output is correct |
27 |
Correct |
115 ms |
3564 KB |
Output is correct |
28 |
Correct |
116 ms |
3436 KB |
Output is correct |
29 |
Correct |
107 ms |
3564 KB |
Output is correct |
30 |
Correct |
105 ms |
3564 KB |
Output is correct |
31 |
Correct |
117 ms |
3564 KB |
Output is correct |
32 |
Correct |
48 ms |
2284 KB |
Output is correct |
33 |
Correct |
114 ms |
3564 KB |
Output is correct |
34 |
Correct |
370 ms |
10604 KB |
Output is correct |
35 |
Correct |
371 ms |
10732 KB |
Output is correct |
36 |
Correct |
339 ms |
10604 KB |
Output is correct |
37 |
Correct |
341 ms |
10732 KB |
Output is correct |
38 |
Correct |
342 ms |
10644 KB |
Output is correct |
39 |
Correct |
261 ms |
8556 KB |
Output is correct |
40 |
Correct |
259 ms |
8556 KB |
Output is correct |
41 |
Correct |
275 ms |
8556 KB |
Output is correct |
42 |
Correct |
270 ms |
8556 KB |
Output is correct |
43 |
Correct |
275 ms |
8556 KB |
Output is correct |
44 |
Correct |
280 ms |
8556 KB |
Output is correct |
45 |
Correct |
278 ms |
8556 KB |
Output is correct |
46 |
Correct |
290 ms |
8556 KB |
Output is correct |
47 |
Correct |
280 ms |
8684 KB |
Output is correct |
48 |
Correct |
276 ms |
8556 KB |
Output is correct |
49 |
Correct |
253 ms |
8556 KB |
Output is correct |
50 |
Correct |
258 ms |
8556 KB |
Output is correct |
51 |
Correct |
247 ms |
8556 KB |
Output is correct |
52 |
Correct |
250 ms |
8556 KB |
Output is correct |
53 |
Correct |
254 ms |
8684 KB |
Output is correct |
54 |
Correct |
271 ms |
9324 KB |
Output is correct |
55 |
Correct |
203 ms |
6764 KB |
Output is correct |
56 |
Correct |
249 ms |
6636 KB |
Output is correct |
57 |
Correct |
2255 ms |
49872 KB |
Output is correct |
58 |
Correct |
2271 ms |
48748 KB |
Output is correct |
59 |
Correct |
2189 ms |
48748 KB |
Output is correct |
60 |
Correct |
2199 ms |
48844 KB |
Output is correct |
61 |
Correct |
2173 ms |
48756 KB |
Output is correct |
62 |
Correct |
2198 ms |
48864 KB |
Output is correct |
63 |
Correct |
1397 ms |
39016 KB |
Output is correct |
64 |
Correct |
1408 ms |
39052 KB |
Output is correct |
65 |
Correct |
1530 ms |
40684 KB |
Output is correct |
66 |
Correct |
1511 ms |
40564 KB |
Output is correct |
67 |
Correct |
1506 ms |
40708 KB |
Output is correct |
68 |
Correct |
1530 ms |
40656 KB |
Output is correct |
69 |
Correct |
1527 ms |
40604 KB |
Output is correct |
70 |
Correct |
1521 ms |
40796 KB |
Output is correct |
71 |
Correct |
1531 ms |
40684 KB |
Output is correct |
72 |
Correct |
1532 ms |
40556 KB |
Output is correct |
73 |
Correct |
1343 ms |
39148 KB |
Output is correct |
74 |
Correct |
1391 ms |
39148 KB |
Output is correct |
75 |
Correct |
1357 ms |
39148 KB |
Output is correct |
76 |
Correct |
1417 ms |
39224 KB |
Output is correct |
77 |
Correct |
1341 ms |
39148 KB |
Output is correct |
78 |
Correct |
1557 ms |
41836 KB |
Output is correct |
79 |
Correct |
1024 ms |
29420 KB |
Output is correct |
80 |
Correct |
1428 ms |
30956 KB |
Output is correct |