QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#283472#1873. ArrayCryingWA 954ms7704kbC++172.3kb2023-12-14 17:49:212023-12-14 17:49:21

Judging History

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

  • [2023-12-14 17:49:21]
  • 评测
  • 测评结果:WA
  • 用时:954ms
  • 内存:7704kb
  • [2023-12-14 17:49:21]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define op(x) ((x&1)?x+1:x-1)
#define odd(x) (x&1)
#define even(x) (!odd(x))
#define lc(x) (x<<1)
#define rc(x) (lc(x)|1)
#define lowbit(x) (x&-x)
#define mp(x,y) make_pair(x,y)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
using namespace std;
const int MAXN = 2e5+10;

int T,n,b[MAXN],pre[MAXN],to[MAXN],f[MAXN];

deque<int>dq;

int chk(int mid){ //(b[1]-mid,b[1]]范围内的点强制不向前接
	while(dq.size())dq.pop_back();

	rep(i,1,n){
		if(!pre[i] && i!=1 && !(i<=b[1] && i>b[1]-mid)){ 
			//找一个人接,找不到也没有问题
			if(dq.size()){
				int u = dq.front();
				if(to[u] < i)return 0;
				dq.pop_front();
			}
		}
		if(to[i] != -1)dq.push_back(i);
	}
	if(dq.size()){
		int u = dq.front(); if(to[u] != n+1)return 0;
	}
	return 1;
}

int ans[MAXN];

void solve(){
	cin>>n;
	rep(i,1,n)cin>>b[i];

	rep(i,1,n)if(b[i] < i)return void(cout<<"-1\n");
	if(b[1] == n+1)return void(cout<<"-1\n");

	if(b[n] == n){ //corner case
		rep(i,1,n)if(b[i] != i)return void(cout<<"-1\n");
		rep(i,1,n)cout<<1<<" ";cout<<"\n";
		return;
	}

	rep(i,1,n)to[i] = n+1;
	memset(f,0,sizeof f);memset(pre,0,sizeof pre);
	for(int l=1,r;l<=n;l=r+1){
		r=l;while(r<n && b[r+1]==b[l])r++;
		to[r] = -1;
		if(r<n){
			if(b[r+1] != n+1)pre[b[r+1]] = r;
			rep(i,l,r-1)to[i] = b[r];
		}
	}
	int L = 1,R = b[1],ret = -1;
	while(L<=R){
		int mid = (L+R)>>1;
		if(chk(mid))ret = mid,L = mid+1;
		else R = mid-1;
	}
	if(ret==-1)return void(cout<<"-1\n");

	while(dq.size())dq.pop_back();
	rep(i,1,n){
		if(!pre[i] && i!=1 && !(i<=b[1] && i>b[1]-ret)){ 
			//必须接上
			if(dq.empty())return void(cout<<"-1\n");
			int u = dq.front(); 
			if(to[u] < i)return void(cout<<"-1\n");
			f[i] = u; dq.pop_front();
		}
		if(pre[i])f[i] = pre[i];
		if(to[i] != -1)dq.push_back(i);
	}
	if(dq.size()){
		int u = dq.front(); if(to[u] != n+1)return void(cout<<"-1\n");
	}
	//		
	int cur = 0;
	rep(i,1,n){
		if(!f[i])ans[i] = ++cur;
		else ans[i] = ans[f[i]];
	}
	rep(i,1,n)cout<<ans[i]<<" ";cout<<"\n";
}

int main(){
	ios::sync_with_stdio(false);cin.tie(0);

	cin>>T;
	while(T--)solve();

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 5060kb

input:

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

output:

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

result:

ok 233

Test #2:

score: -100
Wrong Answer
time: 954ms
memory: 7704kb

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