文章目录
引入
#include<iostream>
using namespace std;
const int N=100010;
int n;
int stk[N],tt;
int main()
{
cin.tie(0);
//ios::sync_with_stdio(false);
cin >> n;
//scanf("%d",&n);
for(int i=0;i<n;i++)
{
int x;
//scanf("%d",&x);
cin >> x;
while(tt && stk[tt]>=x)tt--;
if(tt)
cout << stk[tt]<< ' ';
//printf("%d ",stk[tt]);
else cout << -1 << ' ';
//else printf("-1 ");
stk[++ tt]=x;
}
return 0;
}
结果
一:scanf printf输入输出运行的结果最快,数据量级超过100万(一百万)时,推荐用scanf和printf
运行时间 88ms
以下三种为cin cout输入输出
二:ios::sync_with_stdio(false);
628ms
三: cin.tie(0);
238ms
如果不用printf和scanf 纯用cin cout
加上 cin.tie(0) 和 ios::sync_with_stdio(false)
才能达到92ms