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;
#define st first
#define nd second
#define pb push_back
#define int long long int
#define endl '\n'
#define MOD (int)(1e9 + 7)
#define all(x) x.begin(), x.end()
#define mid start+(end-start)/2
#define debug(x) cerr << #x << " = " << x << endl
#define binary(x) cerr << #x << " = " << bitset<8>(x) << endl
#define N (int)(1e6)+5
int n, m, a, b, c;
vector<int> v;
int tree[4*N][3];
//tree[n][0] = o alt diziyi non decresing swaplayarak sortlamak icin gereken min mood
//tree[n][1] = o alt dizinin en buyuk elemani
//tree[n][2] = o alt dizinin en kucuk elemani
void build(int wai, int start, int end){
if(start == end){
tree[wai][1] = v[start-1];
tree[wai][2] = v[start-1];
return;
}
build(wai*2, start, mid), build(wai*2+1, mid+1, end);
tree[wai][0] = max(tree[wai*2][0], tree[wai*2+1][0]);
if(tree[wai*2][1] > tree[wai*2+1][2]) tree[wai][0] = max(tree[wai][0], tree[wai*2][1]);
tree[wai][1] = max(tree[wai*2][1], tree[wai*2+1][1]);
tree[wai][2] = min(tree[wai*2][2], tree[wai*2+1][2]);
}
pair<int, pair<int, int> > query(int wai, int start, int end, int l, int r){
if(start > r || end < l) return {0, {INT_MIN, INT_MAX}};
if(start >= l && end <= r) return {tree[wai][0],{tree[wai][1],tree[wai][2]}};
pair<int, pair<int, int> > sol = query(wai*2, start, mid, l, r);
pair<int, pair<int, int> > sag = query(wai*2+1, mid+1, end, l, r);
pair<int, pair<int, int> > gonnareturn;
if(sol.st != INT_MIN || sag.st != INT_MIN) gonnareturn.st = max(sol.st, sag.st);
else gonnareturn.st = 0;
if(sol.nd.st > sag.nd.nd) gonnareturn.st = max(gonnareturn.st, sol.nd.st);
gonnareturn.nd.st = max(sol.nd.st, sag.nd.st);
gonnareturn.nd.nd = min(sol.nd.nd, sag.nd.nd);
return gonnareturn;
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i = 0; i < n; i++){
cin >> a;
v.pb(a);
}
build(1, 1, n);
for(int i = 0; i < m; i++){
cin >> a >> b >> c;
if(query(1, 1, n, a, b).st <= c) cout << 1 << endl;
cout << 0 << endl;
}
}
# | 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... |