#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9 + 9;
const ll LOGN = 21;
const ll MAXN = 1e6 + 100;
struct Query {
int l, r, k, id;
Query(int _l, int _r, int _k, int _id) : l(_l), r(_r), k(_k), id(_id) { }
};
vector<Query> Q[MAXN];
int ans[MAXN], w[MAXN], fen[MAXN];
void update(int k, int val) {
while (k) {
fen[k] = max(fen[k], val);
k -= k & -k;
}
}
int get(int k) {
int mx = 0;
while (k < MAXN) {
mx = max(mx, fen[k]);
k += k & -k;
}
return mx;
}
int main() {
fast
int N, M, l, r, k;
cin >> N >> M;
w[0] = 1e9 + 100;
for (int i = 1; i <= N; i++)
cin >> w[i];
for (int i = 0; i < M; i++) {
cin >> l >> r >> k;
Q[r].push_back(Query(l, r, k, i));
}
stack<int> st;
st.push(0);
for (int i = 1; i <= N; i++) {
while (w[st.top()] <= w[i])
st.pop();
update(st.top(), w[st.top()] + w[i]);
st.push(i);
for (auto u : Q[i])
ans[u.id] = get(u.l) <= u.k;
}
for (int i = 0; i < M; i++)
cout << ans[i] << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
29276 KB |
Output is correct |
2 |
Correct |
6 ms |
29344 KB |
Output is correct |
3 |
Correct |
6 ms |
29276 KB |
Output is correct |
4 |
Correct |
6 ms |
29276 KB |
Output is correct |
5 |
Correct |
6 ms |
29276 KB |
Output is correct |
6 |
Correct |
6 ms |
29276 KB |
Output is correct |
7 |
Correct |
6 ms |
29276 KB |
Output is correct |
8 |
Correct |
6 ms |
29276 KB |
Output is correct |
9 |
Correct |
6 ms |
29276 KB |
Output is correct |
10 |
Correct |
6 ms |
29140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
29276 KB |
Output is correct |
2 |
Correct |
6 ms |
29344 KB |
Output is correct |
3 |
Correct |
6 ms |
29276 KB |
Output is correct |
4 |
Correct |
6 ms |
29276 KB |
Output is correct |
5 |
Correct |
6 ms |
29276 KB |
Output is correct |
6 |
Correct |
6 ms |
29276 KB |
Output is correct |
7 |
Correct |
6 ms |
29276 KB |
Output is correct |
8 |
Correct |
6 ms |
29276 KB |
Output is correct |
9 |
Correct |
6 ms |
29276 KB |
Output is correct |
10 |
Correct |
6 ms |
29140 KB |
Output is correct |
11 |
Correct |
7 ms |
29272 KB |
Output is correct |
12 |
Correct |
7 ms |
29388 KB |
Output is correct |
13 |
Correct |
7 ms |
29532 KB |
Output is correct |
14 |
Correct |
8 ms |
29528 KB |
Output is correct |
15 |
Correct |
8 ms |
29532 KB |
Output is correct |
16 |
Correct |
8 ms |
29532 KB |
Output is correct |
17 |
Correct |
8 ms |
29532 KB |
Output is correct |
18 |
Correct |
7 ms |
29532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
635 ms |
94724 KB |
Output is correct |
2 |
Correct |
637 ms |
92244 KB |
Output is correct |
3 |
Correct |
635 ms |
91904 KB |
Output is correct |
4 |
Correct |
625 ms |
92240 KB |
Output is correct |
5 |
Correct |
632 ms |
90040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
36436 KB |
Output is correct |
2 |
Correct |
44 ms |
36432 KB |
Output is correct |
3 |
Correct |
43 ms |
35924 KB |
Output is correct |
4 |
Correct |
43 ms |
35928 KB |
Output is correct |
5 |
Correct |
44 ms |
35928 KB |
Output is correct |
6 |
Correct |
36 ms |
35668 KB |
Output is correct |
7 |
Correct |
36 ms |
35580 KB |
Output is correct |
8 |
Correct |
42 ms |
35536 KB |
Output is correct |
9 |
Correct |
30 ms |
32720 KB |
Output is correct |
10 |
Correct |
42 ms |
35456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
29276 KB |
Output is correct |
2 |
Correct |
6 ms |
29344 KB |
Output is correct |
3 |
Correct |
6 ms |
29276 KB |
Output is correct |
4 |
Correct |
6 ms |
29276 KB |
Output is correct |
5 |
Correct |
6 ms |
29276 KB |
Output is correct |
6 |
Correct |
6 ms |
29276 KB |
Output is correct |
7 |
Correct |
6 ms |
29276 KB |
Output is correct |
8 |
Correct |
6 ms |
29276 KB |
Output is correct |
9 |
Correct |
6 ms |
29276 KB |
Output is correct |
10 |
Correct |
6 ms |
29140 KB |
Output is correct |
11 |
Correct |
7 ms |
29272 KB |
Output is correct |
12 |
Correct |
7 ms |
29388 KB |
Output is correct |
13 |
Correct |
7 ms |
29532 KB |
Output is correct |
14 |
Correct |
8 ms |
29528 KB |
Output is correct |
15 |
Correct |
8 ms |
29532 KB |
Output is correct |
16 |
Correct |
8 ms |
29532 KB |
Output is correct |
17 |
Correct |
8 ms |
29532 KB |
Output is correct |
18 |
Correct |
7 ms |
29532 KB |
Output is correct |
19 |
Correct |
107 ms |
45908 KB |
Output is correct |
20 |
Correct |
101 ms |
45652 KB |
Output is correct |
21 |
Correct |
98 ms |
45408 KB |
Output is correct |
22 |
Correct |
95 ms |
45516 KB |
Output is correct |
23 |
Correct |
90 ms |
45392 KB |
Output is correct |
24 |
Correct |
83 ms |
44420 KB |
Output is correct |
25 |
Correct |
84 ms |
45076 KB |
Output is correct |
26 |
Correct |
92 ms |
45380 KB |
Output is correct |
27 |
Correct |
94 ms |
45208 KB |
Output is correct |
28 |
Correct |
92 ms |
45140 KB |
Output is correct |
29 |
Correct |
104 ms |
45516 KB |
Output is correct |
30 |
Correct |
104 ms |
45396 KB |
Output is correct |
31 |
Correct |
101 ms |
45484 KB |
Output is correct |
32 |
Correct |
100 ms |
45568 KB |
Output is correct |
33 |
Correct |
112 ms |
45312 KB |
Output is correct |
34 |
Correct |
76 ms |
44424 KB |
Output is correct |
35 |
Correct |
87 ms |
44548 KB |
Output is correct |
36 |
Correct |
76 ms |
44112 KB |
Output is correct |
37 |
Correct |
80 ms |
44128 KB |
Output is correct |
38 |
Correct |
79 ms |
44372 KB |
Output is correct |
39 |
Correct |
93 ms |
43968 KB |
Output is correct |
40 |
Correct |
84 ms |
42552 KB |
Output is correct |
41 |
Correct |
91 ms |
43200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
29276 KB |
Output is correct |
2 |
Correct |
6 ms |
29344 KB |
Output is correct |
3 |
Correct |
6 ms |
29276 KB |
Output is correct |
4 |
Correct |
6 ms |
29276 KB |
Output is correct |
5 |
Correct |
6 ms |
29276 KB |
Output is correct |
6 |
Correct |
6 ms |
29276 KB |
Output is correct |
7 |
Correct |
6 ms |
29276 KB |
Output is correct |
8 |
Correct |
6 ms |
29276 KB |
Output is correct |
9 |
Correct |
6 ms |
29276 KB |
Output is correct |
10 |
Correct |
6 ms |
29140 KB |
Output is correct |
11 |
Correct |
7 ms |
29272 KB |
Output is correct |
12 |
Correct |
7 ms |
29388 KB |
Output is correct |
13 |
Correct |
7 ms |
29532 KB |
Output is correct |
14 |
Correct |
8 ms |
29528 KB |
Output is correct |
15 |
Correct |
8 ms |
29532 KB |
Output is correct |
16 |
Correct |
8 ms |
29532 KB |
Output is correct |
17 |
Correct |
8 ms |
29532 KB |
Output is correct |
18 |
Correct |
7 ms |
29532 KB |
Output is correct |
19 |
Correct |
635 ms |
94724 KB |
Output is correct |
20 |
Correct |
637 ms |
92244 KB |
Output is correct |
21 |
Correct |
635 ms |
91904 KB |
Output is correct |
22 |
Correct |
625 ms |
92240 KB |
Output is correct |
23 |
Correct |
632 ms |
90040 KB |
Output is correct |
24 |
Correct |
46 ms |
36436 KB |
Output is correct |
25 |
Correct |
44 ms |
36432 KB |
Output is correct |
26 |
Correct |
43 ms |
35924 KB |
Output is correct |
27 |
Correct |
43 ms |
35928 KB |
Output is correct |
28 |
Correct |
44 ms |
35928 KB |
Output is correct |
29 |
Correct |
36 ms |
35668 KB |
Output is correct |
30 |
Correct |
36 ms |
35580 KB |
Output is correct |
31 |
Correct |
42 ms |
35536 KB |
Output is correct |
32 |
Correct |
30 ms |
32720 KB |
Output is correct |
33 |
Correct |
42 ms |
35456 KB |
Output is correct |
34 |
Correct |
107 ms |
45908 KB |
Output is correct |
35 |
Correct |
101 ms |
45652 KB |
Output is correct |
36 |
Correct |
98 ms |
45408 KB |
Output is correct |
37 |
Correct |
95 ms |
45516 KB |
Output is correct |
38 |
Correct |
90 ms |
45392 KB |
Output is correct |
39 |
Correct |
83 ms |
44420 KB |
Output is correct |
40 |
Correct |
84 ms |
45076 KB |
Output is correct |
41 |
Correct |
92 ms |
45380 KB |
Output is correct |
42 |
Correct |
94 ms |
45208 KB |
Output is correct |
43 |
Correct |
92 ms |
45140 KB |
Output is correct |
44 |
Correct |
104 ms |
45516 KB |
Output is correct |
45 |
Correct |
104 ms |
45396 KB |
Output is correct |
46 |
Correct |
101 ms |
45484 KB |
Output is correct |
47 |
Correct |
100 ms |
45568 KB |
Output is correct |
48 |
Correct |
112 ms |
45312 KB |
Output is correct |
49 |
Correct |
76 ms |
44424 KB |
Output is correct |
50 |
Correct |
87 ms |
44548 KB |
Output is correct |
51 |
Correct |
76 ms |
44112 KB |
Output is correct |
52 |
Correct |
80 ms |
44128 KB |
Output is correct |
53 |
Correct |
79 ms |
44372 KB |
Output is correct |
54 |
Correct |
93 ms |
43968 KB |
Output is correct |
55 |
Correct |
84 ms |
42552 KB |
Output is correct |
56 |
Correct |
91 ms |
43200 KB |
Output is correct |
57 |
Correct |
730 ms |
95180 KB |
Output is correct |
58 |
Correct |
632 ms |
95056 KB |
Output is correct |
59 |
Correct |
615 ms |
94080 KB |
Output is correct |
60 |
Correct |
601 ms |
94484 KB |
Output is correct |
61 |
Correct |
578 ms |
94828 KB |
Output is correct |
62 |
Correct |
573 ms |
95232 KB |
Output is correct |
63 |
Correct |
381 ms |
90892 KB |
Output is correct |
64 |
Correct |
382 ms |
91028 KB |
Output is correct |
65 |
Correct |
581 ms |
93008 KB |
Output is correct |
66 |
Correct |
529 ms |
91748 KB |
Output is correct |
67 |
Correct |
572 ms |
91964 KB |
Output is correct |
68 |
Correct |
639 ms |
92800 KB |
Output is correct |
69 |
Correct |
614 ms |
93008 KB |
Output is correct |
70 |
Correct |
585 ms |
92528 KB |
Output is correct |
71 |
Correct |
598 ms |
92704 KB |
Output is correct |
72 |
Correct |
589 ms |
92792 KB |
Output is correct |
73 |
Correct |
352 ms |
85016 KB |
Output is correct |
74 |
Correct |
378 ms |
85584 KB |
Output is correct |
75 |
Correct |
356 ms |
85180 KB |
Output is correct |
76 |
Correct |
354 ms |
85008 KB |
Output is correct |
77 |
Correct |
358 ms |
84868 KB |
Output is correct |
78 |
Correct |
537 ms |
86140 KB |
Output is correct |
79 |
Correct |
413 ms |
78256 KB |
Output is correct |
80 |
Correct |
503 ms |
82352 KB |
Output is correct |