Submission #27092

#TimeUsernameProblemLanguageResultExecution timeMemory
27092tlwpdusEditor (BOI15_edi)C++98
100 / 100
896 ms399308 KiB
#include <bits/stdc++.h>

using namespace std;

int n;

struct node {
    node *l, *r;
    int val;
    node() {val = 0; l = r = NULL;}
    node(int v):val(v){l = r = NULL;}
    void init(int s = 0, int e = n) {
        if (s==e) return;
        int m = (s+e)>>1;
        if (!l) l = new node();
        if (!r) r = new node();
        l->init(s,m); r->init(m+1,e);
        val = max(l->val,r->val);
    }
    int getv(int S, int E, int s = 0, int e = n) {
        if (e<S||E<s) return 0;
        if (S<=s&&e<=E) return val;
        int m = (s+e)>>1;
        return max(l->getv(S,E,s,m),r->getv(S,E,m+1,e));
    }
    node* upd(int idx, int val, node *ori, int s = 0, int e = n) {
        if (e<idx||idx<s) return ori;
        if (s==e) return new node(val);
        int m = (s+e)>>1;
        if (!l) l = new node();
        l = l->upd(idx,val,ori->l,s,m);
        if (!r) r = new node();
        r = r->upd(idx,val,ori->r,m+1,e);
        this->val = max(l->val,r->val);
        return this;
    }
} *head[300100];

int arr[300100];
int main() {
    int i;

    scanf("%d",&n);
    head[0] = new node();
    head[0]->init();
    for (i=1;i<=n;i++) {
        head[i] = new node();
        scanf("%d",&arr[i]);
        if (arr[i]>0) {
            head[i] = head[i]->upd(0,i,head[0]);
        }
        else {
            arr[i] *= -1;
            head[i] = head[i]->upd(arr[i],i,head[head[i-1]->getv(0,arr[i]-1)-1]);
        }
        printf("%d\n",arr[head[i]->getv(0,0)]);
    }

    return 0;
}

Compilation message (stderr)

edi.cpp: In function 'int main()':
edi.cpp:43:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
edi.cpp:48:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&arr[i]);
                            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...