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++){ for(int i=1;i<=n;i++){
a[i]=readInt(); a[i]=readInt();
} }
ans[n]=0; for(int i=n;i>=1;i--){
s.push(n); while(!s.empty()&&a[s.top()]<=a[i])s.pop();
for(int i=n-1;i>=1;i--){ ans[i]=s.empty()?0:s.top();
if (a[i]>=a[s.top()]) {
ans[i]=0;
s.push(i); 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++){ for(int i=1;i<=n;i++){
cout<<ans[i]<<" ";; cout<<ans[i]<<" ";;

View File

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