# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
371169 | daniel920712 | Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) | C++14 | 2264 ms | 62716 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 <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <utility>
using namespace std;
struct A
{
int l,r;
int nxl,nxr;
pair < pair < int , int > , int > ans;
}Node[2000005];
int all[2000005];
int now=1;
pair < pair < int , int > , int > operator +(pair < pair < int , int > , int > a,pair < pair < int , int > , int > b)
{
pair < pair < int , int > , int > ans;
ans.first.first=max(a.first.first,b.first.first);
ans.first.second=min(a.first.second,b.first.second);
ans.second=max(a.second,b.second);
if(a.first.first>b.first.second) ans.second=max(ans.second,a.first.first+b.first.second);
return ans;
}
void build(int l,int r,int here)
{
Node[here].l=l;
Node[here].r=r;
if(l==r)
{
Node[here].ans=make_pair(make_pair(all[l],all[l]),0);
return;
}
Node[here].nxl=now++;
Node[here].nxr=now++;
build(l,(l+r)/2,Node[here].nxl);
build((l+r)/2+1,r,Node[here].nxr);
Node[here].ans=Node[Node[here].nxl].ans+Node[Node[here].nxr].ans;
//printf("%d %d %d %d %d\n",l,r,Node[here].ans.first.first,Node[here].ans.first.second,Node[here].ans.second);
}
pair < pair < int , int > , int > Find(int l,int r,int here)
{
if(Node[here].l==l&&Node[here].r==r) return Node[here].ans;
if(r<=(Node[here].l+Node[here].r)/2) return Find(l,r,Node[here].nxl);
else if(l>(Node[here].l+Node[here].r)/2) return Find(l,r,Node[here].nxr);
else return Find(l,(Node[here].l+Node[here].r)/2,Node[here].nxl)+Find((Node[here].l+Node[here].r)/2+1,r,Node[here].nxr);
}
int main()
{
int N,M,x,y,z,t,i,j,big;
scanf("%d %d",&N,&M);
for(i=1;i<=N;i++) scanf("%d",&all[i]);
build(1,N,0);
while(M--)
{
scanf("%d %d %d",&x,&y,&z);
//printf("%d\n",Find(x,y,0).second);
if(Find(x,y,0).second<=z) printf("1\n");
else printf("0\n");
}
return 0;
}
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... |