// 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 (l != r)
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
860 KB |
Output is correct |
2 |
Incorrect |
0 ms |
860 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
860 KB |
Output is correct |
2 |
Incorrect |
0 ms |
860 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
1880 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
1880 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
860 KB |
Output is correct |
2 |
Incorrect |
0 ms |
860 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |