QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#120096#5500. BarsxuzzWA 1ms5660kbC++14974b2023-07-06 13:29:482023-07-06 13:29:49

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-06 13:29:49]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5660kb
  • [2023-07-06 13:29:48]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9') f=(ch=='-')?-1:1,ch=getchar();
	while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x*f;
}
const int N=2000005;
int a[N],fa[N];
long long ans;
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int main()
{
//	freopen("wifi.in","r",stdin);
//	freopen("wifi.out","w",stdout);
	int n=read();a[1]=read(),fa[1]=1,ans=1ll*a[1]*(n-1);
	for(int i=2;i<=n;i++)
	{
		a[i]=read();int f=find(i-1);
		long long s=1ll*(n-f)*a[i]-1ll*(n-i)*a[f];
//		cout<<s<<' '<<f<<endl;
		if(s>0)
		{
			ans+=s;int ff=find(f-1);
//			cout<<ans<<endl;
			while(ff)
			{
				s=1ll*(f-ff)*(a[i]-a[f])+1ll*(i-f)*(a[ff]-a[f]);
				if(s<=0) break;
//				cout<<i<<' '<<f<<' '<<ff<<' '<<s<<' ';
				ans+=s,fa[f]=ff,f=ff,ff=find(f-1);
//				cout<<ans<<endl;
			}
			fa[i]=i;
		}
		else fa[i]=i-1;
	}
	printf("%lld\n",ans);
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5660kb

input:

2
4
5 2 2 6
5
1 5 4 4 1

output:

9

result:

wrong answer 1st lines differ - expected: '33', found: '9'