QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#780153#9787. Shrek's Song of the SwampmyloveATRIWA 108ms35080kbC++144.2kb2024-11-25 02:13:552024-11-25 02:13:56

Judging History

你现在查看的是最新测评结果

  • [2024-11-25 02:13:56]
  • 评测
  • 测评结果:WA
  • 用时:108ms
  • 内存:35080kb
  • [2024-11-25 02:13:55]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ldb=long double;
using ull=unsigned long long;
const long long inf=0x3f3f3f3f3f3f3f3f;
using i128=__int128;
const int mod=1000000007;
const long double eps=0.00000000001;

ll a[1000010];
ll f[1000010];
ll dp0[1000010];
ll dp1[1000010];
map<ll,ll>b;
map<ll,ll>c0,c1;
void solve()
{
    ll n;
    cin>>n;
    ll mx0=0;
    ll mx1=0;
    for(ll i=1;i<=n;i++)cin>>a[i];
    for(ll i=n;i>=1;i--)
    {
        if(b.count(a[i]))f[i]=1;
        else f[i]=0;
        b[a[i]]++;
    }

    for(ll i=1;i<=n;i++)
    {
        if(f[i]==0)
        {
            if(c0.count(a[i])&&c1.count(a[i]))
            {
                dp0[i]=max(c0[a[i]],c1[a[i]])+1;
                c0[a[i]]=max(c0[a[i]],dp0[i]);
                mx0=max(mx0,dp0[i]);
            }
            else if(!c0.count(a[i])&&c1.count(a[i]))
            {
                dp0[i]=max(dp0[i],c1[a[i]]+1);
                c0[a[i]]=max(c0[a[i]],dp0[i]);
                mx0=max(mx0,dp0[i]);
            }
            else if(c0.count(a[i])&&!c1.count(a[i]))
            {
                dp0[i]=max(dp0[i],c0[a[i]]+1);
                c0[a[i]]=max(c0[a[i]],dp0[i]);
                mx0=max(mx0,dp0[i]);
            }
        }
        else if(f[i]==1)
        {
            //dp1[i]
            if(c0.count(a[i])&&c1.count(a[i]))
            {
                if(mx0==c0[a[i]]||mx0==c1[a[i]])
                {
                    dp0[i]=max(dp0[i],mx0+1);
                    dp1[i]=max(dp1[i],mx0+1);
                    c0[a[i]]=max(c0[a[i]],dp0[i]);
                    c1[a[i]]=max(c1[a[i]],dp1[i]);
                    mx0=max(mx0,dp0[i]);
                    mx1=max(mx1,dp1[i]);
                }
                else
                {
                    dp0[i]=max(c0[a[i]],c1[a[i]])+1;
                    dp1[i]=max(dp1[i],mx0+1);
                    c0[a[i]]=max(c0[a[i]],dp0[i]);
                    c1[a[i]]=max(c1[a[i]],dp1[i]);
                    mx0=max(mx0,dp0[i]);
                    mx1=max(mx1,dp1[i]);
                }
            }
            else if(!c0.count(a[i])&&c1.count(a[i]))
            {
                if(mx0==c1[a[i]])
                {
                    dp0[i]=max(dp0[i],mx0+1);
                    dp1[i]=max(dp1[i],mx0+1);
                    c0[a[i]]=max(c0[a[i]],dp0[i]);
                    c1[a[i]]=max(c1[a[i]],dp1[i]);
                    mx0=max(mx0,dp0[i]);
                    mx1=max(mx1,dp1[i]);
                }
                else
                {
                    dp0[i]=max(dp0[i],c1[a[i]]+1);
                    dp1[i]=max(dp1[i],mx0+1);
                    c0[a[i]]=max(c0[a[i]],dp0[i]);
                    c1[a[i]]=max(c1[a[i]],dp1[i]);
                    mx0=max(mx0,dp0[i]);
                    mx1=max(mx1,dp1[i]);
                }
            }
            else if(c0.count(a[i])&&!c1.count(a[i]))
            {
                if(mx0==c0[a[i]])
                {
                    dp0[i]=max(dp0[i],mx0+1);
                    dp1[i]=max(dp1[i],mx0+1);
                    c0[a[i]]=max(c0[a[i]],dp0[i]);
                    c1[a[i]]=max(c1[a[i]],dp1[i]);
                    mx0=max(mx0,dp0[i]);
                    mx1=max(mx1,dp1[i]);
                }
                else
                {
                    dp0[i]=max(dp0[i],c0[a[i]]+1);
                    dp1[i]=max(dp1[i],mx0+1);
                    c0[a[i]]=max(c0[a[i]],dp0[i]);
                    c1[a[i]]=max(c1[a[i]],dp1[i]);
                    mx0=max(mx0,dp0[i]);
                    mx1=max(mx1,dp1[i]);
                }
            }
            else if(!c0.count(a[i])&&!c1.count(a[i]))
            {
                dp1[i]=max(dp1[i],mx0+1);
                c1[a[i]]=max(c1[a[i]],dp1[i]);
                mx1=max(mx1,dp1[i]);
            }
            dp1[i]=max(dp1[i],1ll);
            mx1=max(mx1,dp1[i]);
        }
    }
    ll ans=0;
    
    printf("%lld\n",mx0);







    



}

int main()
{
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    ll _=1;
//    cin>>_;
    while(_--)
    {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7880kb

input:

9
1 2 3 1 3 1 2 3 2

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: 0
Accepted
time: 1ms
memory: 7896kb

input:

6
3 4 10 1 -3 5

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 1ms
memory: 8008kb

input:

4
1 2 1 1

output:

3

result:

ok 1 number(s): "3"

Test #4:

score: 0
Accepted
time: 0ms
memory: 7932kb

input:

9
1 2 3 1 3 1 2 3 2

output:

5

result:

ok 1 number(s): "5"

Test #5:

score: 0
Accepted
time: 0ms
memory: 7856kb

input:

6
3 4 10 1 -3 5

output:

0

result:

ok 1 number(s): "0"

Test #6:

score: 0
Accepted
time: 0ms
memory: 7880kb

input:

4
1 2 1 1

output:

3

result:

ok 1 number(s): "3"

Test #7:

score: -100
Wrong Answer
time: 108ms
memory: 35080kb

input:

1000000
7 2 6 10 3 1 9 3 5 3 8 10 8 4 10 1 9 5 2 7 9 7 10 4 5 2 10 9 6 3 6 10 5 2 9 3 4 6 6 10 10 6 1 9 4 5 7 2 2 10 2 8 5 6 1 8 3 9 1 8 1 6 6 1 4 9 3 8 1 4 10 10 7 4 9 8 7 1 9 1 5 5 6 5 5 6 7 4 10 6 1 6 10 6 7 8 1 9 1 9 10 3 2 5 2 3 9 2 9 4 8 4 8 9 2 6 8 4 5 3 3 3 2 6 8 10 2 10 2 4 10 10 10 7 1 3 2...

output:

438335

result:

wrong answer 1st numbers differ - expected: '463867', found: '438335'