#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int N = 1e6 + 5;
int n, m;
int a[N], u[N], v[N], k[N];
vector <int> ask[N];
int ans[N];
int Max[4 * N];
void upd(int s, int l, int r, int u, int v, int val){
if (u <= l && r <= v){
Max[s] = max(Max[s], val);
return;
}
int mid = l + r >> 1;
if (mid >= u) upd(2 * s, l, mid, u, v, val);
if (mid + 1 <= v) upd(2 * s + 1, mid + 1, r, u, v, val);
}
int get(int s, int l, int r, int u){
if (l == r) return Max[s];
int mid = l + r >> 1;
if (mid >= u) return get(2 * s, l, mid, u);
return get(2 * s + 1, mid + 1, r, u);
}
void solve(){
cin >> n >> m;
for (int i = 1; i <= n; ++ i) cin >> a[i];
for (int i = 1; i <= m; ++ i){
cin >> u[i] >> v[i] >> k[i];
ask[v[i]].pb(i);
}
stack <int> st;
for (int i = 1; i <= n; ++ i){
while (!st.empty() && a[st.top()] < a[i]) st.pop();
if (!st.empty()) upd(1, 1, n, 1, st.top(), a[i] + a[st.top()]);
st.push(i);
for (int z : ask[i]) if (get(1, 1, n, u[z]) <= k[z]) ans[z] = 1;
}
for (int i = 1; i <= m; ++ i) cout << ans[i] << '\n';
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
Compilation message
sortbooks.cpp: In function 'void upd(int, int, int, int, int, int)':
sortbooks.cpp:21:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
21 | int mid = l + r >> 1;
| ~~^~~
sortbooks.cpp: In function 'int get(int, int, int, int)':
sortbooks.cpp:28:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
28 | int mid = l + r >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
33116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
33116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
912 ms |
104652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
69 ms |
40164 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
33116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
33116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |