QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#367597#1873. ArrayzhaohaikunWA 1ms3592kbC++201.7kb2024-03-26 10:03:582024-03-26 10:03:59

Judging History

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

  • [2024-03-26 10:03:59]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3592kb
  • [2024-03-26 10:03:58]
  • 提交

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;
	}
	F(i, 1, n) {
		read(b[i]);
		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()) {
			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: 0
Wrong Answer
time: 1ms
memory: 3592kb

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

result:

wrong answer 233