QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#222217#7616. Jump Graphucup-team1525#WA 1ms10004kbC++141.3kb2023-10-21 16:20:052023-10-21 16:20:06

Judging History

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

  • [2023-10-21 16:20:06]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:10004kb
  • [2023-10-21 16:20:05]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=300005;
int mx[N*4];
ll ans[N],f[N],g[N];
int n;
int a[N];
void build(int l,int r,int x)
{
	if (l==r)
	{
		mx[x]=l;
		return;
	}
	int mid=(l+r)/2;
	build(l,mid,x*2);
	build(mid+1,r,x*2+1);
	mx[x]=(a[mx[x*2]]>a[mx[x*2+1]]?mx[x*2]:mx[x*2+1]);
	// cout<<l<<' '<<r<<' '<<mx[x]<<endl;
}
int ask(int l,int r,int L,int R,int x)
{
	if (l==L&&r==R)
		return mx[x];
	int mid=(l+r)/2;
	if (R<=mid)
		return ask(l,mid,L,R,x*2);
	if (L>mid)
		return ask(mid+1,r,L,R,x*2+1);
	int la=ask(l,mid,L,mid,x*2),ra=ask(mid+1,r,mid+1,R,x*2+1);
	return a[la]>a[ra]?la:ra;
}
int work(int l,int r)
{
	if (l>r)
		return 0;
	int mid=ask(1,n,l,r,1);
	// cout<<l<<' '<<r<<' '<<mid<<endl;
	int ls=work(l,mid-1);
	int rs=work(mid+1,r);
	f[mid]=f[ls]+f[rs]+r-mid+1;
	g[mid]=g[ls]+g[rs]+mid-l+1;
	// cout<<l<<' '<<r<<' '<<mid<<' '<<f[mid]<<' '<<g[mid]<<endl;
	ans[l]+=f[rs]+r-mid+1;
	ans[mid]-=r-mid+1;
	ans[mid+1]-=f[rs];
	ans[mid]+=g[ls];
	ans[mid+1]+=mid-l+1;
	ans[r+1]-=mid-l+1;
	return mid;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;++i)
		scanf("%d",&a[i]);
	build(1,n,1);
	work(1,n);
	ll sum=0;
	for (int i=1;i<=n;++i)
	{
		sum+=ans[i];
		printf("%lld ",sum);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 10004kb

input:

6
1 6 3 2 5 4

output:

11 7 7 7 6 8 

result:

ok single line: '11 7 7 7 6 8 '

Test #2:

score: 0
Accepted
time: 0ms
memory: 9944kb

input:

2
1 2

output:

1 1 

result:

ok single line: '1 1 '

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 8040kb

input:

36
9 29 1 3 14 31 24 21 10 18 22 16 8 7 15 12 17 19 25 28 27 34 11 6 32 4 20 13 2 35 23 26 33 36 30 5

output:

101 98 99 99 101 92 86 84 84 84 79 78 77 77 76 78 80 92 115 155 168 212 232 232 228 230 228 228 228 300 329 329 331 438 470 470 

result:

wrong answer 1st lines differ - expected: '92 89 90 90 91 78 73 71 71 71 ...110 107 136 136 137 136 168 168', found: '101 98 99 99 101 92 86 84 84 8...28 300 329 329 331 438 470 470 '