QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#722816 | #1873. Array | Made_in_Code | RE | 0ms | 0kb | C++14 | 1.2kb | 2024-11-07 20:15:18 | 2024-11-07 20:15:20 |
answer
#include <fstream>
using namespace std;
ifstream cin("sing.in");
ofstream cout("sing.out");
const int kMaxN = 5e5 + 1;
int t, n, m, k, a[kMaxN], b[kMaxN];
void Solve() {
cin >> n, m = n, k = 1;
for (int i = 1; i <= n; i++) {
cin >> a[i], b[i] = 0;
}
for (int i = 1; i <= n; i++) {
if (a[i] <= n) {
m = min(m, a[i] - i + 1);
}
if (a[i] < i || a[i] < a[i - 1]) {
cout << -1 << '\n';
return;
}
}
if (a[1] == n + 1) {
cout << -1 << '\n';
return;
}
for (int i = 1; i < m; i++) {
b[i] = i;
}
b[a[1]] = m;
for (int i = 1; i < n; i++) {
for (; k <= n && b[k]; k++) {
}
if (!b[i]) {
cout << -1 << '\n';
return;
} else if (a[i] == a[i + 1]) {
b[k] = b[i];
} else if (a[i + 1] <= n) {
b[a[i + 1]] = b[i];
} else if (i + 1 == k) {
cout << -1 << '\n';
return;
} else {
break;
}
}
for (; k <= n; k++) {
!b[k] && (b[k] = b[k - 1]);
}
for (int i = 1; i <= n; i++) {
cout << b[i] << " \n"[i == n];
}
}
int main() {
cin.tie(0), cout.tie(0);
ios::sync_with_stdio(0);
cin >> t;
while (t--) {
Solve();
}
return 0;
}
详细
Test #1:
score: 0
Dangerous Syscalls
input:
3 4 3 3 5 5 7 4 6 6 7 8 8 8 5 2 3 4 4 6