/**
* author: NimaAryan
* created: 2023-10-26 14:32:00
**/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "algo/debug.h"
#endif
using i64 = long long;
struct Item {
int max_pair;
};
Item operator+(Item a, Item b) {
if (b.max_pair > a.max_pair) {
swap(a, b);
}
return a;
}
struct Fenwick {
vector<Item> fenw;
int n;
Fenwick(int n) : n(n) {
fenw.resize(n);
}
void modify(int x, Item v) {
for (int i = x + 1; i <= n; i += i & -i) {
fenw[i - 1] = fenw[i - 1] + v;
}
}
Item query(int x) {
Item res{};
for (int i = x; i > 0; i -= i & -i) {
res = res + fenw[i - 1];
}
return res;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, M;
cin >> N >> M;
vector<int> w(N);
for (int i = 0; i < N; ++i) {
cin >> w[i];
}
vector<int> l(M), r(M), k(M);
vector<vector<int>> qs(N);
for (int i = 0; i < M; ++i) {
cin >> l[i] >> r[i] >> k[i];
--l[i], --r[i];
qs[r[i]].push_back(i);
}
vector<int> L(N), stk;
for (int i = 0; i < N; ++i) {
while (!stk.empty() && w[stk.back()] <= w[i]) {
stk.pop_back();
}
L[i] = stk.empty() ? -1 : stk.back();
stk.push_back(i);
}
Fenwick fen(N); // i -> N-i-1
vector<int> ans(M);
for (int r = 0; r < N; ++r) {
if (L[r] != -1) {
fen.modify(N - L[r] - 1, Item{w[r] + w[L[r]]});
}
for (int i : qs[r]) {
ans[i] = fen.query(N - l[i]).max_pair <= k[i];
}
}
for (int i = 0; i < M; ++i) {
cout << ans[i] << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
860 KB |
Output is correct |
15 |
Correct |
3 ms |
844 KB |
Output is correct |
16 |
Correct |
2 ms |
1112 KB |
Output is correct |
17 |
Correct |
2 ms |
860 KB |
Output is correct |
18 |
Correct |
2 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
726 ms |
87284 KB |
Output is correct |
2 |
Correct |
747 ms |
87728 KB |
Output is correct |
3 |
Correct |
768 ms |
87876 KB |
Output is correct |
4 |
Correct |
729 ms |
87888 KB |
Output is correct |
5 |
Correct |
675 ms |
87836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
8532 KB |
Output is correct |
2 |
Correct |
39 ms |
8464 KB |
Output is correct |
3 |
Correct |
37 ms |
8960 KB |
Output is correct |
4 |
Correct |
38 ms |
9048 KB |
Output is correct |
5 |
Correct |
44 ms |
9292 KB |
Output is correct |
6 |
Correct |
31 ms |
8064 KB |
Output is correct |
7 |
Correct |
34 ms |
8020 KB |
Output is correct |
8 |
Correct |
35 ms |
8920 KB |
Output is correct |
9 |
Correct |
23 ms |
4004 KB |
Output is correct |
10 |
Correct |
36 ms |
8912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
860 KB |
Output is correct |
15 |
Correct |
3 ms |
844 KB |
Output is correct |
16 |
Correct |
2 ms |
1112 KB |
Output is correct |
17 |
Correct |
2 ms |
860 KB |
Output is correct |
18 |
Correct |
2 ms |
860 KB |
Output is correct |
19 |
Correct |
118 ms |
20756 KB |
Output is correct |
20 |
Correct |
101 ms |
20768 KB |
Output is correct |
21 |
Correct |
88 ms |
18908 KB |
Output is correct |
22 |
Correct |
90 ms |
18884 KB |
Output is correct |
23 |
Correct |
90 ms |
18872 KB |
Output is correct |
24 |
Correct |
79 ms |
18652 KB |
Output is correct |
25 |
Correct |
78 ms |
18708 KB |
Output is correct |
26 |
Correct |
85 ms |
19536 KB |
Output is correct |
27 |
Correct |
89 ms |
19388 KB |
Output is correct |
28 |
Correct |
86 ms |
19796 KB |
Output is correct |
29 |
Correct |
103 ms |
20672 KB |
Output is correct |
30 |
Correct |
92 ms |
20708 KB |
Output is correct |
31 |
Correct |
92 ms |
20560 KB |
Output is correct |
32 |
Correct |
93 ms |
20560 KB |
Output is correct |
33 |
Correct |
91 ms |
20776 KB |
Output is correct |
34 |
Correct |
73 ms |
18260 KB |
Output is correct |
35 |
Correct |
79 ms |
18260 KB |
Output is correct |
36 |
Correct |
73 ms |
18000 KB |
Output is correct |
37 |
Correct |
77 ms |
17976 KB |
Output is correct |
38 |
Correct |
72 ms |
18252 KB |
Output is correct |
39 |
Correct |
82 ms |
19084 KB |
Output is correct |
40 |
Correct |
70 ms |
15564 KB |
Output is correct |
41 |
Correct |
82 ms |
18724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
860 KB |
Output is correct |
15 |
Correct |
3 ms |
844 KB |
Output is correct |
16 |
Correct |
2 ms |
1112 KB |
Output is correct |
17 |
Correct |
2 ms |
860 KB |
Output is correct |
18 |
Correct |
2 ms |
860 KB |
Output is correct |
19 |
Correct |
726 ms |
87284 KB |
Output is correct |
20 |
Correct |
747 ms |
87728 KB |
Output is correct |
21 |
Correct |
768 ms |
87876 KB |
Output is correct |
22 |
Correct |
729 ms |
87888 KB |
Output is correct |
23 |
Correct |
675 ms |
87836 KB |
Output is correct |
24 |
Correct |
40 ms |
8532 KB |
Output is correct |
25 |
Correct |
39 ms |
8464 KB |
Output is correct |
26 |
Correct |
37 ms |
8960 KB |
Output is correct |
27 |
Correct |
38 ms |
9048 KB |
Output is correct |
28 |
Correct |
44 ms |
9292 KB |
Output is correct |
29 |
Correct |
31 ms |
8064 KB |
Output is correct |
30 |
Correct |
34 ms |
8020 KB |
Output is correct |
31 |
Correct |
35 ms |
8920 KB |
Output is correct |
32 |
Correct |
23 ms |
4004 KB |
Output is correct |
33 |
Correct |
36 ms |
8912 KB |
Output is correct |
34 |
Correct |
118 ms |
20756 KB |
Output is correct |
35 |
Correct |
101 ms |
20768 KB |
Output is correct |
36 |
Correct |
88 ms |
18908 KB |
Output is correct |
37 |
Correct |
90 ms |
18884 KB |
Output is correct |
38 |
Correct |
90 ms |
18872 KB |
Output is correct |
39 |
Correct |
79 ms |
18652 KB |
Output is correct |
40 |
Correct |
78 ms |
18708 KB |
Output is correct |
41 |
Correct |
85 ms |
19536 KB |
Output is correct |
42 |
Correct |
89 ms |
19388 KB |
Output is correct |
43 |
Correct |
86 ms |
19796 KB |
Output is correct |
44 |
Correct |
103 ms |
20672 KB |
Output is correct |
45 |
Correct |
92 ms |
20708 KB |
Output is correct |
46 |
Correct |
92 ms |
20560 KB |
Output is correct |
47 |
Correct |
93 ms |
20560 KB |
Output is correct |
48 |
Correct |
91 ms |
20776 KB |
Output is correct |
49 |
Correct |
73 ms |
18260 KB |
Output is correct |
50 |
Correct |
79 ms |
18260 KB |
Output is correct |
51 |
Correct |
73 ms |
18000 KB |
Output is correct |
52 |
Correct |
77 ms |
17976 KB |
Output is correct |
53 |
Correct |
72 ms |
18252 KB |
Output is correct |
54 |
Correct |
82 ms |
19084 KB |
Output is correct |
55 |
Correct |
70 ms |
15564 KB |
Output is correct |
56 |
Correct |
82 ms |
18724 KB |
Output is correct |
57 |
Correct |
693 ms |
102908 KB |
Output is correct |
58 |
Correct |
687 ms |
102996 KB |
Output is correct |
59 |
Correct |
599 ms |
98688 KB |
Output is correct |
60 |
Correct |
592 ms |
98812 KB |
Output is correct |
61 |
Correct |
636 ms |
99104 KB |
Output is correct |
62 |
Correct |
630 ms |
98992 KB |
Output is correct |
63 |
Correct |
424 ms |
90908 KB |
Output is correct |
64 |
Correct |
445 ms |
91288 KB |
Output is correct |
65 |
Correct |
543 ms |
98172 KB |
Output is correct |
66 |
Correct |
538 ms |
98304 KB |
Output is correct |
67 |
Correct |
579 ms |
98508 KB |
Output is correct |
68 |
Correct |
661 ms |
103020 KB |
Output is correct |
69 |
Correct |
699 ms |
103008 KB |
Output is correct |
70 |
Correct |
626 ms |
102484 KB |
Output is correct |
71 |
Correct |
635 ms |
102304 KB |
Output is correct |
72 |
Correct |
648 ms |
102420 KB |
Output is correct |
73 |
Correct |
358 ms |
89176 KB |
Output is correct |
74 |
Correct |
374 ms |
90704 KB |
Output is correct |
75 |
Correct |
408 ms |
89028 KB |
Output is correct |
76 |
Correct |
381 ms |
88812 KB |
Output is correct |
77 |
Correct |
379 ms |
88964 KB |
Output is correct |
78 |
Correct |
677 ms |
94944 KB |
Output is correct |
79 |
Correct |
496 ms |
71048 KB |
Output is correct |
80 |
Correct |
601 ms |
92784 KB |
Output is correct |