QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#255370#7685. Barkley IIsfjhWA 40ms9892kbC++141.4kb2023-11-18 15:39:462023-11-18 15:39:46

Judging History

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

  • [2023-11-18 15:39:46]
  • 评测
  • 测评结果:WA
  • 用时:40ms
  • 内存:9892kb
  • [2023-11-18 15:39:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace  std;
#define int long long
#define endl '\n'
#define fer(i,a,b) for(int i=a;i<=b;i++)
#define fdr(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
const int N=5e5+10;

int n,m;
int a[N],c[N];
int pos[N],p[N];

int lowbit(int x){
	return x&(-x);
}

int getsum(int x){
	int ans=0;
	while(x>0){
		ans+=c[x];
		x-=lowbit(x);
	}
	return ans;
}

void add(int x,int k){
	while(x<=n){
		c[x]+=k;
		x+=lowbit(x);
	}
}

bool cmp(array<int,3> A,array<int,3> B){
	return A[1]<B[1];
}

void solve(){
	cin>>n>>m;
	vector<array<int,3>> v;
	fer(i,1,n) cin>>a[i],pos[i]=0,p[i]=0,c[i]=0;
	pos[n+1]=0;p[n+1]=0;
	fer(i,1,n){
		if(i-pos[a[i]]>=2&&a[i]<=n+1){
			v.pb({pos[a[i]]+1,i-1,a[i]});
		}
		pos[a[i]]=i;
	}
	fer(i,1,n+1){
		v.pb({pos[i]+1,n,i});
	}
	sort(v.begin(),v.end(),cmp);
	int num=v.size();
	int nw=0,ans=0;
	fer(i,0,num-1){
		int l=v[i][0],r=v[i][1],mex=v[i][2];
	}
	fer(i,0,num-1){
		int l=v[i][0],r=v[i][1],mex=v[i][2];
		while(nw<r){
			nw++;
			if(p[a[nw]]){
				add(p[a[nw]],-1);
			}
			add(nw,1);
			p[a[nw]]=nw;
		}
//		cout<<l<<' '<<r<<' '<<mex<<endl;
//		cout<<getsum(r)-getsum(l-1)-mex<<endl;
		ans=max(ans,getsum(r)-getsum(l-1)-mex);
	}
	cout<<ans<<endl;
}




signed main(){
	ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		solve();
	}
}
















Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 40ms
memory: 9756kb

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:

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

result:

wrong answer 8th numbers differ - expected: '7', found: '5'