답안 #145595

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
145595 2019-08-20T13:25:54 Z davitmarg Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
3000 ms 261392 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;

void myscan(int &number)
{
    //variable to indicate sign of input number
    bool negative = false;
    register int c;

    number = 0;

    // extract current character from buffer
    c = getchar();
    while(c==10)
		c = getchar();
    if (c=='-')
    {
        // number is negative
        negative = true;

        // extract the next character from the buffer
        c = getchar();
    }

    // Keep on extracting characters if they are integers
    // i.e ASCII Value lies from '0'(48) to '9' (57)
    for (; (c>47 && c<58); c=getchar())
        number = number *10 + c - 48;

    // if scanned input has a negative sign, negate the
    // value of the input number
    if (negative)
        number *= -1;
}





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

int mergeSerge(vector<int>& a,vector<int>& b,vector<int> &c)
{
    int p=0,q=0,d=0;
    for(int i=0;i<b.size();i++)
        if(b[i]<a.back())
            d=a.back()+b[i];
    while(p<a.size())
    {
        while(q<b.size() && b[q]<a[p])
            c.PB(b[q++]);
        c.PB(a[p++]);
    }
    while(q<b.size())
        c.PB(b[q++]);

    return d;
}

void build(int v,int l,int r)
{
    if(l==r)
    {
        t[v]=a[l];
        g[v].PB(a[l]);
        return;
    }
    int 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]);
}

int get(int v,int l,int r,int i,int j,int 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];
    }
    int m=(l+r)>>1;
    
    int 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(int i=1;i<=n;i++)
        myscan(a[i]);
    build(1,1,n);

    while(m--)
    {
        int l,r,k;  
        ans=0;
       // scanf("%d%d%d",&l,&r,&k);
        myscan(l);
        myscan(r);
        myscan(k);
        get(1,1,n,l,r,-1);
        //cout<<ans<<endl;
    
        if(ans>=k)
            putchar((int)'0');
        else
            putchar((int)'1');
        putchar(10);
    }

	return 0;
}



/*

3 2 
5 4 4 
1 3 9 
1 3 8 


*/

Compilation message

sortbooks.cpp: In function 'void myscan(int&)':
sortbooks.cpp:30:18: warning: ISO C++1z does not allow 'register' storage class specifier [-Wregister]
     register int c;
                  ^
sortbooks.cpp: In function 'int mergeSerge(std::vector<int>&, std::vector<int>&, std::vector<int>&)':
sortbooks.cpp:70:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<b.size();i++)
                 ~^~~~~~~~~
sortbooks.cpp:73:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(p<a.size())
           ~^~~~~~~~~
sortbooks.cpp:75:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(q<b.size() && b[q]<a[p])
               ~^~~~~~~~~
sortbooks.cpp:79:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(q<b.size())
           ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 89 ms 94328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 89 ms 94328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3111 ms 261392 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 384 ms 111792 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 89 ms 94328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 89 ms 94328 KB Output isn't correct
2 Halted 0 ms 0 KB -