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>
using namespace std;
typedef long long ll;
#define f first
#define s second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (int)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 1e6 + 100;
ll w[N];
vector <pair <ll, ll>> save[N];
vector <vector <ll>> ask[N];
ll seg[N * 4];
void upd(int id, int l, int r, int p, ll x) {
if (l > p || r < p)
return;
if (l == r) {
seg[id] = x;
return;
}
int m = (l + r) / 2;
upd(id * 2, l, m, p, x);
upd(id * 2 + 1, m + 1, r, p, x);
seg[id] = max(seg[id * 2], seg[id * 2 + 1]);
}
ll get(int id, int l, int r, int u, int v) {
if (l > v || r < u)
return 0;
if (l >= u && r <= v)
return seg[id];
int m = (l + r) / 2;
return max(get(id * 2, l, m, u, v), get(id * 2 + 1, m + 1, r, u, v));
}
int ans[N];
ll solve() {
int n, m;
cin >> n >> m;
vector <pair <int, int>> st;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
st.pb({x, i});
w[i] = x;
}
sort(all(st), greater <pair <int, int>> ());
set <int> pos;
int j = 0;
for (int i = 0; i < n; i++) {
int v = st[i].s;
while (st[j].f > st[i].f) {
pos.insert(st[j].s);
j++;
}
auto it = pos.lower_bound(v);
if (it != pos.begin()) {
it = prev(it);
save[*it].pb({v, w[v] + w[*it]});
}
}
for (int i = 1; i <= m; i++) {
int l, r, k;
cin >> l >> r >> k;
ask[l].pb({r, k, i});
}
for (int i = n; i >= 1; i--) {
for (auto x : save[i]) {
upd(1, 1, n, x.f, x.s);
}
for (auto x : ask[i]) {
if (get(1, 1, n, i, x[0]) <= x[1]) {
ans[x[2]] = 1;
}
}
}
for (int i = 1; i <= m; i++)
cout << ans[i] << '\n';
return 0;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
//cin >> t;
while (t--) {
solve();
//cout << solve() << '\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... |