This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define F first
#define S second
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forbn(i, b, n) for(int i = b; i < n; ++i)
#define sz(v) (int)v.size()
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
typedef complex<double> cd; // !!! long double slow
template <class T> inline void mineq(T &a, T b) { a = min(a, b); }
template <class T> inline void maxeq(T &a, T b) { a = max(a, b); }
int n, Q;
const int INF = 1000 * 1000 * 1000 + 10;
const int MX = 1000 * 1000;
int ls[MX], ks[MX];
struct Seg {
int n;
vi mx;
Seg(int n): n(n) {
mx.assign(2 * n, -1);
}
void upd(int p, int v) {
for(maxeq(mx[p += n], v); p > 1; p >>= 1)
mx[p >> 1] = max(mx[p], mx[p ^ 1]);
}
int query(int l, int r) {
int res = -1;
for(l += n, r += n + 1; l < r; l >>= 1, r >>= 1) {
if(l & 1) maxeq(res, mx[l++]);
if(r & 1) maxeq(res, mx[--r]);
}
return res;
}
};
void solve() {
cin >> n >> Q;
vi a(n + 1, INF);
forbn(i, 1, n + 1)
cin >> a[i];
vi qs[n + 1];
forn(q, Q) {
int r;
cin >> ls[q] >> r >> ks[q];
qs[r].eb(q);
}
Seg seg(n + 1);
vi st(1), ans(Q);
forbn(i, 1, n + 1) {
while(a[st.back()] <= a[i])
st.pop_back();
seg.upd(st.back(), a[st.back()] + a[i]);
st.push_back(i);
for(int q: qs[i]) {
ans[q] = seg.query(ls[q], n) <= ks[q];
}
}
for(int el: ans)
cout << el << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
// freopen("boards.in", "r", stdin);
// freopen("boards.out", "w", stdout);
int t = 1;
// cin >> t;
while(t--) {
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |