QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#592439#7685. Barkley IIsazhiWA 59ms3960kbC++201.9kb2024-09-26 22:34:082024-09-26 22:34:08

Judging History

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

  • [2024-09-26 22:34:08]
  • 评测
  • 测评结果:WA
  • 用时:59ms
  • 内存:3960kb
  • [2024-09-26 22:34:08]
  • 提交

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;
	vector<int> pre(max(n,m)+10),sum((max(n,m)<<1)+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]];
		if((i-1)-pre[a[i]]+1>0){
			tr.pb({pre[a[i]]+1,i-1,a[i]});
		}
		pre[a[i]] = i;
	}
	for(int i =1;i<=n+1;i++){
		tr.pb({pre[a[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){
		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: 100
Accepted
time: 0ms
memory: 3960kb

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: 59ms
memory: 3664kb

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:

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

result:

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