Submission #145323

# Submission time Handle Problem Language Result Execution time Memory
145323 2019-08-19T15:17:43 Z MKopchev popa (BOI18_popa) C++14
100 / 100
104 ms 508 KB
#include<bits/stdc++.h>
#include<popa.h>
using namespace std;

stack<int> open,idle;

int n_,in_;

int ask(int a,int b,int c,int d)
{
    while(a>b);
    while(c>d);
    in_++;
    return query(a,b,c,d);
}
int solve(int N, int* Left, int* Right)
{
    n_=N;
    in_=0;
    for(int i=0;i<N;i++)Left[i]=-1,Right[i]=-1;

    open=idle;

    Left[0]=-1;
    open.push(0);
    for(int i=1;i<N;i++)
    {
        int prev=-1;
        while(open.size()&&ask(open.top(),i,i,i))
        {
            prev=open.top();
            open.pop();
        }

        if(open.size())Right[open.top()]=i;
        Left[i]=prev;
        open.push(i);
    }

    set<int> seen={};
    for(int i=0;i<N;i++)
    {
        seen.insert(Left[i]);
        seen.insert(Right[i]);
    }

    assert(in_<=4*N);

    for(int i=0;i<N;i++)
        if(seen.count(i)==0)return i;
    assert(0==1);
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 248 KB Output is correct
2 Correct 13 ms 248 KB Output is correct
3 Correct 11 ms 248 KB Output is correct
4 Correct 14 ms 248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 376 KB Output is correct
2 Correct 86 ms 500 KB Output is correct
3 Correct 64 ms 372 KB Output is correct
4 Correct 64 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 508 KB Output is correct
2 Correct 104 ms 424 KB Output is correct
3 Correct 96 ms 372 KB Output is correct
4 Correct 86 ms 500 KB Output is correct