QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#367598#1873. ArrayzhaohaikunWA 88ms18412kbC++201.8kb2024-03-26 10:06:422024-03-26 10:06:43

Judging History

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

  • [2024-03-26 10:06:43]
  • 评测
  • 测评结果:WA
  • 用时:88ms
  • 内存:18412kb
  • [2024-03-26 10:06:42]
  • 提交

answer

// MagicDark
#include <bits/stdc++.h>
#define debug cerr << "[" << __LINE__ << "] "
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> inline void chkmax(T &x, T y) {x = max(x, y);}
template <typename T> inline void chkmin(T &x, T y) {x = min(x, y);}
template <typename T> inline void read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	x *= f;
}
const int N = 2e5 + 10;
int n, b[N], lim[N], prelim[N], suflim[N], a[N];
vector <int> v[N];
void zhk() {
	read(n);
	F(i, 1, n) {
		v[i].clear();
		prelim[i] = n + 1;
		suflim[i] = 0;
		lim[i] = i;
	}
	int fi = 0;
	F(i, 1, n) {
		read(b[i]);
		if (b[i] == n + 1 && !fi) fi = i - 1;
		chkmin(lim[b[i]], i);
		chkmin(prelim[i - 1], b[i]);
		chkmax(suflim[n + 1], i);
	}
	DF(i, n - 1, 1) chkmin(prelim[i], prelim[i + 1]);
	F(i, 2, n) chkmax(suflim[i], suflim[i - 1]);
	priority_queue <int> q;
	int m = 0;
	DF(i, n, 1) {
		if (q.empty() || i == fi) {
			if (prelim[i] != n + 1) return puts("-1"), void();
			a[i] = ++m;
		} else {
			int x = q.top(); q.pop();
			if (x > prelim[i] || i < suflim[x]) return puts("-1"), void();
			a[i] = a[x];
		}
		v[lim[i]].push_back(i);
		for (int j: v[i]) q.push(j);
	}
	if (q.size() && suflim[q.top()]) return puts("-1"), void();
	F(i, 1, n) cout << a[i] << ' '; cout << '\n';
}
signed main() {
	int _ = 1;
	cin >> _;
	while (_--) zhk();
	return 0;
}
/* why?
*/

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3848kb

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 1 4 3 2 1 
-1

result:

ok 233

Test #2:

score: -100
Wrong Answer
time: 88ms
memory: 18412kb

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