Submission #145378

# Submission time Handle Problem Language Result Execution time Memory
145378 2019-08-19T18:24:22 Z davitmarg Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
674 ms 262148 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;

LL n,m,a[1000006];
LL ans;
vector<LL> g[4*1000006];
LL t[4*1000006],mx[4*1000006];

LL mergeSerge(vector<LL>& a,vector<LL>& b,vector<LL> &c)
{
    LL p=0,q=0,d=0;
    while(p<a.size())
    {
        while(q<b.size() && b[q]<a[p])
        {
            d=max(d,a[p]+b[q]);
            c.PB(b[q++]);
        }
        c.PB(a[p++]);
    }
    while(q<b.size())
        c.PB(b[q++]);
    return d;
}

void build(LL v,LL l,LL r)
{
    if(l==r)
    {
        t[v]=a[l];
        g[v].PB(a[l]);
        return;
    }
    LL m=(l+r)/2;
    build(v*2,l,m);
    build(v*2+1,m+1,r);
    mx[v]=mergeSerge(g[v*2],g[v*2+1],g[v]);
    mx[v]=max(mx[v],max(mx[v*2],mx[v*2+1]));
    t[v]=max(t[v*2],t[v*2+1]);
}

LL get(LL v,LL l,LL r,LL i,LL j,LL lmax)
{
    if(i>j)
        return -1;
    if(l==i && r==j)
    {
        //cout<<"["<<l<<":"<<r<<"]"<<" "<<lmax<<endl;
        if(g[v][0]<lmax)
            ans=max(ans,lmax+(*(lower_bound(all(g[v]),lmax)-1)));
        ans=max(ans,mx[v]);
        return t[v];
    }
    LL m=(l+r)>>1;

    LL p1,p2;

    p1=get(v*2,l,m,i,min(j,m),lmax);
    lmax=max(lmax,p1);

    p2=get(v*2+1,m+1,r,max(m+1,i),j,lmax);
    lmax=max(lmax,p2);

    return lmax;
}

int main()
{
    cin>>n>>m;
    for(LL i=1;i<=n;i++)
        scanf("%lld",a+i);
    build(1,1,n);

    while(m--)
    {
        LL l,r,k;
        ans=0;
        scanf("%lld%lld%lld",&l,&r,&k);
        get(1,1,n,l,r,-1);
        //cout<<ans<<endl;
        printf("%lld\n",(k>=ans));
    }

	return 0;
}
 
/*

3 1
5 4 4
1 3 9

*/

Compilation message

sortbooks.cpp: In function 'long long int mergeSerge(std::vector<long long int>&, std::vector<long long int>&, std::vector<long long int>&)':
sortbooks.cpp:34:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(p<a.size())
           ~^~~~~~~~~
sortbooks.cpp:36:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(q<b.size() && b[q]<a[p])
               ~^~~~~~~~~
sortbooks.cpp:43:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(q<b.size())
           ~^~~~~~~~~
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:103:33: warning: format '%lld' expects argument of type 'long long int', but argument 2 has type 'int' [-Wformat=]
         printf("%lld\n",(k>=ans));
                         ~~~~~~~~^
sortbooks.cpp:93:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld",a+i);
         ~~~~~^~~~~~~~~~~~
sortbooks.cpp:100:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld%lld",&l,&r,&k);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 87 ms 94200 KB Output is correct
2 Correct 99 ms 94452 KB Output is correct
3 Correct 88 ms 94456 KB Output is correct
4 Correct 87 ms 94328 KB Output is correct
5 Correct 87 ms 94352 KB Output is correct
6 Correct 88 ms 94328 KB Output is correct
7 Correct 88 ms 94428 KB Output is correct
8 Correct 89 ms 94488 KB Output is correct
9 Incorrect 87 ms 94328 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 87 ms 94200 KB Output is correct
2 Correct 99 ms 94452 KB Output is correct
3 Correct 88 ms 94456 KB Output is correct
4 Correct 87 ms 94328 KB Output is correct
5 Correct 87 ms 94352 KB Output is correct
6 Correct 88 ms 94328 KB Output is correct
7 Correct 88 ms 94428 KB Output is correct
8 Correct 89 ms 94488 KB Output is correct
9 Incorrect 87 ms 94328 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 674 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 384 ms 120024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 87 ms 94200 KB Output is correct
2 Correct 99 ms 94452 KB Output is correct
3 Correct 88 ms 94456 KB Output is correct
4 Correct 87 ms 94328 KB Output is correct
5 Correct 87 ms 94352 KB Output is correct
6 Correct 88 ms 94328 KB Output is correct
7 Correct 88 ms 94428 KB Output is correct
8 Correct 89 ms 94488 KB Output is correct
9 Incorrect 87 ms 94328 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 87 ms 94200 KB Output is correct
2 Correct 99 ms 94452 KB Output is correct
3 Correct 88 ms 94456 KB Output is correct
4 Correct 87 ms 94328 KB Output is correct
5 Correct 87 ms 94352 KB Output is correct
6 Correct 88 ms 94328 KB Output is correct
7 Correct 88 ms 94428 KB Output is correct
8 Correct 89 ms 94488 KB Output is correct
9 Incorrect 87 ms 94328 KB Output isn't correct
10 Halted 0 ms 0 KB -