Submission #978427

# Submission time Handle Problem Language Result Execution time Memory
978427 2024-05-09T08:13:26 Z alexdd popa (BOI18_popa) C++17
61 / 100
482 ms 940 KB
#include "popa.h"
#include<bits/stdc++.h>
using namespace std;
int myquery(int a, int b, int c, int d)
{
    return query(min(a,b),max(a,b),min(c,d),max(c,d));
}
vector<int> ord;
void precalc(int limle[1005])
{
    for(int i=0;i<ord.size();i++)
    {
        int st=0,dr=i,ans=i;
        while(st<=dr)
        {
            int mij=(st+dr)/2;
            if(myquery(ord[mij],ord[i],ord[i],ord[i]))
            {
                ans=mij;
                dr=mij-1;
            }
            else
                st=mij+1;
        }
        limle[ord[i]] = ord[ans];
    }
}
int tole[1005],tori[1005];
int limle[1005],limri[1005];
int calc(int le, int ri)
{
    if(le>ri)
        return -1;
    if(le==ri)
    {
        tole[le]=tori[le]=-1;
        return le;
    }
    for(int root=le;root<=ri;root++)
    {
        if(limle[root]<=le && limri[root]>=ri)
        {
            tole[root] = calc(le,root-1);
            tori[root] = calc(root+1,ri);
            return root;
        }
    }
    return -5;
}
int solve(int N, int* Left, int* Right)
{
    ord.clear();
    for(int i=0;i<N;i++)
        ord.push_back(i);
    precalc(limle);
    reverse(ord.begin(),ord.end());
    precalc(limri);
    //for(int i=0;i<N;i++) cout<<i<<"  "<<limle[i]<<" "<<limri[i]<<" lim\n";
    for(int i=0;i<N;i++)
        tole[i]=tori[i]=-1;
    int root = calc(0,N-1);
    for(int i=0;i<N;i++)
    {
        Left[i]=tole[i];
        Right[i]=tori[i];
    }
    return root;
}

Compilation message

popa.cpp: In function 'void precalc(int*)':
popa.cpp:11:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for(int i=0;i<ord.size();i++)
      |                 ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 21 ms 700 KB Output is correct
2 Correct 26 ms 696 KB Output is correct
3 Correct 26 ms 692 KB Output is correct
4 Correct 25 ms 692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 442 ms 852 KB Output is correct
2 Correct 482 ms 688 KB Output is correct
3 Correct 269 ms 940 KB Output is correct
4 Correct 470 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 452 KB too many queries
2 Halted 0 ms 0 KB -