#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn = 2*1e5+5, INF = 4e18+9;
struct SegmentTree{
struct Node{
ll mx = 0;
};
vector<Node> T;
int n, N;
SegmentTree(int n) : n(n){
N = 1;
while(N < n) N*=2;
T.resize(N*2+1);
};
void upd(int i, ll x){
auto upd = [&](auto upd, int node, int low, int high, int i, ll x) -> void{
if(low == high){
T[node].mx = max(T[node].mx, x);
return;
}
int mid = (low+high)/2;
if(i <= mid){
upd(upd, node*2, low, mid, i, x);
}else{
upd(upd, node*2+1, mid+1, high, i, x);
}
T[node].mx = max(T[node*2].mx, T[node*2+1].mx);
};
upd(upd, 1, 1, N, i, x);
}
ll get_max(int l, int r){
auto get_max = [&](auto get_max, int node, int low, int high, int l, int r) -> ll{
if(low > r || l > high) return 0;
if(low >= l && r >= high) return T[node].mx;
int mid = (low+high)/2;
return max(get_max(get_max, node*2, low, mid, l, r), get_max(get_max, node*2+1, mid+1, high, l, r));
};
return get_max(get_max, 1, 1, N, l, r);
}
};
struct que{
int l, r, k, id;
};
void solve(){
int n, Q;
cin >> n >> Q;
vector<int> a(n+1);
for(int i = 1; i <= n; i++){
cin >> a[i];
}
vector<vector<que>> sweep(n+1);
for(int i = 1; i <= Q; i++){
int l, r, k, id;
cin >> l >> r >> k;
id = i;
sweep[r].push_back({l, r, k, id});
}
stack<int> st;
SegmentTree T(n+1);
vector<int> ans(Q+1);
for(int i = 1; i <= n; i++){
while(!st.empty() && a[st.top()] <= a[i]) st.pop();
if(!st.empty()){
T.upd(st.top(), a[st.top()]+a[i]);
}
for(auto it : sweep[i]){
ans[it.id] = T.get_max(it.l, it.r) <= it.k;
}
st.push(i);
}
for(int i = 1; i <= Q; i++){
cout << ans[i] << "\n";
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
452 KB |
Output is correct |
6 |
Correct |
2 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
504 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
452 KB |
Output is correct |
6 |
Correct |
2 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
504 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
576 KB |
Output is correct |
12 |
Correct |
3 ms |
848 KB |
Output is correct |
13 |
Correct |
3 ms |
840 KB |
Output is correct |
14 |
Correct |
4 ms |
848 KB |
Output is correct |
15 |
Correct |
4 ms |
848 KB |
Output is correct |
16 |
Correct |
5 ms |
848 KB |
Output is correct |
17 |
Correct |
4 ms |
848 KB |
Output is correct |
18 |
Correct |
3 ms |
848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1014 ms |
107964 KB |
Output is correct |
2 |
Correct |
1041 ms |
109052 KB |
Output is correct |
3 |
Correct |
1072 ms |
108892 KB |
Output is correct |
4 |
Correct |
1088 ms |
109012 KB |
Output is correct |
5 |
Correct |
899 ms |
109052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
10204 KB |
Output is correct |
2 |
Correct |
64 ms |
10060 KB |
Output is correct |
3 |
Correct |
55 ms |
10312 KB |
Output is correct |
4 |
Correct |
71 ms |
10344 KB |
Output is correct |
5 |
Correct |
60 ms |
10308 KB |
Output is correct |
6 |
Correct |
48 ms |
9800 KB |
Output is correct |
7 |
Correct |
47 ms |
9800 KB |
Output is correct |
8 |
Correct |
51 ms |
9668 KB |
Output is correct |
9 |
Correct |
27 ms |
4176 KB |
Output is correct |
10 |
Correct |
68 ms |
9668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
452 KB |
Output is correct |
6 |
Correct |
2 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
504 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
576 KB |
Output is correct |
12 |
Correct |
3 ms |
848 KB |
Output is correct |
13 |
Correct |
3 ms |
840 KB |
Output is correct |
14 |
Correct |
4 ms |
848 KB |
Output is correct |
15 |
Correct |
4 ms |
848 KB |
Output is correct |
16 |
Correct |
5 ms |
848 KB |
Output is correct |
17 |
Correct |
4 ms |
848 KB |
Output is correct |
18 |
Correct |
3 ms |
848 KB |
Output is correct |
19 |
Correct |
205 ms |
22852 KB |
Output is correct |
20 |
Correct |
161 ms |
22784 KB |
Output is correct |
21 |
Correct |
137 ms |
22344 KB |
Output is correct |
22 |
Correct |
143 ms |
22344 KB |
Output is correct |
23 |
Correct |
142 ms |
22468 KB |
Output is correct |
24 |
Correct |
112 ms |
22344 KB |
Output is correct |
25 |
Correct |
112 ms |
22184 KB |
Output is correct |
26 |
Correct |
131 ms |
22600 KB |
Output is correct |
27 |
Correct |
126 ms |
22600 KB |
Output is correct |
28 |
Correct |
136 ms |
22592 KB |
Output is correct |
29 |
Correct |
136 ms |
22852 KB |
Output is correct |
30 |
Correct |
148 ms |
22864 KB |
Output is correct |
31 |
Correct |
152 ms |
22800 KB |
Output is correct |
32 |
Correct |
168 ms |
22856 KB |
Output is correct |
33 |
Correct |
149 ms |
22856 KB |
Output is correct |
34 |
Correct |
125 ms |
21832 KB |
Output is correct |
35 |
Correct |
116 ms |
21832 KB |
Output is correct |
36 |
Correct |
109 ms |
21576 KB |
Output is correct |
37 |
Correct |
109 ms |
21576 KB |
Output is correct |
38 |
Correct |
139 ms |
21832 KB |
Output is correct |
39 |
Correct |
115 ms |
20868 KB |
Output is correct |
40 |
Correct |
101 ms |
18564 KB |
Output is correct |
41 |
Correct |
114 ms |
21432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
452 KB |
Output is correct |
6 |
Correct |
2 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
504 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
576 KB |
Output is correct |
12 |
Correct |
3 ms |
848 KB |
Output is correct |
13 |
Correct |
3 ms |
840 KB |
Output is correct |
14 |
Correct |
4 ms |
848 KB |
Output is correct |
15 |
Correct |
4 ms |
848 KB |
Output is correct |
16 |
Correct |
5 ms |
848 KB |
Output is correct |
17 |
Correct |
4 ms |
848 KB |
Output is correct |
18 |
Correct |
3 ms |
848 KB |
Output is correct |
19 |
Correct |
1014 ms |
107964 KB |
Output is correct |
20 |
Correct |
1041 ms |
109052 KB |
Output is correct |
21 |
Correct |
1072 ms |
108892 KB |
Output is correct |
22 |
Correct |
1088 ms |
109012 KB |
Output is correct |
23 |
Correct |
899 ms |
109052 KB |
Output is correct |
24 |
Correct |
70 ms |
10204 KB |
Output is correct |
25 |
Correct |
64 ms |
10060 KB |
Output is correct |
26 |
Correct |
55 ms |
10312 KB |
Output is correct |
27 |
Correct |
71 ms |
10344 KB |
Output is correct |
28 |
Correct |
60 ms |
10308 KB |
Output is correct |
29 |
Correct |
48 ms |
9800 KB |
Output is correct |
30 |
Correct |
47 ms |
9800 KB |
Output is correct |
31 |
Correct |
51 ms |
9668 KB |
Output is correct |
32 |
Correct |
27 ms |
4176 KB |
Output is correct |
33 |
Correct |
68 ms |
9668 KB |
Output is correct |
34 |
Correct |
205 ms |
22852 KB |
Output is correct |
35 |
Correct |
161 ms |
22784 KB |
Output is correct |
36 |
Correct |
137 ms |
22344 KB |
Output is correct |
37 |
Correct |
143 ms |
22344 KB |
Output is correct |
38 |
Correct |
142 ms |
22468 KB |
Output is correct |
39 |
Correct |
112 ms |
22344 KB |
Output is correct |
40 |
Correct |
112 ms |
22184 KB |
Output is correct |
41 |
Correct |
131 ms |
22600 KB |
Output is correct |
42 |
Correct |
126 ms |
22600 KB |
Output is correct |
43 |
Correct |
136 ms |
22592 KB |
Output is correct |
44 |
Correct |
136 ms |
22852 KB |
Output is correct |
45 |
Correct |
148 ms |
22864 KB |
Output is correct |
46 |
Correct |
152 ms |
22800 KB |
Output is correct |
47 |
Correct |
168 ms |
22856 KB |
Output is correct |
48 |
Correct |
149 ms |
22856 KB |
Output is correct |
49 |
Correct |
125 ms |
21832 KB |
Output is correct |
50 |
Correct |
116 ms |
21832 KB |
Output is correct |
51 |
Correct |
109 ms |
21576 KB |
Output is correct |
52 |
Correct |
109 ms |
21576 KB |
Output is correct |
53 |
Correct |
139 ms |
21832 KB |
Output is correct |
54 |
Correct |
115 ms |
20868 KB |
Output is correct |
55 |
Correct |
101 ms |
18564 KB |
Output is correct |
56 |
Correct |
114 ms |
21432 KB |
Output is correct |
57 |
Correct |
1000 ms |
109384 KB |
Output is correct |
58 |
Correct |
1044 ms |
109384 KB |
Output is correct |
59 |
Correct |
1036 ms |
108360 KB |
Output is correct |
60 |
Correct |
1053 ms |
108384 KB |
Output is correct |
61 |
Correct |
950 ms |
108284 KB |
Output is correct |
62 |
Correct |
954 ms |
108376 KB |
Output is correct |
63 |
Correct |
611 ms |
104960 KB |
Output is correct |
64 |
Correct |
632 ms |
106056 KB |
Output is correct |
65 |
Correct |
820 ms |
108288 KB |
Output is correct |
66 |
Correct |
866 ms |
108288 KB |
Output is correct |
67 |
Correct |
891 ms |
108232 KB |
Output is correct |
68 |
Correct |
876 ms |
109384 KB |
Output is correct |
69 |
Correct |
860 ms |
109384 KB |
Output is correct |
70 |
Correct |
886 ms |
109008 KB |
Output is correct |
71 |
Correct |
947 ms |
109128 KB |
Output is correct |
72 |
Correct |
937 ms |
109008 KB |
Output is correct |
73 |
Correct |
564 ms |
101132 KB |
Output is correct |
74 |
Correct |
565 ms |
101628 KB |
Output is correct |
75 |
Correct |
565 ms |
100936 KB |
Output is correct |
76 |
Correct |
578 ms |
101096 KB |
Output is correct |
77 |
Correct |
583 ms |
100836 KB |
Output is correct |
78 |
Correct |
811 ms |
100964 KB |
Output is correct |
79 |
Correct |
559 ms |
81324 KB |
Output is correct |
80 |
Correct |
764 ms |
98728 KB |
Output is correct |