#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 10;
#define ff first
#define ss second
ll fen[N];
ll arr[N];
void upd(int at, ll val) {
while(at > 0) {
fen[at] = max(fen[at], val);
at-=at&(-at);
}
}
ll get(int r) {
ll mx = 0;
while(r < N) {
mx = max(mx, fen[r]);
r+=r&(-r);
}
return mx;
}
int main () {
int n, m;
cin >> n >> m;
for(int i = 0;i<N;i++)fen[i] = 0;
for(int i = 1;i<=n;i++)cin >> arr[i];
vector<pair<pair<ll,ll>, ll>> que[n+1];
for(int i = 0;i<m;i++) {
ll l, r, v;
cin >> l >> r >> v;
que[r].push_back(make_pair(make_pair(l, v), i));
}
ll ans[m];
vector<int> stk;
stk.push_back(0);
for(int i = 1;i<=n;i++) {
while(stk.size() and arr[stk.back()] <= arr[i])stk.pop_back();
if(stk.size())upd(stk.back(), arr[stk.back()]+arr[i]);
stk.push_back(i);
for(auto q:que[i]) {
ans[q.ss] = get(q.ff.ff)<=q.ff.ss;
}
}
for(int i = 0;i<m;i++)cout << ans[i] << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
2 ms |
1748 KB |
Output is correct |
3 |
Correct |
2 ms |
1876 KB |
Output is correct |
4 |
Correct |
2 ms |
1876 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
2 ms |
1876 KB |
Output is correct |
7 |
Correct |
2 ms |
1876 KB |
Output is correct |
8 |
Correct |
2 ms |
1852 KB |
Output is correct |
9 |
Correct |
2 ms |
1876 KB |
Output is correct |
10 |
Correct |
2 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
2 ms |
1748 KB |
Output is correct |
3 |
Correct |
2 ms |
1876 KB |
Output is correct |
4 |
Correct |
2 ms |
1876 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
2 ms |
1876 KB |
Output is correct |
7 |
Correct |
2 ms |
1876 KB |
Output is correct |
8 |
Correct |
2 ms |
1852 KB |
Output is correct |
9 |
Correct |
2 ms |
1876 KB |
Output is correct |
10 |
Correct |
2 ms |
1876 KB |
Output is correct |
11 |
Correct |
4 ms |
2004 KB |
Output is correct |
12 |
Correct |
6 ms |
2108 KB |
Output is correct |
13 |
Correct |
6 ms |
2252 KB |
Output is correct |
14 |
Correct |
8 ms |
2388 KB |
Output is correct |
15 |
Correct |
9 ms |
2372 KB |
Output is correct |
16 |
Correct |
7 ms |
2240 KB |
Output is correct |
17 |
Correct |
6 ms |
2300 KB |
Output is correct |
18 |
Correct |
7 ms |
2260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
159 ms |
6748 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
123 ms |
9124 KB |
Output is correct |
2 |
Correct |
115 ms |
11320 KB |
Output is correct |
3 |
Correct |
119 ms |
11156 KB |
Output is correct |
4 |
Correct |
117 ms |
11244 KB |
Output is correct |
5 |
Correct |
133 ms |
11208 KB |
Output is correct |
6 |
Correct |
109 ms |
11056 KB |
Output is correct |
7 |
Correct |
105 ms |
11084 KB |
Output is correct |
8 |
Correct |
100 ms |
10456 KB |
Output is correct |
9 |
Correct |
75 ms |
6992 KB |
Output is correct |
10 |
Correct |
111 ms |
10452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
2 ms |
1748 KB |
Output is correct |
3 |
Correct |
2 ms |
1876 KB |
Output is correct |
4 |
Correct |
2 ms |
1876 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
2 ms |
1876 KB |
Output is correct |
7 |
Correct |
2 ms |
1876 KB |
Output is correct |
8 |
Correct |
2 ms |
1852 KB |
Output is correct |
9 |
Correct |
2 ms |
1876 KB |
Output is correct |
10 |
Correct |
2 ms |
1876 KB |
Output is correct |
11 |
Correct |
4 ms |
2004 KB |
Output is correct |
12 |
Correct |
6 ms |
2108 KB |
Output is correct |
13 |
Correct |
6 ms |
2252 KB |
Output is correct |
14 |
Correct |
8 ms |
2388 KB |
Output is correct |
15 |
Correct |
9 ms |
2372 KB |
Output is correct |
16 |
Correct |
7 ms |
2240 KB |
Output is correct |
17 |
Correct |
6 ms |
2300 KB |
Output is correct |
18 |
Correct |
7 ms |
2260 KB |
Output is correct |
19 |
Correct |
376 ms |
23216 KB |
Output is correct |
20 |
Correct |
318 ms |
23176 KB |
Output is correct |
21 |
Correct |
293 ms |
23648 KB |
Output is correct |
22 |
Correct |
296 ms |
23568 KB |
Output is correct |
23 |
Correct |
290 ms |
23592 KB |
Output is correct |
24 |
Correct |
277 ms |
23680 KB |
Output is correct |
25 |
Correct |
277 ms |
23632 KB |
Output is correct |
26 |
Correct |
315 ms |
23328 KB |
Output is correct |
27 |
Correct |
307 ms |
23384 KB |
Output is correct |
28 |
Correct |
301 ms |
23332 KB |
Output is correct |
29 |
Correct |
306 ms |
23100 KB |
Output is correct |
30 |
Correct |
307 ms |
23308 KB |
Output is correct |
31 |
Correct |
317 ms |
23204 KB |
Output is correct |
32 |
Correct |
304 ms |
23200 KB |
Output is correct |
33 |
Correct |
312 ms |
23204 KB |
Output is correct |
34 |
Correct |
275 ms |
22860 KB |
Output is correct |
35 |
Correct |
279 ms |
22796 KB |
Output is correct |
36 |
Correct |
269 ms |
22764 KB |
Output is correct |
37 |
Correct |
261 ms |
22856 KB |
Output is correct |
38 |
Correct |
318 ms |
22904 KB |
Output is correct |
39 |
Correct |
267 ms |
21184 KB |
Output is correct |
40 |
Correct |
231 ms |
17908 KB |
Output is correct |
41 |
Correct |
242 ms |
20560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
2 ms |
1748 KB |
Output is correct |
3 |
Correct |
2 ms |
1876 KB |
Output is correct |
4 |
Correct |
2 ms |
1876 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
2 ms |
1876 KB |
Output is correct |
7 |
Correct |
2 ms |
1876 KB |
Output is correct |
8 |
Correct |
2 ms |
1852 KB |
Output is correct |
9 |
Correct |
2 ms |
1876 KB |
Output is correct |
10 |
Correct |
2 ms |
1876 KB |
Output is correct |
11 |
Correct |
4 ms |
2004 KB |
Output is correct |
12 |
Correct |
6 ms |
2108 KB |
Output is correct |
13 |
Correct |
6 ms |
2252 KB |
Output is correct |
14 |
Correct |
8 ms |
2388 KB |
Output is correct |
15 |
Correct |
9 ms |
2372 KB |
Output is correct |
16 |
Correct |
7 ms |
2240 KB |
Output is correct |
17 |
Correct |
6 ms |
2300 KB |
Output is correct |
18 |
Correct |
7 ms |
2260 KB |
Output is correct |
19 |
Runtime error |
159 ms |
6748 KB |
Execution killed with signal 11 |
20 |
Halted |
0 ms |
0 KB |
- |