QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#594110#9313. Make Maxsbj_noierWA 111ms25628kbC++142.1kb2024-09-27 19:17:592024-09-27 19:18:00

Judging History

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

  • [2024-09-27 19:18:00]
  • 评测
  • 测评结果:WA
  • 用时:111ms
  • 内存:25628kb
  • [2024-09-27 19:17:59]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long 
using namespace std;

const int maxn=2e5+10;
int t,n,m;
int a[maxn],b[maxn],c[maxn],fa[maxn],sz[maxn],pre[maxn],nxt[maxn];
vector<int>e[maxn];
inline void ipt(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		b[i]=a[i];
	}
}
inline void init(){
	sort(b+1,b+n+1);
	m=unique(b+1,b+n+1)-b-1;
	for(int i=1;i<=n;i++){
		c[i]=lower_bound(b+1,b+n+1,a[i])-b;
		e[c[i]].push_back(i);
//		printf("%lld ",c[i]);
	}
//	printf("\n");
}
inline int find(int x){
	if(fa[x]==x)return x;
	return fa[x]=find(fa[x]);
}
inline void solve(){
	int ans=0;
	for(int i=1;i<=n;i++)fa[i]=i,sz[i]=1;
	fa[0]=0,fa[n+1]=0;
	for(int i=1;i<=n;i++)pre[i]=i-1,nxt[i]=i+1;
	for(int i=1;i<=m;i++){
		for(int j=0;j<e[i].size();j++){
			int u=e[i][j];
			u=find(u);
			int v1=pre[u],v2=nxt[u];
			v1=find(v1);
			v2=find(v2);
			if(c[v1]==c[v2]){
				if(c[u]<c[v1]){
					fa[u]=v1;
					nxt[v1]=v2;
					ans+=sz[u];
					sz[v1]+=sz[u];
				}
				else if(c[u]==c[v1]){
					fa[u]=v1;
					nxt[v1]=v2;
					sz[v1]+=sz[u];
				}
			}
			else if(c[v1]>c[v2]){
				if(c[u]<c[v2]){
					fa[u]=v2;
					pre[v2]=v1;
					ans+=sz[u];
					sz[v2]+=sz[u];
				}
				else if(c[u]==c[v2]){
					fa[u]=v2;
					pre[v2]=v1;
					sz[v2]+=sz[u];
				}
				else if(c[u]<c[v1]){
					fa[u]=v1;
					nxt[v1]=v2;
					ans+=sz[u];
					sz[v1]+=sz[u];
				}
				else if(c[u]==c[v1]){
					fa[u]=v1;
					nxt[v1]=v2;
					sz[v1]+=sz[u];
				}
			}
			else {
				if(c[u]<c[v1]){
					fa[u]=v1;
					nxt[v1]=v2;
					ans+=sz[u];
					sz[v1]+=sz[u];
				}
				else if(c[u]==c[v1]){
					fa[u]=v1;
					nxt[v1]=v2;
					sz[v1]+=sz[u];
				}
				else if(c[u]<c[v2]){
					fa[u]=v2;
					pre[v2]=v1;
					ans+=sz[u];
					sz[v2]+=sz[u];
				}
				else if(c[u]==c[v2]){
					fa[u]=v2;
					pre[v2]=v1;
					sz[v2]+=sz[u];
				}
			}
//			for(int k=1;k<=n;k++)printf("%lld ",fa[k]);
//			printf("\n");
		}
		e[i].clear();
	}
	printf("%lld\n",ans);
}
signed main(){
	scanf("%lld",&t);
	while(t--){
		ipt();
		init();
		solve();
	}
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 17504kb

input:

4
2
1 2
2
2 2
7
1 1 1 2 2 2 2
3
1 2 3

output:

1
0
3
3

result:

ok 4 number(s): "1 0 3 3"

Test #2:

score: -100
Wrong Answer
time: 111ms
memory: 25628kb

input:

2
198018
875421126 585870339 471894633 383529988 625397685 944061047 704695631 105113224 459022561 760848605 980735314 847376362 980571959 329939331 644635272 326439858 752879510 837384394 175179068 182094523 397239381 1199016 185143405 279638454 252374970 822030887 860312140 137248166 993229443 164...

output:

3713798
4130372

result:

wrong answer 1st numbers differ - expected: '4084978', found: '3713798'