제출 #286871

#제출 시각아이디문제언어결과실행 시간메모리
286871tqbfjotldHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
64 / 100
929 ms262144 KiB
#include <bits/stdc++.h>
using namespace std;

struct node{
    int s,e;
    vector<pair<int,int> > v;
    vector<int> prefm;
    node *l,*r;
    node (int _s, int _e){
        s = _s;
        e = _e;
        if (s!=e){
            l = new node(s,(s+e)/2);
            r = new node((s+e)/2+1,e);
        }
    }
    void upd(int p, pair<int,int> val){
        v.push_back(val);
        if (s==e) return;
        if (p<=(s+e)/2) l->upd(p,val);
        else r->upd(p,val);
    }
    void procAll(){
        sort(v.begin(),v.end());
        int t = -1;
        for (auto&x:v){
            t = max(t,x.second);
            prefm.push_back(t);
        }
        if (s==e) return;
        l->procAll();
        r->procAll();
    }
    int qu(int a, int b, int maxp){
        if (a<=s && e<=b){
            int pos = lower_bound(v.begin(),v.end(),make_pair(maxp+1,-1))-v.begin();
            if (pos==0) return -1;
            assert(pos-1<prefm.size());
            return prefm[pos-1];
        }
        if (b<=(s+e)/2) return l->qu(a,b,maxp);
        if (a>(s+e)/2) return r->qu(a,b,maxp);
        return max(l->qu(a,b,maxp),r->qu(a,b,maxp));
    }
}*root;

stack<int> thing;
int val[1000005];

void input(int &a){
    a = 0;
   char ch = ' ';
    while (ch<'0' || ch>'9'){
        ch = getchar();
    }
    while (ch>='0' && ch<='9'){
        a = (a<<3) + (a<<1) + ch - '0';
        ch = getchar();
    }
}

int main(){
    int n,m;
    input(n);
    input(m);
    for (int x = 0; x<n; x++){
        input(val[x]);
    }
    root = new node(0,n);
    for (int x = 0; x<n; x++){
        while ((!thing.empty()) && val[thing.top()]<=val[x]){
            thing.pop();
        }
        if (!thing.empty()){
            root->upd(thing.top(),{x,val[thing.top()]+val[x]});
        }
        thing.push(x);
    }
    root->procAll();
    for (int x = 0; x<m; x++){
        int a,b,c;
        input(a); input(b); input(c);
        a--;b--;
        int v = root->qu(a,b,b);
        //printf("found %d\n",v);
        if (v<=c) printf("1\n");
        else printf("0\n");
    }
}

컴파일 시 표준 에러 (stderr) 메시지

In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from sortbooks.cpp:1:
sortbooks.cpp: In member function 'int node::qu(int, int, int)':
sortbooks.cpp:38:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |             assert(pos-1<prefm.size());
      |                    ~~~~~^~~~~~~~~~~~~
#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...