QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#647976#7685. Barkley IIsilver_museWA 38ms7840kbC++201.5kb2024-10-17 16:26:402024-10-17 16:26:41

Judging History

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

  • [2024-10-17 16:26:41]
  • 评测
  • 测评结果:WA
  • 用时:38ms
  • 内存:7840kb
  • [2024-10-17 16:26:40]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define ph push_back
using namespace std;

const int N=5e5+5;
int T,n,m,a[N];
int bit[N],lst[N];
vector<int>va,pos[N];
vector<array<int,2> >que[N];

void add(int x,int d)
{
    for(;x<=n;x+=x&(-x)) bit[x]+=d;
}
int query(int x)
{
    int res=0;
    for(;x;x-=x&(-x)) res+=bit[x];
    return res;
}

void clear()
{
    for(int i=1;i<=n;i++) que[i].clear(),bit[i]=0;
    for(auto it:va) pos[it].clear(),lst[it]=0;
    va.clear();
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin>>T;
    while(T--)
    {
        cin>>n>>m;
        clear();
        for(int i=1;i<=n;i++) 
        {
            cin>>a[i];
            va.ph(a[i]);
            pos[a[i]].ph(i);
        }
        sort(va.begin(),va.end());
        va.erase(unique(va.begin(),va.end()),va.end());
        for(auto u:va)
        {
            if(pos[u][0]>1) que[pos[u][0]-1].ph({1,u});
            for(int i=1;i<pos[u].size();i++)
                if(pos[u][i]>pos[u][i-1]+1) que[pos[u][i]-1].ph({pos[u][i-1]+1,u});
            if(n>pos[u].back()) que[n].ph({pos[u].back()+1,u});
        }
        int ans=0;
        for(int r=1;r<=n;r++)
        {
            int p=lst[a[r]];
            add(p+1,1); add(r+1,-1);
            lst[a[r]]=r;
            for(auto it:que[r])
                ans=max(ans,query(it[0])-it[1]);
        }
        cout<<ans<<endl;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 7840kb

input:

2
5 4
1 2 2 3 4
5 10000
5 2 3 4 1

output:

2
3

result:

ok 2 number(s): "2 3"

Test #2:

score: -100
Wrong Answer
time: 38ms
memory: 7780kb

input:

50000
10 19
12 6 1 12 11 15 4 1 13 18
10 8
8 7 6 7 6 2 2 3 4 8
10 6
3 2 6 6 5 2 3 4 5 6
10 11
6 3 7 9 2 1 2 10 10 4
10 6
6 1 2 6 1 1 3 4 2 1
10 9
8 5 3 9 1 7 5 5 1 1
10 5
1 4 3 2 5 4 5 3 5 2
10 14
3 8 12 10 4 2 3 13 7 3
10 14
5 5 12 2 8 1 13 9 8 5
10 7
5 5 6 6 1 5 3 7 3 4
10 7
5 1 4 6 1 6 4 3 7 5
10...

output:

3
1
2
4
2
3
3
3
3
3
4
5
2
3
0
3
1
3
7
6
3
3
0
2
4
4
6
2
3
0
6
1
2
2
2
5
3
3
3
3
2
5
2
1
3
3
2
3
1
4
2
2
4
4
2
2
5
3
2
1
4
3
3
3
2
3
0
4
7
6
2
2
4
3
3
4
0
6
3
3
3
3
4
0
1
1
4
5
4
5
3
1
1
2
1
3
3
4
4
3
4
2
1
3
4
4
3
0
3
4
3
5
4
4
2
4
6
4
4
5
3
4
5
1
4
3
3
3
3
0
3
2
1
2
5
1
2
1
4
4
2
2
4
5
4
3
0
6
6
3
...

result:

wrong answer 1st numbers differ - expected: '6', found: '3'