QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#232648#7616. Jump GraphPhantomThresholdWA 0ms22092kbC++201.8kb2023-10-30 18:35:192023-10-30 18:35:21

Judging History

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

  • [2023-10-30 18:35:21]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:22092kb
  • [2023-10-30 18:35:19]
  • 提交

answer

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

const int maxn = 210000;

int n;
int p[maxn];

int fa[maxn],li[maxn],ri[maxn],v[maxn];
int findfa(const int x){ return fa[x]==x?x:fa[x]=findfa(fa[x]); }

int minsum[maxn],lsum[maxn],rsum[maxn],lnum[maxn],num[maxn],rnum[maxn];
int ans[maxn];

void add(int l,int r,int c)
{
	ans[l]+=c;
	ans[r+1]-=c;
}

signed main()
{
	///////////////////////////////////////////////
	ios_base::sync_with_stdio(false);
	
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int x; cin>>x;
		p[x]=i;
	}
	
	for(int i=1;i<=n;i++)
	{
		int j=p[i]; 
		fa[j]=j; v[j]=1;
		
		int lf= v[j-1]?findfa(j-1):0;
		int rf= v[j+1]?findfa(j+1):0;
		
		if(lf&&rf)
		{
			if(ri[rf]<n) add(li[lf],ri[lf],minsum[rf]+ri[rf]-li[rf]+1);
			else add(li[lf],ri[lf],lsum[rf]+ri[rf]-li[rf]+1);
			
			if(li[lf]>1) add(li[rf],ri[rf],minsum[lf]+ri[lf]-li[lf]+1);
			else add(li[rf],ri[rf],rsum[lf]+ri[lf]-li[lf]+1);
		}
		if(lf) add(li[lf],ri[lf],1);
		if(rf) add(li[rf],ri[rf],1);
		
		if(lf)
		{
			if(li[lf]>1) add(j,j,minsum[lf]+lnum[lf]);
			else add(j,j,rsum[lf]);
		}
		if(rf)
		{
			if(ri[rf]<n) add(j,j,minsum[rf]+rnum[rf]);
			else add(j,j,lsum[rf]);
		}
		
		li[j]=ri[j]=j;
		minsum[j]=lsum[j]=rsum[j]=1;
		lnum[j]=rnum[j]=0;
		num[j]=1;
		if(lf)
		{
			fa[lf]=j,li[j]=li[lf];
			minsum[j]+= minsum[lf]+rnum[lf];
			lsum[j]+=lsum[lf];
			rsum[j]+=ri[lf]-li[lf]+1+rsum[lf];
			lnum[j]+=lnum[lf]+num[lf];
			num[j]+=rnum[lf];
		}
		if(rf)
		{
			fa[rf]=j,ri[j]=ri[rf];
			minsum[j]+= minsum[rf]+lnum[rf];
			lsum[j]+= ri[rf]-li[rf]+1+lsum[rf];
			rsum[j]+=rsum[rf];
			rnum[j]+=rnum[rf]+num[rf];
			num[j]+=lnum[rf];
		}
	}
	
	for(int i=1;i<=n;i++) ans[i]+=ans[i-1];
	for(int i=1;i<=n;i++) cout<<ans[i]<<" \n"[i==n];
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 22092kb

input:

2
1 2

output:

1 1

result:

ok single line: '1 1'

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 22088kb

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:

92 89 90 90 91 79 74 72 72 72 66 66 65 65 64 66 66 71 75 86 96 97 117 117 115 117 116 116 116 113 142 142 143 143 175 175

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: '92 89 90 90 91 79 74 72 72 72 ...116 113 142 142 143 143 175 175'