QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#592242#7685. Barkley IIsazhiTL 0ms13024kbC++201.9kb2024-09-26 21:28:152024-09-26 21:28:17

Judging History

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

  • [2024-09-26 21:28:17]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:13024kb
  • [2024-09-26 21:28:15]
  • 提交

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;
struct qujian{
	int l,r,mex;
};
void solve(){	
	int n,m;cin>>n>>m;
	vector<int> sum(N<<1),a(N),pre(N<<1);
	vector<qujian> st;
	fa(i,1,n){
		cin>>a[i];
	}
	auto update = [&](int x,int k)->void {
		while(x<=n){
			sum[x] += k;
			x+= lowbit(x);
		}
	};
	auto query = [&](int x) ->ll{
		ll res = 0;
		while(x){
			res +=sum[x];
			x -= lowbit(x);
		}
		return res;
	};
	fa(i,1,n){
		if(a[i]+1<=n&&pre[a[i]]+1<i){
			st.pb({pre[a[i]]+1,i-1,a[i]});
		}
		pre[a[i]] = i;
	}
	fa(i,1,n){
		if(pre[a[i]]+1<=n){
			st.pb({pre[a[i]]+1,n,a[i]});
		}
	}
	sort(all(st),[&](qujian x,qujian y){
		return x.r<y.r;
	});
	for(int i = 1;i<=n;i++){
		pre[a[i]] = 0;
	}
	int now = 0;
	ll ans = 0;
	for(int i  = 0;i<n;i++){
		while(now<st[i].r){
			now++;
			if(pre[a[now]]){
				update(now,-1);
			}
			pre[a[now]] = now;
			update(now,1);
			ans = max(ans,query(st[i].r)-query(st[i].l-1)-st[i].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;
}
/**/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
Time Limit Exceeded

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:

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

result: