#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
using namespace std;
typedef pair<int, int> pii;
struct _qs {
int l, r, k, i;
void scan(int idx) {
i = idx;
cin >> l >> r >> k;
}
bool operator<(const _qs &p) const {
return l > p.l;
}
} qs[1000000];
bool ans[1000000];
int n, q;
int W[1000001];
int fen[1000001];
void update(int i, int x) {
while (i <= n) {
fen[i] = max(fen[i], x);
i += i & -i;
}
}
int query(int i) {
int r = 0;
while (i) {
r = max(r, fen[i]);
i -= i & -i;
}
return r;
}
vector<int> R[1000001];
void add(int l, int r) {
R[l].push_back(r);
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> q;
for (int i = 1; i <= n; ++i) cin >> W[i];
vector<int> st;
for (int i = n; i > 0; --i) {
while (!st.empty() && W[st.back()] < W[i]) {
add(i, st.back());
st.pop_back();
}
st.push_back(i);
}
for (int i = 0; i < q; ++i) qs[i].scan(i);
sort(qs, qs + q);
for (int i = 0, j = n + 1; i < q; ++i) {
while (qs[i].l < j) {
for (int k : R[--j]) {
update(k, W[j] + W[k]);
}
}
ans[qs[i].i] = query(qs[i].r) <= qs[i].k;
}
for (int i = 0; i < q; ++i) printf("%d\n", (int)ans[i]);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
23800 KB |
Output is correct |
2 |
Correct |
24 ms |
23800 KB |
Output is correct |
3 |
Correct |
24 ms |
23928 KB |
Output is correct |
4 |
Correct |
24 ms |
23800 KB |
Output is correct |
5 |
Correct |
23 ms |
23928 KB |
Output is correct |
6 |
Correct |
24 ms |
23928 KB |
Output is correct |
7 |
Correct |
24 ms |
23928 KB |
Output is correct |
8 |
Correct |
23 ms |
23928 KB |
Output is correct |
9 |
Correct |
24 ms |
23896 KB |
Output is correct |
10 |
Correct |
24 ms |
23836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
23800 KB |
Output is correct |
2 |
Correct |
24 ms |
23800 KB |
Output is correct |
3 |
Correct |
24 ms |
23928 KB |
Output is correct |
4 |
Correct |
24 ms |
23800 KB |
Output is correct |
5 |
Correct |
23 ms |
23928 KB |
Output is correct |
6 |
Correct |
24 ms |
23928 KB |
Output is correct |
7 |
Correct |
24 ms |
23928 KB |
Output is correct |
8 |
Correct |
23 ms |
23928 KB |
Output is correct |
9 |
Correct |
24 ms |
23896 KB |
Output is correct |
10 |
Correct |
24 ms |
23836 KB |
Output is correct |
11 |
Correct |
25 ms |
24056 KB |
Output is correct |
12 |
Correct |
26 ms |
24184 KB |
Output is correct |
13 |
Correct |
26 ms |
24184 KB |
Output is correct |
14 |
Correct |
28 ms |
24284 KB |
Output is correct |
15 |
Correct |
29 ms |
24312 KB |
Output is correct |
16 |
Correct |
27 ms |
24152 KB |
Output is correct |
17 |
Correct |
26 ms |
24060 KB |
Output is correct |
18 |
Correct |
26 ms |
24056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
876 ms |
98404 KB |
Output is correct |
2 |
Correct |
926 ms |
99552 KB |
Output is correct |
3 |
Correct |
892 ms |
99320 KB |
Output is correct |
4 |
Correct |
886 ms |
99368 KB |
Output is correct |
5 |
Correct |
773 ms |
83424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
30204 KB |
Output is correct |
2 |
Correct |
94 ms |
30044 KB |
Output is correct |
3 |
Correct |
84 ms |
28660 KB |
Output is correct |
4 |
Correct |
87 ms |
28660 KB |
Output is correct |
5 |
Correct |
85 ms |
28876 KB |
Output is correct |
6 |
Correct |
79 ms |
28468 KB |
Output is correct |
7 |
Correct |
80 ms |
28536 KB |
Output is correct |
8 |
Correct |
81 ms |
28660 KB |
Output is correct |
9 |
Correct |
65 ms |
27128 KB |
Output is correct |
10 |
Correct |
81 ms |
28600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
23800 KB |
Output is correct |
2 |
Correct |
24 ms |
23800 KB |
Output is correct |
3 |
Correct |
24 ms |
23928 KB |
Output is correct |
4 |
Correct |
24 ms |
23800 KB |
Output is correct |
5 |
Correct |
23 ms |
23928 KB |
Output is correct |
6 |
Correct |
24 ms |
23928 KB |
Output is correct |
7 |
Correct |
24 ms |
23928 KB |
Output is correct |
8 |
Correct |
23 ms |
23928 KB |
Output is correct |
9 |
Correct |
24 ms |
23896 KB |
Output is correct |
10 |
Correct |
24 ms |
23836 KB |
Output is correct |
11 |
Correct |
25 ms |
24056 KB |
Output is correct |
12 |
Correct |
26 ms |
24184 KB |
Output is correct |
13 |
Correct |
26 ms |
24184 KB |
Output is correct |
14 |
Correct |
28 ms |
24284 KB |
Output is correct |
15 |
Correct |
29 ms |
24312 KB |
Output is correct |
16 |
Correct |
27 ms |
24152 KB |
Output is correct |
17 |
Correct |
26 ms |
24060 KB |
Output is correct |
18 |
Correct |
26 ms |
24056 KB |
Output is correct |
19 |
Correct |
197 ms |
38972 KB |
Output is correct |
20 |
Correct |
197 ms |
38904 KB |
Output is correct |
21 |
Correct |
188 ms |
38856 KB |
Output is correct |
22 |
Correct |
189 ms |
38776 KB |
Output is correct |
23 |
Correct |
190 ms |
38928 KB |
Output is correct |
24 |
Correct |
167 ms |
35656 KB |
Output is correct |
25 |
Correct |
164 ms |
35604 KB |
Output is correct |
26 |
Correct |
168 ms |
35780 KB |
Output is correct |
27 |
Correct |
168 ms |
35772 KB |
Output is correct |
28 |
Correct |
167 ms |
35820 KB |
Output is correct |
29 |
Correct |
172 ms |
35912 KB |
Output is correct |
30 |
Correct |
171 ms |
35948 KB |
Output is correct |
31 |
Correct |
172 ms |
35884 KB |
Output is correct |
32 |
Correct |
172 ms |
35820 KB |
Output is correct |
33 |
Correct |
174 ms |
35912 KB |
Output is correct |
34 |
Correct |
158 ms |
35616 KB |
Output is correct |
35 |
Correct |
158 ms |
35496 KB |
Output is correct |
36 |
Correct |
155 ms |
35316 KB |
Output is correct |
37 |
Correct |
156 ms |
35312 KB |
Output is correct |
38 |
Correct |
162 ms |
35440 KB |
Output is correct |
39 |
Correct |
161 ms |
35436 KB |
Output is correct |
40 |
Correct |
143 ms |
33480 KB |
Output is correct |
41 |
Correct |
158 ms |
34408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
23800 KB |
Output is correct |
2 |
Correct |
24 ms |
23800 KB |
Output is correct |
3 |
Correct |
24 ms |
23928 KB |
Output is correct |
4 |
Correct |
24 ms |
23800 KB |
Output is correct |
5 |
Correct |
23 ms |
23928 KB |
Output is correct |
6 |
Correct |
24 ms |
23928 KB |
Output is correct |
7 |
Correct |
24 ms |
23928 KB |
Output is correct |
8 |
Correct |
23 ms |
23928 KB |
Output is correct |
9 |
Correct |
24 ms |
23896 KB |
Output is correct |
10 |
Correct |
24 ms |
23836 KB |
Output is correct |
11 |
Correct |
25 ms |
24056 KB |
Output is correct |
12 |
Correct |
26 ms |
24184 KB |
Output is correct |
13 |
Correct |
26 ms |
24184 KB |
Output is correct |
14 |
Correct |
28 ms |
24284 KB |
Output is correct |
15 |
Correct |
29 ms |
24312 KB |
Output is correct |
16 |
Correct |
27 ms |
24152 KB |
Output is correct |
17 |
Correct |
26 ms |
24060 KB |
Output is correct |
18 |
Correct |
26 ms |
24056 KB |
Output is correct |
19 |
Correct |
876 ms |
98404 KB |
Output is correct |
20 |
Correct |
926 ms |
99552 KB |
Output is correct |
21 |
Correct |
892 ms |
99320 KB |
Output is correct |
22 |
Correct |
886 ms |
99368 KB |
Output is correct |
23 |
Correct |
773 ms |
83424 KB |
Output is correct |
24 |
Correct |
97 ms |
30204 KB |
Output is correct |
25 |
Correct |
94 ms |
30044 KB |
Output is correct |
26 |
Correct |
84 ms |
28660 KB |
Output is correct |
27 |
Correct |
87 ms |
28660 KB |
Output is correct |
28 |
Correct |
85 ms |
28876 KB |
Output is correct |
29 |
Correct |
79 ms |
28468 KB |
Output is correct |
30 |
Correct |
80 ms |
28536 KB |
Output is correct |
31 |
Correct |
81 ms |
28660 KB |
Output is correct |
32 |
Correct |
65 ms |
27128 KB |
Output is correct |
33 |
Correct |
81 ms |
28600 KB |
Output is correct |
34 |
Correct |
197 ms |
38972 KB |
Output is correct |
35 |
Correct |
197 ms |
38904 KB |
Output is correct |
36 |
Correct |
188 ms |
38856 KB |
Output is correct |
37 |
Correct |
189 ms |
38776 KB |
Output is correct |
38 |
Correct |
190 ms |
38928 KB |
Output is correct |
39 |
Correct |
167 ms |
35656 KB |
Output is correct |
40 |
Correct |
164 ms |
35604 KB |
Output is correct |
41 |
Correct |
168 ms |
35780 KB |
Output is correct |
42 |
Correct |
168 ms |
35772 KB |
Output is correct |
43 |
Correct |
167 ms |
35820 KB |
Output is correct |
44 |
Correct |
172 ms |
35912 KB |
Output is correct |
45 |
Correct |
171 ms |
35948 KB |
Output is correct |
46 |
Correct |
172 ms |
35884 KB |
Output is correct |
47 |
Correct |
172 ms |
35820 KB |
Output is correct |
48 |
Correct |
174 ms |
35912 KB |
Output is correct |
49 |
Correct |
158 ms |
35616 KB |
Output is correct |
50 |
Correct |
158 ms |
35496 KB |
Output is correct |
51 |
Correct |
155 ms |
35316 KB |
Output is correct |
52 |
Correct |
156 ms |
35312 KB |
Output is correct |
53 |
Correct |
162 ms |
35440 KB |
Output is correct |
54 |
Correct |
161 ms |
35436 KB |
Output is correct |
55 |
Correct |
143 ms |
33480 KB |
Output is correct |
56 |
Correct |
158 ms |
34408 KB |
Output is correct |
57 |
Correct |
921 ms |
100168 KB |
Output is correct |
58 |
Correct |
902 ms |
100064 KB |
Output is correct |
59 |
Correct |
889 ms |
100160 KB |
Output is correct |
60 |
Correct |
889 ms |
100088 KB |
Output is correct |
61 |
Correct |
893 ms |
99928 KB |
Output is correct |
62 |
Correct |
891 ms |
100024 KB |
Output is correct |
63 |
Correct |
723 ms |
82272 KB |
Output is correct |
64 |
Correct |
722 ms |
82072 KB |
Output is correct |
65 |
Correct |
764 ms |
83812 KB |
Output is correct |
66 |
Correct |
768 ms |
83800 KB |
Output is correct |
67 |
Correct |
764 ms |
83888 KB |
Output is correct |
68 |
Correct |
769 ms |
84004 KB |
Output is correct |
69 |
Correct |
767 ms |
83984 KB |
Output is correct |
70 |
Correct |
788 ms |
84020 KB |
Output is correct |
71 |
Correct |
767 ms |
83932 KB |
Output is correct |
72 |
Correct |
771 ms |
84064 KB |
Output is correct |
73 |
Correct |
691 ms |
80608 KB |
Output is correct |
74 |
Correct |
720 ms |
81504 KB |
Output is correct |
75 |
Correct |
694 ms |
80740 KB |
Output is correct |
76 |
Correct |
699 ms |
80736 KB |
Output is correct |
77 |
Correct |
709 ms |
80608 KB |
Output is correct |
78 |
Correct |
754 ms |
83176 KB |
Output is correct |
79 |
Correct |
614 ms |
70248 KB |
Output is correct |
80 |
Correct |
709 ms |
78688 KB |
Output is correct |