题解

root 站长 2020-05-27 17:14:05 1
#include <iostream>
#include <cstdio>

using namespace std;

const int N = 1e6 + 10;
int a[N], res[N];

int main() {
    int n, max = 0, maxi = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);

    int j = 1;
    for (int i = n - 1; i >= 1; i--) {
        j = i + 1;
        while (a[i] >= a[j] && a[j] > 0) j = res[j];
        res[i] = j;
    }

    for (int i = 1; i <= n; i++) printf("%d\n", res[i]);
    return 0;
}
{{ vote && vote.total.up }}

共 1 条回复

chen_zhe 沙雕

这个不是可怕,神秘,南,的DP吗