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;
#pragma GCC optimize("Ofast")
#define pii pair<int, int>
#define pipi pair<pii, pii>
int N = 1<<20;
vector<int> bin(2*N, 0);
vector<vector<int>> bmm(2*N);
int sol = 0;
int query(int curr, int l, int r, int a, int b, int mx)
{
if (l >= b || r <= a) return -1e9;
if (a <= l && r <= b)
{
sol = max(sol, bin[curr]);
auto u = lower_bound(bmm[curr].begin(), bmm[curr].end(), mx);
if (u!= bmm[curr].begin())
{
int last = *(--u);
sol = max(sol, mx+last);
}
return bmm[curr].back();
}
int m = (l+r)/2;
mx = max(mx, query(curr*2, l, m, a, b, mx));
mx = max(mx, query(curr*2+1, m, r, a, b, mx));
return mx;
}
int main()
{
int n, q;
cin >> n >> q;
for (int i = 0; i < n; i++)
{
int a;
cin >> a;
bmm[i+N].push_back(a);
}
for (int i = n; i < N; i++) bmm[i+N].push_back(1e9);
for (int i = N-1; i >0; i--)
{
bmm[i] = vector<int>(bmm[i*2]);
for (int ele:bmm[i*2+1]) bmm[i].push_back(ele);
sort(bmm[i].begin(), bmm[i].end());
bin[i] = max(bin[i*2], bin[i*2+1]);
int mx = bmm[i*2].back();
auto u = lower_bound(bmm[i*2+1].begin(), bmm[i*2+1].end(), mx);
if (u!=bmm[i*2+1].begin())
{
bin[i] = max(bin[i], mx+*(--u));
}
}
while(q--)
{
int l, r, mood;
cin >> l >> r >> mood;
l--;
sol=0;
query(1, 0, N, l, r, -1e9);
if (sol <= mood) cout << "1\n";
else cout << "0\n";
}
return 0;
}
# | 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... |