QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#592298#7685. Barkley IIsazhiWA 42ms3940kbC++202.0kb2024-09-26 21:49:152024-09-26 21:49:19

Judging History

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

  • [2024-09-26 21:49:19]
  • 评测
  • 测评结果:WA
  • 用时:42ms
  • 内存:3940kb
  • [2024-09-26 21:49: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(max(n,m)+10),a(n+10),pre(max(n,m)+10);
	vector<qujian> st;
	fa(i,1,n){
		cin>>a[i];
	}
	auto update = [&](int x,int k)->void {
		while(x<=n+10){
			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]<=n+1&&pre[a[i]]+1<i){
			st.pb({pre[a[i]]+1,i-1,a[i]});
		}
		pre[a[i]] = i;
	}
	fa(i,1,n+1){
		if(pre[i]+1<=n){
			st.pb({pre[i]+1,n,i});
		}
	}
	sort(all(st),[&](qujian x,qujian y){
		return x.r<y.r;
	});
	for(int i = 1;i<=n+1;i++){
		pre[a[i]] = 0;
	}
	int now = 0;
	ll ans = -1;
	for(int i  = 0;i<n;i++){
		while(now<st[i].r){
			now++;
			if(pre[a[now]]){
				update(pre[a[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: 3940kb

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: 42ms
memory: 3792kb

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
1
0
4
2
3
1
3
4
1
1
5
0
3
6
3
1
5
7
6
3
5
6
2
6
8
7
2
3
5
5
1
2
2
0
5
3
0
1
3
2
5
2
1
2
5
2
3
3
8
6
2
1
7
2
2
5
4
1
6
6
3
7
3
2
1
0
7
6
6
2
2
4
3
3
3
4
6
3
4
3
1
3
0
5
9
2
2
3
5
3
5
2
0
1
2
6
8
4
3
4
5
5
5
7
7
2
2
1
5
1
5
4
4
5
4
4
3
6
7
2
3
5
7
4
7
3
7
0
6
3
2
-1
2
5
4
1
3
4
5
2
6
4
5
4
3
-1
2
6
...

result:

wrong answer 2nd numbers differ - expected: '5', found: '1'