QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#83613 | #1873. Array | woxiangbaile# | WA | 195ms | 8444kb | C++14 | 2.0kb | 2023-03-02 17:58:38 | 2023-03-02 17:58:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i <= e; ++i)
#define drep(i, s, e) for (int i = s; i >= e; --i)
#define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout)
#define pv(a) cout << #a << " = " << a << endl
#define pa(a, l, r) cout << #a " : "; rep(_, l, r) cout << a[_] << ' '; cout << endl
const int N = 2e5 + 10;
int read() {
int x = 0, f = 1; char c = getchar();
for (; c < '0' || c > '9'; c = getchar()) if (c == '-') f = -1;
for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48;
return x * f;
}
int n, b[N], L[N], p[N], a[N], cnt, len, buc[N], tot;
bool tag[N];
void solve() {
n = read(), cnt = 0, len = n;
rep(i, 1, n) b[i] = read(), L[i] = 0, p[i] = -1, tag[i] = false;
rep(i, 1, n) if (b[i] < i) return printf("-1\n"), void();
rep(i, 1, n) if (b[i] <= n) len = min(len, b[i] - i + 1);
rep(i, 0, n - 1) if (b[i] < b[i + 1]) {
rep(j, b[i], b[i + 1] - 1) L[j] = i + 1;
tag[i] = true, p[b[i + 1]] = i;
}
priority_queue <int, vector <int>, greater <int> > q;
a[0] = cnt = 1;
rep(i, 1, n) {
if (~p[i]) a[i] = a[p[i]];
else if (cnt < len) a[i] = ++ cnt;
else {
if (q.size() && L[i] <= q.top()) a[i] = a[q.top()], q.pop();
else return printf("-1\n"), void();
}
// cout << "i, a[i] = " << i << ' ' << a[i] << endl;
if (q.size() && q.top() < L[i]) return printf("-1\n"), void();
if (!tag[i]) q.push(i);
}
if (cnt < len) return printf("-1\n"), void();
tot = 0;
rep(i, 1, len) buc[i] = 0;
for (int i = 1, j = 0; i <= n; ++ i) {
if (i > 1) tot -= -- buc[a[i - 1]] == 0;
while (j <= n && tot < len) {
if (++ j <= n) tot += ++ buc[a[j]] == 1;
else break;
}
// cout << "i, j = " << i << ' ' << j << endl;
if (b[i] != j) return printf("-1\n"), void();
}
rep(i, 1, n) printf("%d%c", a[i], " \n"[i == n]);
}
int main() {
for (int tc = read(); tc; -- tc) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3576kb
input:
3 4 3 3 5 5 7 4 6 6 7 8 8 8 5 2 3 4 4 6
output:
2 2 1 1 2 3 4 1 3 2 4 -1
result:
ok 233
Test #2:
score: -100
Wrong Answer
time: 195ms
memory: 8444kb
input:
23198 7 1 2 3 4 5 6 7 7 1 2 3 4 5 6 8 7 1 2 3 4 5 7 7 7 1 2 3 4 5 7 8 7 1 2 3 4 5 8 8 7 1 2 3 4 6 6 7 7 1 2 3 4 6 6 8 7 1 2 3 4 6 7 7 7 1 2 3 4 6 7 8 7 1 2 3 4 6 8 8 7 1 2 3 4 7 7 7 7 1 2 3 4 7 7 8 7 1 2 3 4 7 8 8 7 1 2 3 4 8 8 8 7 1 2 3 5 5 6 7 7 1 2 3 5 5 6 8 7 1 2 3 5 5 7 7 7 1 2 3 5 5 7 8 7 1 2 ...
output:
1 1 1 1 1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -...
result:
wrong answer wrong answer, the correct answer is -1