QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#227801#7616. Jump Graphucup-team2230#WA 0ms3828kbC++231.3kb2023-10-27 23:33:012023-10-27 23:33:02

Judging History

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

  • [2023-10-27 23:33:02]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3828kb
  • [2023-10-27 23:33:01]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define a first
#define b second
#define pb push_back
#define eb emplace_back
using ll=long long;
using PL=pair<ll,int>;
using P=pair<int,int>;
#define tct template<class t>
#define tctu template<class t,class u>
tct using vc=vector<t>;
tctu bool chmax(t&a,u b){if(a<b){a=b;return 1;}return 0;}
tctu bool chmin(t&a,u b){if(a>b){a=b;return 1;}return 0;}

const int ALP=26;
void solve(){
	int n;
	cin>>n;
	vc<int> A(n);
	for(int i=0;i<n;i++){
		cin>>A[i];
		A[i]--;
	}
	vc<ll> ans(n);
	vc<ll> L1(n),L2(n);
	stack<int> st;
	for(int i=0;i<n;i++){
		while(!st.empty()&&A[st.top()]<A[i]){
			L2[i]+=L2[st.top()];
			st.pop();
		}
		int l=-1;
		if(!st.empty()){
			l=st.top();
			L1[i]+=L1[l];
		}
		L1[i]+=L2[i];
		ans[i]+=L1[i];
		L1[i]+=i-l;
		L2[i]+=i-l;
		st.push(i);
		//printf("%d %d : %d\n",L1[i],L2[i],ans[i]);
	}
	while(!st.empty()) st.pop();
	vc<ll> R1(n),R2(n);
	for(int i=n-1;i>=0;i--){
		while(!st.empty()&&A[st.top()]<A[i]){
			R2[i]+=R2[st.top()];
			st.pop();
		}
		int r=n;
		if(!st.empty()){
			r=st.top();
			R1[i]+=R1[r];
		}
		R1[i]+=R2[i];
		ans[i]+=R1[i];
		R1[i]+=r-i;
		R2[i]+=r-i;
		st.push(i);
	}
	for(int i=0;i<n;i++) cout<<ans[i]<<" ";
	cout<<endl;
}
	
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	int T=1;
	while(T--) solve();
}

詳細信息

Test #1:

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

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

input:

2
1 2

output:

1 1 

result:

ok single line: '1 1 '

Test #3:

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

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 100 87 81 79 79 79 73 72 71 71 70 72 72 77 83 94 107 100 120 120 116 118 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: '101 98 99 99 100 87 81 79 79 7...16 113 142 142 143 143 175 175 '