9672022-02-06 13:13:16nmarciTitkos sorozatcpp11Accepted 40/4082ms17352 KiB
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <algorithm>
#include <list>
#include <ctime>

using namespace std;
using ll = long long int;

ll inf = 1e9+7;

void test(vector<int>& v, vector<int>& ans){
    int n = v.size();
    int ctr = n;
    vector<vector<int>> g(n);
    ans.resize(n,0);
    for(int i = 0; i < n; ++i){
        if(v[i] == -1){
            ans[i] = ctr--;
        }
        else{
            g[v[i] - 1].push_back(i);
        }
    }
    int i = n - 1;
    while(i >= 0){
        for(auto j : g[i]){
            ans[j] = ctr--;
        }
        --i;
    }
}

vector<int> kodol(vector<int>& v){
    vector<int> ret;
    for(int i = 0; i < v.size(); ++i){
        int ptr = i + 1;
        while(ptr < v.size() && v[ptr] < v[i]) ++ptr;
        if(ptr == v.size()) ret.push_back(-1);
        else ret.push_back(ptr + 1);
    }
    return ret;
}

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    vector<int> ans(n);
    for(auto& i : v){
        cin >> i;
    }
    test(v,ans);
    for(auto i : ans)
        cout << i << " ";
    cout << endl;
    /*int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; ++i){
        v[i] = i + 1;
    }
    while(next_permutation(v.begin(), v.end())){
        vector<int> kod = kodol(v);
        vector<int> dekodolt(n);
        test(kod, dekodolt);
        vector<int> chk = kodol(dekodolt);
        if(chk != kod){
            cerr << "v:" << endl;
            for(auto i : v)
                cerr << i << " ";
            cerr << endl;
            cerr << "kod:" << endl;
            for(auto i : kod)
                cerr << i << " ";
            cerr << endl;
            cerr << "dek:" << endl;
            for(auto i : dekodolt)
                cerr << i << " ";
            cerr << endl;
        }
    }*/
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/02ms1736 KiB
2Accepted0/025ms6648 KiB
3Accepted1/11ms2112 KiB
4Accepted1/11ms2116 KiB
5Accepted2/21ms2128 KiB
6Accepted1/12ms2168 KiB
7Accepted1/11ms2168 KiB
8Accepted2/22ms2172 KiB
9Accepted2/257ms11952 KiB
10Accepted2/259ms12544 KiB
11Accepted2/254ms13108 KiB
12Accepted2/250ms13680 KiB
13Accepted2/250ms14260 KiB
14Accepted2/282ms14968 KiB
15Accepted2/254ms15808 KiB
16Accepted3/352ms16132 KiB
17Accepted3/352ms16164 KiB
18Accepted3/352ms16192 KiB
19Accepted3/350ms16308 KiB
20Accepted3/352ms17352 KiB
21Accepted1/150ms15280 KiB
22Accepted1/148ms15140 KiB
23Accepted1/146ms15124 KiB