QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#233674#7616. Jump Graph275307894aWA 1ms10212kbC++142.0kb2023-10-31 21:17:512023-10-31 21:17:51

Judging History

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

  • [2023-10-31 21:17:51]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:10212kb
  • [2023-10-31 21:17:51]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=3e5+5,M=(1<<15)+5,K=(1<<25)+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(time(0));
int n,p[N],st[N],sh,L[N],R[N];ll f[N][2],ans[N];
void Solve(){
	int i,j;scanf("%d",&n);
	for(i=1;i<=n;i++) scanf("%d",&p[i]);
	for(i=1;i<=n;i++){
		while(sh&&p[st[sh]]<p[i]) sh--;
		L[i]=st[sh];st[++sh]=i;
	}
	st[sh=0]=n+1;
	for(i=n;i;i--){
		while(sh&&p[st[sh]]<p[i]) sh--;
		R[i]=st[sh];st[++sh]=i;
	}
	vector<pii> E;
	for(i=1;i<=n;i++) E.emplace_back(i,L[i]),E.emplace_back(i,R[i]);
	sort(E.begin(),E.end(),[](pii x,pii y){return abs(x.fi-x.se)<abs(y.fi-y.se);});
	for(auto i:E){
		int op=(i.fi<i.se);
		int x=min(i.fi,i.se),y=max(i.fi,i.se);
		f[i.fi][op]=y-x-1;
		if(i.se!=n+1){
			sh=0;
			for(int j=x+1;j<y;j++) {
				while(sh&&p[st[sh]]<p[j]) sh--;
				st[++sh]=j;
			}
			for(j=1+(i.se!=0);j<=sh;j++) f[i.fi][op]+=f[st[j]][0];
		}
		if(i.se!=0){
			sh=0;
			for(int j=y-1;j>x;j--){
				while(sh&&p[st[sh]]<p[j]) sh--;
				st[++sh]=j;
			}
			for(j=1+(i.se!=n+1);j<=sh;j++) f[i.fi][op]+=f[st[j]][1];
		}
	}
	ll tot=0;sh=0;
	for(i=1;i<=n;i++){
		while(sh&&p[st[sh]]<p[i]) tot-=f[st[sh--]][0];
		st[++sh]=i;tot+=f[i][0];
		ans[i]+=tot;
	}
	tot=0;sh=0;
	for(i=n;i;i--){
		while(sh&&p[st[sh]]<p[i]) tot-=f[st[sh--]][1];
		st[++sh]=i;tot+=f[i][1];
		ans[i]+=tot;
	}
	// for(i=1;i<=n;i++) cerr<<f[i][0]<<' '<<f[i][1]<<'\n';
	for(i=1;i<=n;i++) printf("%lld ",ans[i]+n-1-(R[i]-L[i]-2));
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1ms
memory: 10212kb

input:

2
1 2

output:

1 1 

result:

ok single line: '1 1 '

Test #3:

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

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 90 77 72 71 71 71 65 64 64 64 63 65 65 68 74 82 95 88 111 111 107 111 109 110 110 107 136 136 136 136 168 168 

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 90 77 72 71 71 71 ...10 107 136 136 136 136 168 168 '