Submission #371169

#TimeUsernameProblemLanguageResultExecution timeMemory
371169daniel920712Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
13 / 100
2264 ms62716 KiB
#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)

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:50:19: warning: unused variable 't' [-Wunused-variable]
   50 |     int N,M,x,y,z,t,i,j,big;
      |                   ^
sortbooks.cpp:50:23: warning: unused variable 'j' [-Wunused-variable]
   50 |     int N,M,x,y,z,t,i,j,big;
      |                       ^
sortbooks.cpp:50:25: warning: unused variable 'big' [-Wunused-variable]
   50 |     int N,M,x,y,z,t,i,j,big;
      |                         ^~~
sortbooks.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   51 |     scanf("%d %d",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~
sortbooks.cpp:53:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   53 |     for(i=1;i<=N;i++) scanf("%d",&all[i]);
      |                       ~~~~~^~~~~~~~~~~~~~
sortbooks.cpp:57:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   57 |         scanf("%d %d %d",&x,&y,&z);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...