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>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << (x) << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int INF = 1e9 + 7, N = 1e6 + 7, C = 1e9 + 7;
int a[N], ans[N];
V<array<int, 3>> G[N];
int bit[N];
void add(int pos, int val) {
for(; pos < N; pos += pos & -pos)
bit[pos] = max(bit[pos], val);
}
int qry(int pos) {
int res = 0;
for(; pos; pos -= pos & -pos)
res = max(res, bit[pos]);
return res;
}
signed main()
{
IO_OP;
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i++)
cin >> a[i];
for(int i = 0; i < m; i++) {
int l, r, k;
cin >> l >> r >> k;
G[l].PB({r, k, i});
}
a[n + 1] = INF;
deque<int> cut;
cut.PB(n + 1);
for(int i = n; i >= 1; i--) {
while(a[i] > a[cut[0]]) {
add(cut[0], a[cut[0]] + a[i]);
cut.pop_front();
}
cut.push_front(i);
for(auto qq:G[i]) {
int r = qq[0], k = qq[1], qi = qq[2];
int tt = qry(r);
if(tt <= k) ans[qi] = 1;
else ans[qi] = 0;
}
}
for(int i = 0; i < m; i++)
cout << ans[i] << '\n';
}
# | 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... |