QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#592495#7685. Barkley IIsazhiRE 0ms0kbC++201.9kb2024-09-26 22:58:272024-09-26 22:58:28

Judging History

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

  • [2024-09-26 22:58:28]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-09-26 22:58:27]
  • 提交

answer

// author:  jieda
// file:	cpp
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
# define fi first
# define se second
# define all(x) x.begin(),x.end()
# define stst stringstream
# define pb push_back
# define pf push_front
# define pp push
# define lowbit(x) (x)&(-x)
# define fa(i,op,n) for (ll i = op; i <= n; i++)
# define fb(j,op,n) for (ll j = op; j >= n; j--)
# define fg(i,op,n) for (ll i = op; i != n; i = ne[i])
int dx[4] = {-1,0,1,0},dy[4] = {0,1,0,-1};
typedef unsigned long long  ull;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
const ll N = 5e5+10,M = 1e5+10,INF = 0x3f3f3f3f,mod = 1e9+7;
const ll MOD = 212370440130137957ll;//hash(hight)
const int base = 131;
const double eps = 1e-3;
const int seed=10086,mo=1e6+7; //hash(lower)
int prime = 233317;

void solve(){	
	int n,m;cin>>n>>m;
	vector<int> a(n+1);
	vector<array<int,3>> tr;
	fa(i,1,n) cin>>a[i];
	map<int,int> lft,pre;
	vector<int> sum(max(n,m)+10);
	auto add = [&](int x,int k) ->void{
		while(x<N){
			sum[x] += k;
			x += lowbit(x); 
		}
	};
	auto query = [&](int x) ->int{
		int res =0;
		while(x){
			res += sum[x];
			x -= lowbit(x);
		}
		return res;
	};
	for(int i  =1;i<=n;i++){
		lft[i] = pre[a[i]];pre[a[i]] = i;
		if((i-1)-(lft[i]+1)+1>0){
			tr.pb({lft[i]+1,i-1,a[i]});
		}
		
	}
	for(int i =1;i<=n+1;i++){
		if(pre[i]<n)tr.pb({pre[i]+1,n,i});
	}
	
	sort(all(tr),[&](auto &x,auto &y){
		return x[1]<y[1];
	});
	int ans = -1,now = 0;
	for(auto [l,r,mex]:tr){
	  //  cout<<l<<' '<<r<<' '<<mex<<'\n';
		while(now<r){
			now++;
			if(lft[now]) {
				add(lft[now],-1);
			}
			add(now,1);
		}
		ans = max(ans,query(r)-query(l-1)-mex);
	}
	cout<<ans<<'\n';
}	

int main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int t = 1;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}
/*

*/

详细

Test #1:

score: 0
Runtime Error

input:

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

output:


result: