QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#261363#1873. ArrayDualqwqWA 0ms11556kbC++201.8kb2023-11-22 20:35:132023-11-22 20:35:13

Judging History

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

  • [2023-11-22 20:35:13]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:11556kb
  • [2023-11-22 20:35:13]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

namespace FastIO {
	#define iL (1 << 20)
	char ibuf[iL],*iS = ibuf + iL,*iT = ibuf + iL;
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread(ibuf,1,iL,stdin),iS == iT ? EOF : *iS++) : *iS++)
	template<typename T>
	inline void read(T &a)
	{
		char ch;int sign = 0;
		for(ch = gc();!isdigit(ch);ch = gc())
			if(ch == '-') sign = 1;
		a = ch & 15;
		for(ch = gc();isdigit(ch);ch = gc())
			a = (a << 3) + (a << 1) + (ch & 15);
		if(sign) a = -a;
	}
	char Out[iL],*iter = Out;
	#define flush() fwrite(Out,1,iter - Out,stdout),iter = Out
	template<typename T>
	inline void write(T x,char end = '\n')
	{
		int c[40],l = 0;if(x < 0) *iter++ = '-',x = -x;
		do c[++l] = x % 10,x /= 10; while(x);
		while(l) *iter++ = c[l--] + '0';
		*iter++ = end;flush();
	}
	#undef iL 
	#undef gc
	#undef flush
}
using namespace FastIO;

const int N = 2e6 + 5;
int n,a[N],b[N],tot;
int ufs[N];
int find(int x) { return ufs[x] == x ? x : ufs[x] = find(ufs[x]);}
inline void Destroy(int x) { ufs[find(x)] = find(x - 1);}
int nxt[N];
inline void work() {
	read(n);
	for(int i = 1;i <= n;i++) read(b[i]);
	for(int i = 1;i <= n;i++) if(b[i] < i) return puts("-1"),void();
	for(int i = 0;i <= n + 1;i++) ufs[i] = i;
	nxt[n] = b[n + 1] = n + 1;
	for(int i = 1;i <= n;i++) if(b[i] < b[i + 1]) nxt[i] = b[i + 1],Destroy(nxt[i]);
	for(int i = n - 1;i >= 1;i--) if(b[i] == b[i + 1]) {
		int p = find(b[i]);//printf("p:%d\n",p);
		if(p <= i && b[i] == n + 1) { nxt[i] = n + 1;continue;}
		if(p <= i) return puts("-1"),void();
		nxt[i] = p;Destroy(nxt[i]);
	} 
	tot = 0;
	for(int i = n;i >= 1;i--)
		if(nxt[i] == n + 1) a[i] = ++tot;
		else a[i] = a[nxt[i]];
	for(int i = 1;i <= n;i++) write(a[i],i == n ? '\n' : ' ');
}
int main() {
	int T;
	read(T);
	while(T--) work();
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 11556kb

input:

3
4
3 3 5 5
7
4 6 6 7 8 8 8
5
2 3 4 4 6

output:

1 2 1 1
2 3 1 4 3 2 1
-1

result:

wrong answer 233