This commit is contained in:
Zengtudor 2024-08-18 13:06:07 +08:00
parent 0a2db0a7d4
commit 5b8eff62bc
2 changed files with 6 additions and 14 deletions

View File

@ -15,19 +15,10 @@ int main(){
for(int i=1;i<=n;i++){
a[i]=readInt();
}
ans[n]=0;
s.push(n);
for(int i=n-1;i>=1;i--){
if (a[i]>=a[s.top()]) {
ans[i]=0;
for(int i=n;i>=1;i--){
while(!s.empty()&&a[s.top()]<=a[i])s.pop();
ans[i]=s.empty()?0:s.top();
s.push(i);
}else{
ans[i]=s.top();
while (s.size()>0&&a[s.top()]>a[i]) {
s.pop();
}
s.push(i);
}
}
for(int i=1;i<=n;i++){
cout<<ans[i]<<" ";;

View File

@ -3,5 +3,6 @@
"args":["-Wall","-g"],
"tests":[
{"in":"1.in","ans":"1.ans"}
]
],
"run_timeout":1000
}