답안 #466861

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
466861 2021-08-20T21:23:43 Z TlenekWodoru Exam (eJOI20_exam) C++14
27 / 100
97 ms 788 KB
#include <bits/stdc++.h>
using namespace std;
int A[100009];
int B[100009];
pair<int,int>granica[100009];
int dp[2][100009];
int DOR[100009];
map<int,int>miejsce;
int Tre[1000000];
int t,t2;
void Przedzial(int l, int p, int dod)
{
    l+=t2;
    p+=t2;
    int v=1;
    int P=t2+1;
    while(true)
    {
        if(v*P+P-1<l)
        {
            v=v/2;
            P=P*2;
            if(v==0){break;}
        }
        else if(v*P==l&&v*P+P-1<=p)
        {
            Tre[v]=max(Tre[v],dod);
            l+=P;
        }
        else
        {
            if(l<v*P+(P/2))
            {
                v=v*2;
                P=P/2;
            }
            else
            {
                v=v*2+1;
                P=P/2;
            }
        }
    }
}
int punkt(int v)
{
    int maxx=0;
    v+=t2;
    while(v!=0)
    {
        maxx=max(maxx,Tre[v]);
        v=v/2;
    }
    return maxx;
}
int TworzenieDrzewa(int x)
{
    int u=x;
    int coss=0;
    while(u>0)
    {
        coss++;
        u=u/2;
    }
    if(pow(2,coss-1)==x){coss--;}
    coss++;
    return coss;
}
int main()
{ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>A[i];
    }
    for(int i=1;i<=n;i++)
    {
        cin>>B[i];
    }
    map<int,int>M;
    M[2000000000]=0;
    for(int i=1;i<=n;i++)
    {
        granica[i].first=M.upper_bound(A[i])->second+1;
        M[A[i]]=i;
    }
    M.clear();
    M[2000000000]=n+1;
    for(int i=n;i>=1;i--)
    {
        granica[i].second=M.upper_bound(A[i])->second-1;
        M[A[i]]=i;
    }
    M.clear();
///-=-==-=-==-=-==-=-==-=-==-=-=-==-=--=-==-=-=-
    bool cv=1;
    for(int i=2;i<=n;i++)
    {
        if(B[i-1]!=B[i])
        {
            cv=0;
            break;
        }
    }
    if(n<=5000)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(A[i]==B[j]&&granica[i].first<=j&&j<=granica[i].second)
                {
                    dp[i%2][j]=dp[i%2][j-1]+1;
                }
                else
                {
                    dp[i%2][j]=max(dp[i%2][j-1],dp[(i-1)%2][j]);
                }
            }
        }
        cout<<dp[n%2][n]<<endl;
    }
    else if(cv==1)
    {
        for(int i=1;i<=n;i++)
        {
            if(A[i]==B[1])
            {
                DOR[granica[i].first]++;
                DOR[granica[i].second+1]--;
            }
        }
        int wynik=0;
        for(int i=1;i<=n;i++)
        {
            DOR[i]+=DOR[i-1];
            if(DOR[i]>0)
            {
                wynik++;
            }
        }
        cout<<wynik<<endl;
    }
    else
    {
        for(int i=1;i<=n;i++)
        {
            miejsce[A[i]]=i;
        }
        t=TworzenieDrzewa(n);
        t2=pow(2,t-1)-1;
        for(int i=1;i<=n;i++)
        {
            int ind=miejsce[B[i]];
            if(ind!=0&&granica[ind].first<=i&&i<=granica[ind].second)
            {
                int dod=punkt(ind)+1;
                Przedzial(ind,n,dod);
            }
        }
        cout<<punkt(n)<<endl;
    }
    return 0;
}





# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 17 ms 460 KB Output is correct
4 Correct 89 ms 724 KB Output is correct
5 Correct 96 ms 716 KB Output is correct
6 Correct 97 ms 788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Incorrect 1 ms 332 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 17 ms 460 KB Output is correct
10 Correct 89 ms 724 KB Output is correct
11 Correct 96 ms 716 KB Output is correct
12 Correct 97 ms 788 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Incorrect 1 ms 332 KB Output isn't correct
16 Halted 0 ms 0 KB -