# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
286270 | SomeoneUnknown | Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) | C++14 | 3073 ms | 115064 KiB |
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;
vector<int> bks;
struct node{
int lo, hi, mid, heaviestswap, mex, meen;
node *lft, *rght;
node(int l, int h){
lo = l;
hi = h;
mid = (l+h)/2;
if(l == h){
heaviestswap = 0;
mex = meen = bks[l];
}else{
lft = new node(l, mid);
rght = new node(mid+1, h);
mex = max(lft->mex, rght->mex);
meen = min(lft->meen, rght->meen);
heaviestswap = max(max(lft->heaviestswap, rght->heaviestswap), mex-meen);
}
}
vector<int> query(int l, int h){
vector<int> res;
if(l <= lo && hi <= h){
res.push_back(meen);
res.push_back(heaviestswap);
res.push_back(mex);
return res;
}
res.push_back(mex);
res.push_back(0);
res.push_back(meen);
int rmin = mex;
if(mid < h){
vector<int> qres = rght->query(l, h);
res[0] = min(res[0], qres[0]);
res[2] = max(res[2], qres[2]);
res[1] = max(res[1], qres[1]);
}
if(l <= mid){
vector<int> qres = lft->query(l, h);
res[1] = max(res[1], qres[2]-res[0]);
res[1] = max(res[1], qres[1]);
res[0] = min(res[0], qres[0]);
res[2] = max(res[2], qres[2]);
}
return res;
}
} *root;
int main(){
int n, q;
scanf("%d %d", &n, &q);
bks.push_back(0);
for(int i = 0; i < n; ++i){
int x;
scanf("%d", &x);
bks.push_back(x);
}
root = new node(1, n);
for(int i = 0; i < q; ++i){
int l, r, w;
scanf("%d %d %d", &l, &r, &w);
if(root->query(l,r)[1] > w){
printf("0\n");
}else{
printf("1\n");
}
}
}
Compilation message (stderr)
# | 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... |