QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#255338#7678. The GamesfjhWA 0ms9628kbC++141.4kb2023-11-18 15:34:362023-11-18 15:34:36

Judging History

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

  • [2023-11-18 15:34:36]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:9628kb
  • [2023-11-18 15:34:36]
  • 提交

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: 0
Wrong Answer
time: 0ms
memory: 9628kb

input:

6
5 3
1 2 2 3 3
2 3 4
4 2
1 2 2 4
2 4
5 2
2 3 3 4 4
5 5
6 1
1 1 1 1 1 1
4
4 2
1 1 1 2
2 2
4 1
1 1 1 1
2

output:

1
0
0
2
0
0

result:

wrong answer Wrong answer, number of operation is not correct (test case 1)