QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#261371#1873. ArrayDualqwqWA 50ms19344kbC++201.9kb2023-11-22 20:40:142023-11-22 20:40:15

Judging History

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

  • [2023-11-22 20:40:15]
  • 评测
  • 测评结果:WA
  • 用时:50ms
  • 内存:19344kb
  • [2023-11-22 20:40:14]
  • 提交

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];
bool vst[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,vst[i] = 0;
	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]);
	Destroy(b[1]);
	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]],vst[nxt[i]] = true;
	for(int i = b[1] + 1;i <= n;i++) if(!vst[i]) return puts("-1"),void();
	for(int i = 1;i <= n;i++) write(a[i],i == n ? '\n' : ' ');
}
int main() {
	int T;
	read(T);
	while(T--) work();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 13784kb

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: 50ms
memory: 19344kb

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 oh no! -1