update
This commit is contained in:
parent
0a2db0a7d4
commit
5b8eff62bc
@ -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;
|
||||
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=n;i>=1;i--){
|
||||
while(!s.empty()&&a[s.top()]<=a[i])s.pop();
|
||||
ans[i]=s.empty()?0:s.top();
|
||||
s.push(i);
|
||||
}
|
||||
for(int i=1;i<=n;i++){
|
||||
cout<<ans[i]<<" ";;
|
||||
|
@ -3,5 +3,6 @@
|
||||
"args":["-Wall","-g"],
|
||||
"tests":[
|
||||
{"in":"1.in","ans":"1.ans"}
|
||||
]
|
||||
],
|
||||
"run_timeout":1000
|
||||
}
|
Loading…
Reference in New Issue
Block a user