QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#305686#7685. Barkley II275307894a#WA 61ms27224kbC++141.8kb2024-01-15 20:32:032024-01-15 20:32:03

Judging History

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

  • [2024-01-15 20:32:03]
  • 评测
  • 测评结果:WA
  • 用时:61ms
  • 内存:27224kb
  • [2024-01-15 20:32:03]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=5e5+5,M=N*20+5,K=(1<<25)+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(time(0));
int n,m,A[N],ns[N],nh,pre[N];vector<int> S[N];
vector<pii> Q[N];
namespace bit{
	int f[N];void clr(){fill(f+1,f+n+1,0);}
	void add(int x,int w){while(x<=n) f[x]+=w,x+=x&-x;}
	int qry(int x){int ans=0;while(x) ans+=f[x],x-=x&-x;return ans;}
}
void Solve(){
	int i,j;scanf("%d%d",&n,&m);
	nh=0;for(i=1;i<=n;i++) scanf("%d",&A[i]),ns[++nh]=A[i];
	sort(ns+1,ns+nh+1);
	for(i=1;i<=m+1;i++){
		auto p=LB(ns+1,ns+nh+1,i)-ns-1;
		if(p>nh||ns[p]^i){ns[++nh]=i;break;}
	}
	sort(ns+1,ns+nh+1);nh=unique(ns+1,ns+nh+1)-ns-1;
	for(i=1;i<=nh;i++) S[i].clear();
	for(i=1;i<=n;i++) A[i]=LB(ns+1,ns+nh+1,A[i])-ns,S[A[i]].emplace_back(i);
	for(i=1;i<=n;i++) Q[i].clear();
	for(i=1;i<=nh;i++){
		S[i].emplace_back(0);S[i].emplace_back(n+1);
		sort(S[i].begin(),S[i].end());
		for(j=1;j<S[i].size();j++) if(S[i][j]-1^S[i][j-1]) Q[S[i][j]-1].emplace_back(S[i][j-1]+1,-ns[i]);
	}
	fill(pre+1,pre+nh+1,0);
	int ans=-INF;bit::clr();
	for(i=1;i<=n;i++){
		if(pre[A[i]]) bit::add(pre[A[i]],-1);
		pre[A[i]]=i;bit::add(i,1);
		for(auto j:Q[i]) ans=max(ans,bit::qry(i)-bit::qry(j.fi-1)+j.se)/*,cerr<<j.fi<<' '<<i<<' '<<bit::qry(i)-bit::qry(j.fi-1)<<'\n'*/;
	}
	printf("%d\n",ans);
}
int main(){
	int t=1;
	scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 27224kb

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: 61ms
memory: 27224kb

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:

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

result:

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