QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#722816#1873. ArrayMade_in_CodeRE 0ms0kbC++141.2kb2024-11-07 20:15:182024-11-07 20:15:20

Judging History

你现在查看的是最新测评结果

  • [2024-11-07 20:15:20]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-07 20:15:18]
  • 提交

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

output:


result: