#include<bits/stdc++.h>
/*
#pragma optimize ("g",on)
#pragma GCC optimize ("inline")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("03")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
*/
//01001101 01100001 01101011 01101000 01100001 01100111 01100001 01111001
using namespace std;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ll long long
#define pb push_back
#define sz(a) a.size()
#define nl '\n'
#define popb pop_back()
#define ld double
#define ull unsigned long long
#define ff first
#define ss second
#define fix fixed << setprecision
#define pii pair<int, int>
#define E exit (0)
#define int long long
const int inf = 1e15, N = 1e6 + 1, mod = 998244353;
vector<pii> dir = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
int t[N * 4];
void update(int u, int tl, int tr, int pos, int val) {
if (tl == tr) {
t[u] = max(t[u], val);
return;
}
int mid = (tl + tr) / 2;
if (mid <= pos) {
update(u * 2, tl, mid, pos, val);
}else {
update(u * 2 + 1, mid + 1, tr, pos, val);
}
t[u] = max(t[u * 2], t[u * 2 + 1]);
}
int get(int u, int tl, int tr, int l, int r) {
if (tl >= l && tr <= r) return t[u];
if (tl > r || tr < l) return 0;
int mid = (tl + tr) / 2;
return max(get(u * 2, tl, mid, l, r), get(u * 2 + 1, mid + 1, tr, l, r));
}
main() {
//freopen("triangles.in", "r", stdin);
//freopen("triangles.out", "w", stdout);
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
int n, m;
cin >> n >> m;
int a[n + 1], l[n + 1], ans[m + 1];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
stack<int> st;
st.push(1);
l[1] = 1;
for (int i = 2; i <= n; i++) {
l[i] = i;
while (!st.empty() && a[st.top()] <= a[i]) {
l[i] = l[st.top()];
st.pop();
}
st.push(i);
}
vector<pair<int, pii>> s[n + 1];
for (int i = 1; i <= m; i++) {
int l, r, k;
cin >> l >> r >> k;
s[r].pb({l, {i, k}});
}
for (int i = 1; i <= n; i++) {
if (l[i] > 1) update(1, 1, n, l[i] - 1, a[i] + a[l[i] - 1]);
for (auto e: s[i]) {
ans[e.ss.ff] = (e.ss.ss >= get(1, 1, n, e.ff, n));
}
}
for (int i = 1; i <= m; i++) cout << ans[i] << nl;
}
Compilation message
sortbooks.cpp:58:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
58 | main() {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1122 ms |
82052 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
70 ms |
8388 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |