code:
#include<bits/stdc++.h> using namespace std; int a[100010],top; int main() { int n; cin>>n; a[0]=-1; for(int i=1;i<=n;i++) { int x; scanf("%d",&x); while(top&&a[top]>=x)top--; printf("%d ",a[top]); a[++top]=x; } return 0; }
2023-10-30 23:53:34
code:
#include<bits/stdc++.h> using namespace std; int a[100010],top; int main() { int n; cin>>n; a[0]=-1; for(int i=1;i<=n;i++) { int x; scanf("%d",&x); while(top&&a[top]>=x)top--; printf("%d ",a[top]); a[++top]=x; } return 0; }
下一篇:C#委托