#include<bits/stdc++.h>
//#pragma GCC optimization("g", on)
//#pragma GCC optimize ("inline")
//#pragma GCC optimization("03")
//#pragma GCC optimization("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popused,abm,mmx,avx,tune=native")
using namespace std;
const int N = 1e6 + 5;
const long long inf = 1000000000;
#define ll long long
#define F first
#define S second
#define pb push_back
int n, m, a[N], l[N], r[N], k[N];
int t[4 * N], mx;
bool ans[N];
vector<int> v[N];
void update(int pos, int val, int tl = 0, int tr = n, int v = 1){
if(tl == tr) {
t[v] = max(t[v], val);
}
else{
int tm = (tl + tr) / 2;
if(pos <= tm) update(pos, val, tl, tm, v * 2);
else update(pos, val, tm + 1, tr, v * 2 + 1);
t[v] = max(t[v * 2], t[v * 2 + 1]);
}
}
int get(int v, int tl, int tr, int l, int r){
if(l <= tl && tr <= r) return t[v];
if(l > tr || r < tl) return 0;
int tm = (tl + tr) / 2;
return max(get(v * 2, tl, tm, l, r), get(v * 2 + 1, tm + 1, tr, l, r));
}
main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; ++i){
cin >> a[i];
}
for(int i = 1; i <= m; ++i){
cin >> l[i] >> r[i] >> k[i];
v[r[i]].pb(i);
}
stack<int> st;
st.push(0);
a[0] = inf;
for(int i = 1; i <= n; ++i){
while(a[st.top()] <= a[i]) st.pop();
if(st.top() != 0) update(st.top(), a[st.top()] + a[i]);
st.push(i);
for(auto to : v[i]){
mx = get(1, 1, n, l[to], i);
if(mx <= k[to]) ans[to] = 1;
}
}
for(int i = 1; i <= m; ++i){
cout << ans[i] << '\n';
}
}
Compilation message
sortbooks.cpp:45:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
45 | main() {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23756 KB |
Output is correct |
2 |
Correct |
12 ms |
23836 KB |
Output is correct |
3 |
Incorrect |
15 ms |
23772 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23756 KB |
Output is correct |
2 |
Correct |
12 ms |
23836 KB |
Output is correct |
3 |
Incorrect |
15 ms |
23772 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1400 ms |
67572 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
134 ms |
28204 KB |
Output is correct |
2 |
Correct |
91 ms |
27588 KB |
Output is correct |
3 |
Correct |
108 ms |
26988 KB |
Output is correct |
4 |
Correct |
86 ms |
27160 KB |
Output is correct |
5 |
Correct |
88 ms |
27276 KB |
Output is correct |
6 |
Correct |
79 ms |
26168 KB |
Output is correct |
7 |
Correct |
82 ms |
26188 KB |
Output is correct |
8 |
Correct |
78 ms |
27160 KB |
Output is correct |
9 |
Correct |
45 ms |
25804 KB |
Output is correct |
10 |
Correct |
79 ms |
27244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23756 KB |
Output is correct |
2 |
Correct |
12 ms |
23836 KB |
Output is correct |
3 |
Incorrect |
15 ms |
23772 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23756 KB |
Output is correct |
2 |
Correct |
12 ms |
23836 KB |
Output is correct |
3 |
Incorrect |
15 ms |
23772 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |