QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#437 | #243487 | #7685. Barkley II | Lynkcat | Lynkcat | Success! | 2023-11-08 13:07:13 | 2023-11-08 13:07:14 |
Details
Extra Test:
Wrong Answer
time: 2ms
memory: 15920kb
input:
3 1 1 1 14 14 4 13 10 9 13 1 11 5 6 8 1 9 4 12 1 1 1
output:
-1 8 7
result:
wrong answer 3rd numbers differ - expected: '-1', found: '7'
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#243487 | #7685. Barkley II | Lynkcat | WA | 254ms | 40236kb | C++20 | 1.9kb | 2023-11-08 13:05:52 | 2023-11-08 13:18:05 |
answer
#include<bits/stdc++.h>
const int N=1e6+5;
using namespace std;
int n,m,a[N],cnt[N],f[N];
struct node
{
int x,id;
bool operator<(const node&b)const{return x==b.x?id<b.id:x<b.x;}
}b[N];
struct ask
{
int l,r,val;
bool operator<(const ask&b)const{return r<b.r;}
}q[N*2];int len;
struct BIT
{
int tr[N];
void add(int x,int k){for(int i=x;i<N;i+=(i&-i))tr[i]+=k;}
int query(int x){int res=0;for(int i=x;i;i-=(i&-i))res+=tr[i];return res;}
}T;
int ans;
void clear()
{
len=0;ans=0;
for(int i=n;i>=1;i--)if(f[a[i]]){T.add(f[a[i]],-1);f[a[i]]=0;}
for(int i=1;i<=2*n+2;i++)cnt[i]=0;
}
int li[N],Len;
void solve()
{
clear();
cin>>n>>m;Len=2*n;
for(int i=1;i<=n;i++)cin>>a[i],li[i]=a[i],li[n+i]=a[i]+1;
li[++Len]=1;li[++Len]=2;
sort(li+1,li+Len+1);
Len=unique(li+1,li+Len+1)-li-1;
for(int i=1;i<=n;i++)a[i]=lower_bound(li+1,li+Len+1,a[i])-li;
for(int i=1;i<=n;i++)b[i].x=a[i],b[i].id=i,cnt[a[i]]++,ans+=(cnt[a[i]]==1);
int temp=1;while(cnt[temp])temp++;for(int i=1;i<=n;i++)cnt[a[i]]=0;ans-=temp;
sort(b+1,b+n+1);
for(int l=1,r=1;l<=n;l=r+1)
{
while(b[l].x==b[r+1].x)r++;
if(b[l].x!=b[l-1].x+1)break;
for(int i=l;i<=r;i++)
{
if(i==l)
{
if(b[l].id!=1){++len;q[len].l=1;q[len].r=b[l].id-1;q[len].val=b[l].x;}
continue;
}
if(b[i-1].id+1!=b[i].id)
{++len;q[len].l=b[i-1].id+1;q[len].r=b[i].id-1;q[len].val=b[l].x;}
}
if(b[r].id!=n){++len;q[len].l=b[r].id+1;q[len].r=n;q[len].val=b[l].x;}
}
sort(q+1,q+len+1);
for(int i=1,next=1;i<=len;i++)
{
for(int j=next;j<=q[i].r;j++)
{
if(f[a[j]])T.add(f[a[j]],-1);
T.add(j,1);
f[a[j]]=j;
}
next=q[i].r+1;
ans=max(ans,T.query(q[i].r)-T.query(q[i].l-1)-q[i].val);
}
cout<<ans<<'\n';
}
int TT;
int main()
{
// freopen("27.in","r",stdin);
// freopen("mex.out","w",stdout);
ios::sync_with_stdio(false);cin.tie(0);
cin>>TT;
while(TT--)solve();
}