This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// In the Name of Allah
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,avx,avx2,sse4.2,popcnt,tune=native")
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pb push_back
#define pp pop_back
#define all(x) x.begin(), x.end()
const int N = 1e5 + 12;
int b[N], n, a[N], R[N], x, k, c[N], t[N];
void ip() {
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> b[i];
}
void f(int l, int r) {
if (r - l <= 1) {
if (r - l == 1)
a[l] = x++;
return;
}
f(l + 1, min(t[l] + 1, r));
a[l] = x++;
f(t[l] + 1, r);
}
void solve() {
x = 1;
for (int i = n - 1; ~i; --i)
if (b[i] == -1)
b[i] = n + 1;
memset(c, 127, sizeof c);
vector<int> v;
for (int i = n - 1; ~i; --i) {
while (!v.empty() && b[v.back()] < b[i])
v.pp();
if (b[i] == n + 1)
R[i] = n;
else {
if (v.empty()) {
cout << -1;
return;
}
R[i] = v.back();
if (b[i] > 1 && c[b[i] - 1] > R[i]) {
cout << -1;
return;
}
}
if (b[i] > 1 && b[i] != n + 1)
t[i] = t[c[b[i] - 1]];
else if (b[i] == 1)
t[i] = i;
else
t[i] = n;
c[b[i]] = i;
v.pb(i);
}
f(0, n);
for (int i = 0; i < n; i++)
cout << a[i] << ' ';
}
int32_t main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
ip(), solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |