QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#447868#8050. Random PermutationliqingyangWA 753ms7280kbC++14983b2024-06-18 22:35:562024-06-18 22:35:57

Judging History

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

  • [2024-06-18 22:35:57]
  • 评测
  • 测评结果:WA
  • 用时:753ms
  • 内存:7280kb
  • [2024-06-18 22:35:56]
  • 提交

answer

#include<iostream>
#include<cstring>
using namespace std;
const int C=3000;
int n,p[300010],P[300010];
int box[600010],*f=box+300005;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>p[i];
		P[p[i]]=i;
	}
	long long ans=0;
	int l=max(1,n-C>>1),r=min(n,n+C>>1);
	for(int i=l;i<=r;i++)
	{
		memset(box,0,sizeof(box)),f[0]=1;
		for(int j=P[i]-1,s=0;j;j--)
		{
			f[s+=p[j]<i?-1:1]++;
		}
		int sum=f[0]+f[1];
		for(int j=P[i]+1,s=0;j<=n;j++)
		{
			s+=p[j]<i?1:-1;
			sum+=f[s]+f[s+1];
		}
		ans+=(long long)i*sum;
	}
	for(int i=1;i<=n;i++)
	{
		if(p[i]>=l&&p[i]<=r)
		{
			continue;
		}
		memset(f-(C>>1)-5,0,C+10<<2),f[0]=1;
		for(int j=i-1,s=0;j>=max(1,i-(C>>1));j--)
		{
			f[s+=p[j]<p[i]?-1:1]++;
		}
		int sum=f[0]+f[1];
		for(int j=i+1,s=0;j<=min(n,i+(C>>1));j++)
		{
			s+=p[j]<p[i]?1:-1;
			sum+=f[s]+f[s+1];
		}
		ans+=(long long)p[i]*sum;
	}
	cout<<ans<<endl;
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 7280kb

input:

4
1 4 2 3

output:

22

result:

ok 1 number(s): "22"

Test #2:

score: -100
Wrong Answer
time: 753ms
memory: 6836kb

input:

100000
56449 21738 74917 44834 36187 96576 37204 28451 3444 13029 66039 8955 51445 30706 27229 37159 66052 16691 70389 29935 44984 3648 75082 73600 76621 28345 5298 37940 49412 85260 92029 18185 84398 10233 79227 98312 96649 30680 65206 38879 75397 26951 11294 58085 37297 97167 59252 44104 4058 3796...

output:

248530160689006

result:

wrong answer 1st numbers differ - expected: '250202478701074', found: '248530160689006'