这段代码不开O2为什么TLE
查看原帖
这段代码不开O2为什么TLE
353878
异想之旅楼主2022/7/25 10:50
#include <bits/stdc++.h>
using namespace std;
int n, a[3000001];
typedef pair<int, int> pii;
int main() {
    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;
}
2022/7/25 10:50
加载中...