update
This commit is contained in:
parent
546411d259
commit
0a2db0a7d4
1
day14/P5788/1.ans
Normal file
1
day14/P5788/1.ans
Normal file
@ -0,0 +1 @@
|
||||
2 5 4 5 0
|
2
day14/P5788/1.in
Normal file
2
day14/P5788/1.in
Normal file
@ -0,0 +1,2 @@
|
||||
5
|
||||
1 4 2 3 5
|
@ -0,0 +1,50 @@
|
||||
#include <cctype>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <stack>
|
||||
using namespace std;
|
||||
|
||||
const int MAX_N=3e6+5;
|
||||
int readInt();
|
||||
int a[MAX_N];
|
||||
int ans[MAX_N];
|
||||
stack<int>s;
|
||||
|
||||
int main(){
|
||||
const int n=readInt();
|
||||
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=1;i<=n;i++){
|
||||
cout<<ans[i]<<" ";;
|
||||
}
|
||||
cout<<endl;
|
||||
}
|
||||
|
||||
int readInt(){
|
||||
int x=0,w=1;
|
||||
char ch=0;
|
||||
while (!isdigit(ch)) {
|
||||
if(ch=='-')w=-1;
|
||||
ch=getchar();
|
||||
}
|
||||
while(isdigit(ch)){
|
||||
x=x*10+(ch-'0');
|
||||
ch=getchar();
|
||||
}
|
||||
return x*w;
|
||||
}
|
7
day14/P5788/P5788.json
Normal file
7
day14/P5788/P5788.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"files":["P5788.cpp"],
|
||||
"args":["-Wall","-g"],
|
||||
"tests":[
|
||||
{"in":"1.in","ans":"1.ans"}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user