Submission #460836

# Submission time Handle Problem Language Result Execution time Memory
460836 2021-08-09T10:21:14 Z Tenis0206 Exam (eJOI20_exam) C++11
48 / 100
148 ms 9640 KB
#include <bits/stdc++.h>

using namespace std;
int n;
int a[100005],b[100005],aux[100005],l[100005],r[100005],fr[100005];
int dp[100005];
class arbore_indexat_binar
{
    int aib[100005];
private:
    int ub(int x)
    {
        return (x&(-x));
    }
public:
    void update(int poz, int val)
    {
        for(int i=poz;i<=n;i+=ub(i))
        {
            aib[i] = max(aib[i],val);
        }
    }
    int query(int poz)
    {
        int rez = 0;
        for(int i=poz;i>=1;i-=ub(i))
        {
            rez = max(rez,aib[i]);
        }
        return rez;
    }
} aib;
bool subtask2()
{
    for(int i=2; i<=n; i++)
    {
        if(b[i]!=b[i-1])
        {
            return false;
        }
    }
    return true;
}
bool subtask4()
{
    for(int i=1; i<=n; i++)
    {
        aux[i] = a[i];
    }
    sort(aux+1,aux+n+1);
    for(int i=2; i<=n; i++)
    {
        if(aux[i]==aux[i-1])
        {
            return false;
        }
    }
    return true;
}
void precalc_stack()
{
    stack<int> st;
    for(int i=1; i<=n; i++)
    {
        while(!st.empty() && a[i]>a[st.top()])
        {
            st.pop();
        }
        if(st.empty())
        {
            l[i] = 0;
        }
        else
        {
            l[i] = st.top();
        }
        st.push(i);
    }
    while(!st.empty())
    {
        st.pop();
    }
    for(int i=n; i>=1; i--)
    {
        while(!st.empty() && a[i]>a[st.top()])
        {
            st.pop();
        }
        if(st.empty())
        {
            r[i] = n+1;
        }
        else
        {
            r[i] = st.top();
        }
        st.push(i);
    }
}
int solve_subtask2()
{
    for(int i=1; i<=n; i++)
    {
        if(a[i]==b[1])
        {
            ++fr[l[i]+1];
            --fr[r[i]];
        }
    }
    int rez = 0;
    for(int i=1; i<=n; i++)
    {
        fr[i]+=fr[i-1];
        if(fr[i])
        {
            ++rez;
        }
    }
    return rez;
}
int solve_subtask4()
{
    map<int,int> poz;
    for(int i=1;i<=n;i++)
    {
        poz[a[i]] = i;
    }
    int Max = 0;
    for(int i=1;i<=n;i++)
    {
        if(poz[b[i]]>i && l[poz[b[i]]]>=i)
        {
            continue;
        }
        if(poz[b[i]]<i && r[poz[b[i]]]<=i)
        {
            continue;
        }
        dp[i] = 1 + aib.query(poz[b[i]]);
        aib.update(poz[b[i]],dp[i]);
        Max = max(Max,dp[i]);
    }
    return Max;
}
int solve_general()
{
    return 0;
}
int main()
{
   // freopen("nr.in","r",stdin);
   // freopen("nr.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
    }
    for(int i=1; i<=n; i++)
    {
        cin>>b[i];
    }
    precalc_stack();
    if(subtask2())
    {
        cout<<solve_subtask2()<<'\n';
        return 0;
    }
    if(subtask4())
    {
        cout<<solve_subtask4()<<'\n';
        return 0;
    }
    cout<<solve_general()<<'\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 0 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 6 ms 716 KB Output is correct
3 Correct 19 ms 2380 KB Output is correct
4 Correct 17 ms 2560 KB Output is correct
5 Correct 32 ms 2212 KB Output is correct
6 Correct 19 ms 2380 KB Output is correct
7 Correct 20 ms 2244 KB Output is correct
8 Correct 31 ms 2268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 6 ms 748 KB Output is correct
5 Correct 5 ms 716 KB Output is correct
6 Correct 5 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 716 KB Output is correct
2 Correct 42 ms 3916 KB Output is correct
3 Correct 110 ms 8236 KB Output is correct
4 Correct 148 ms 9204 KB Output is correct
5 Correct 125 ms 9640 KB Output is correct
6 Correct 127 ms 8940 KB Output is correct
7 Correct 129 ms 9584 KB Output is correct
8 Correct 114 ms 8644 KB Output is correct
9 Correct 135 ms 8932 KB Output is correct
10 Correct 88 ms 8900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 0 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 0 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -