@[异想之旅](/user/353878) STL常数太大 手写栈罢(
by _Remake_ @ 2022-07-25 10:53:52
@[异想之旅](/user/353878) cin 太慢了,加个读入优化就能不开 O2 过
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, a[3000001];
typedef pair<int, int> pii;
int main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);//这一句
cin >> n;
stack<pii> s;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = n; i; i--) {
while (!s.empty() && s.top().first <= a[i]) s.pop();
pii temp = make_pair(a[i], i);
if (s.empty())
a[i] = 0;
else
a[i] = s.top().second;
s.push(temp);
}
for (int i = 1; i <= n; i++) cout << a[i] << " ";
return 0;
}
```
by Ninelife_Cat @ 2022-07-25 11:00:06
@[_Remake_](/user/576702) 好的,感谢
by 异想之旅 @ 2022-07-26 06:40:02
@[Ninelife_Cat](/user/329672) 谢谢大佬,疏忽了,下次还是写快读吧……
by 异想之旅 @ 2022-07-26 06:40:32
ios::syns_with_stdio(false)也行
by I_AK_CTSC @ 2022-08-09 19:20:33
scanf更快其实
by I_AK_CTSC @ 2022-08-09 19:21:10