#include <bits/stdc++.h>
using namespace std;
const long long INF1 = 1000000000000;
const long long INF2 = 100000000000000;
//RAQ+RMQ
struct lazy_segment_tree{
int N;
vector<long long> ST, lazy;
lazy_segment_tree(vector<long long> &A){
int N2 = A.size();
N = 1;
while (N < N2){
N *= 2;
}
ST = vector<long long>(N * 2 - 1, -INF2);
for (int i = 0; i < N2; i++){
ST[N - 1 + i] = A[i];
}
for (int i = N - 2; i >= 0; i--){
ST[i] = max(ST[i * 2 + 1], ST[i * 2 + 2]);
}
lazy = vector<long long>(N * 2 - 1, 0);
}
void eval(int i){
if (i < N - 1){
lazy[i * 2 + 1] += lazy[i];
lazy[i * 2 + 2] += lazy[i];
}
ST[i] += lazy[i];
lazy[i] = 0;
}
void range_add(int L, int R, long long x, int i, int l, int r){
eval(i);
if (r <= L || R <= l){
} else if (L <= l && r <= R){
lazy[i] += x;
eval(i);
} else {
int m = (l + r) / 2;
range_add(L, R, x, i * 2 + 1, l, m);
range_add(L, R, x, i * 2 + 2, m, r);
ST[i] = max(ST[i * 2 + 1], ST[i * 2 + 2]);
}
}
void range_add(int L, int R, long long x){
range_add(L, R, x, 0, 0, N);
}
long long range_max(int L, int R, int i, int l, int r){
eval(i);
if (r <= L || R <= l){
return -INF2;
} else if (L <= l && r <= R){
return ST[i];
} else {
int m = (l + r) / 2;
return max(range_max(L, R, i * 2 + 1, l, m), range_max(L, R, i * 2 + 2, m, r));
}
}
long long range_max(int L, int R){
return range_max(L, R, 0, 0, N);
}
};
int main(){
int N, M;
cin >> N >> M;
vector<long long> w(N);
for (int i = 0; i < N; i++){
cin >> w[i];
}
vector<int> l(M), r(M);
vector<long long> k(M);
for (int i = 0; i < M; i++){
cin >> l[i] >> r[i] >> k[i];
l[i]--;
}
vector<vector<int>> query(N);
for (int i = 0; i < M; i++){
query[l[i]].push_back(i);
}
lazy_segment_tree ST(w);
stack<int> st;
st.push(N);
vector<long long> mx(M, 0);
for (int i = N - 1; i >= 0; i--){
while (st.top() != N){
int p = st.top();
if (w[i] <= w[p]){
break;
}
st.pop();
int q = st.top();
ST.range_add(p, p + 1, INF1);
ST.range_add(p + 1, q, -w[p]);
}
int p = st.top();
ST.range_add(i, i + 1, -INF1);
ST.range_add(i + 1, p, w[i]);
st.push(i);
for (int j : query[i]){
mx[j] = ST.range_max(i, r[j]);
}
}
for (int i = 0; i < M; i++){
if (mx[i] <= k[i]){
cout << 1 << endl;
} else {
cout << 0 << endl;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
224 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
224 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
9 ms |
468 KB |
Output is correct |
12 |
Correct |
14 ms |
852 KB |
Output is correct |
13 |
Correct |
14 ms |
864 KB |
Output is correct |
14 |
Correct |
20 ms |
940 KB |
Output is correct |
15 |
Correct |
21 ms |
844 KB |
Output is correct |
16 |
Correct |
16 ms |
928 KB |
Output is correct |
17 |
Correct |
14 ms |
728 KB |
Output is correct |
18 |
Correct |
17 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3075 ms |
105832 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
405 ms |
12200 KB |
Output is correct |
2 |
Correct |
391 ms |
13124 KB |
Output is correct |
3 |
Correct |
354 ms |
14168 KB |
Output is correct |
4 |
Correct |
351 ms |
14336 KB |
Output is correct |
5 |
Correct |
365 ms |
14380 KB |
Output is correct |
6 |
Correct |
324 ms |
12784 KB |
Output is correct |
7 |
Correct |
321 ms |
12872 KB |
Output is correct |
8 |
Correct |
366 ms |
13136 KB |
Output is correct |
9 |
Correct |
197 ms |
4792 KB |
Output is correct |
10 |
Correct |
350 ms |
13128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
224 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
9 ms |
468 KB |
Output is correct |
12 |
Correct |
14 ms |
852 KB |
Output is correct |
13 |
Correct |
14 ms |
864 KB |
Output is correct |
14 |
Correct |
20 ms |
940 KB |
Output is correct |
15 |
Correct |
21 ms |
844 KB |
Output is correct |
16 |
Correct |
16 ms |
928 KB |
Output is correct |
17 |
Correct |
14 ms |
728 KB |
Output is correct |
18 |
Correct |
17 ms |
852 KB |
Output is correct |
19 |
Correct |
925 ms |
23876 KB |
Output is correct |
20 |
Correct |
943 ms |
30516 KB |
Output is correct |
21 |
Correct |
857 ms |
27972 KB |
Output is correct |
22 |
Correct |
895 ms |
27940 KB |
Output is correct |
23 |
Correct |
877 ms |
27944 KB |
Output is correct |
24 |
Correct |
727 ms |
28584 KB |
Output is correct |
25 |
Correct |
730 ms |
28596 KB |
Output is correct |
26 |
Correct |
745 ms |
29600 KB |
Output is correct |
27 |
Correct |
758 ms |
29616 KB |
Output is correct |
28 |
Correct |
739 ms |
30012 KB |
Output is correct |
29 |
Correct |
797 ms |
31164 KB |
Output is correct |
30 |
Correct |
776 ms |
31200 KB |
Output is correct |
31 |
Correct |
782 ms |
31080 KB |
Output is correct |
32 |
Correct |
787 ms |
31204 KB |
Output is correct |
33 |
Correct |
780 ms |
31152 KB |
Output is correct |
34 |
Correct |
715 ms |
28080 KB |
Output is correct |
35 |
Correct |
712 ms |
27980 KB |
Output is correct |
36 |
Correct |
699 ms |
27852 KB |
Output is correct |
37 |
Correct |
704 ms |
27724 KB |
Output is correct |
38 |
Correct |
731 ms |
27932 KB |
Output is correct |
39 |
Correct |
829 ms |
28016 KB |
Output is correct |
40 |
Correct |
630 ms |
20716 KB |
Output is correct |
41 |
Correct |
763 ms |
27632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
224 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
9 ms |
468 KB |
Output is correct |
12 |
Correct |
14 ms |
852 KB |
Output is correct |
13 |
Correct |
14 ms |
864 KB |
Output is correct |
14 |
Correct |
20 ms |
940 KB |
Output is correct |
15 |
Correct |
21 ms |
844 KB |
Output is correct |
16 |
Correct |
16 ms |
928 KB |
Output is correct |
17 |
Correct |
14 ms |
728 KB |
Output is correct |
18 |
Correct |
17 ms |
852 KB |
Output is correct |
19 |
Execution timed out |
3075 ms |
105832 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |