답안 #145341

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
145341 2019-08-19T16:13:09 Z davitmarg Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
1757 ms 58240 KB
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <stack>
#include <cassert>
#include <iterator>
#include <bitset>
#include <fstream>
#define mod 998244353ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
using namespace std;
 
int n,m,a[1000006];
LL ans,mx[4*1000006];
pair<LL,LL> t[4*1000006];
 
pair<LL,LL> merge(pair<LL,LL> a,pair<LL,LL> b)
{
    a.first=max(a.first,b.first);
    a.second=min(a.second,b.second);
    return a;
}
 
void build(int v,int l,int r)
{
    int MX=0;
    for(int i=l;i<=r;i++)
    {
        mx[v]=max(mx[v],MX-(LL)a[i]);
        MX=max(MX,a[i]);
    }
    if(l==r)
    {
        t[v]=MP(a[l],a[l]);
        mx[v]=0;
        return;
    }
    int m=(l+r)/2;
    build(v*2,l,m);
    build(v*2+1,m+1,r);
    t[v]=merge(t[v*2],t[v*2+1]);
}
 
pair<LL,LL> get(int v,int l,int r,int i,int j)
{
    if(i>j)
        return MP(0,0);
    if(l==i && r==j)
    {
        ans=max(ans,mx[v]);
        if(mx[v])
            ans=1;
        return t[v];
    }
    int m=(l+r)>>1;
    pair<LL,LL> p1,p2;
    p1=get(v*2,l,m,i,min(j,m));
    p2=get(v*2+1,m+1,r,max(m+1,i),j);
 
    if(j<=m)
        return p1;
    else if(i>=m+1)
        return p2;
    else
    {
        //cout<<p1.first<<" : "<<p2.second<<endl;
        //ans=max(p1.first-p2.second,ans);
        if(p1.first>p2.second)
            ans=1;
        return merge(p1,p2);
    }
}
 
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        scanf("%d",a+i);
    build(1,1,n);
    while(m--)
    {
        int l,r;
        LL k;
        ans=0;
        scanf("%d%d%lld",&l,&r,&k);
        get(1,1,n,l,r);
        k-=ans;
        //cout<<ans<<endl;
        printf("%d\n",(k>=0));
    }
	return 0;
}
 
/*
 
5 1
9 8 8 8 8 
1 5 1
 
 
*/

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:91:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",a+i);
         ~~~~~^~~~~~~~~~
sortbooks.cpp:98:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%lld",&l,&r,&k);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1757 ms 58240 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 130 ms 9208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -