QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#152621#6680. HeaprsjWA 412ms6576kbC++141.4kb2023-08-28 15:10:572023-08-28 15:10:57

Judging History

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

  • [2023-08-28 15:10:57]
  • 评测
  • 测评结果:WA
  • 用时:412ms
  • 内存:6576kb
  • [2023-08-28 15:10:57]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
int ans[N];
int v[N],a[N],b[N];
int t[N];
void insert(int i,int x,int p) {
	t[i]=x;
	while(i>1) {
		if(!p&&t[i/2]<=t[i]) break;
		else if(p&&t[i/2]>=t[i]) break;
		swap(t[i/2],t[i]);
		i/=2;
	}
}
void get() {
	int n,i;
	cin>>n;
	for(i=1;i<=n;i++) cin>>v[i];
	for(i=1;i<=n;i++) cin>>a[i],b[i]=a[i];
	for(i=1;i<=n;i++) ans[i]=-1;
	for(i=n;i>=1;i--) {
		int j=i;
		int o=v[i];
		int la=0;
		int c=0,d=1e9,ok=0;
		while(j>=1) {
			if(a[j]==o) {
				swap(la,a[j]);
				swap(la,a[i]);
				if(d==1e9) ans[i]=-1;
				else if(o>c) ans[i]=1;
				else if(o<d) ans[i]=0;
				else {
					cout<<"Impossible\n";
					return ;
				} 
				ok=1;
				break;
			}
			c=max(c,a[j]),d=min(d,a[j]);
			swap(la,a[j]);
			j/=2;
		}
		if(!ok) { cout<<"Impossible\n"; return ; }
		if(ans[i]==-1) {
			if(j==1) ans[i]=0;
			else {
				if(a[j/2]>a[j]) ans[i]=1;
				else ans[i]=0;
			}
		}
		if(j!=1) {
			if(ans[i]==1&&a[j/2]<a[j]) { cout<<"Impossible\n"; return ; }
			if(ans[i]==0&&a[j/2]>a[j]) { cout<<"Impossible\n"; return ; }
		}
	}
	for(i=1;i<=n;i++) cout<<ans[i];
	for(i=1;i<=n;i++) insert(i,v[i],ans[i]);
	for(i=1;i<=n;i++) if(t[i]!=b[i]) { cout<<"Impossible\n"; return ; }
	cout<<endl;
}
int main() {
	// freopen("3.in","r",stdin);
	int T; cin>>T;
	while(T--) get();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
4
2 3 1 4
4 1 3 2
5
4 5 1 2 3
3 4 1 5 2
3
1 1 2
2 1 1

output:

0101
Impossible
001

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 412ms
memory: 6576kb

input:

1118
77
210555 375330 669075 785279 194474 310626 830710 886719 102133 426324 41900 971872 167203 702222 230534 112350 673156 358623 886831 72864 818751 367894 842740 531878 818794 131219 412128 104469 70427 658494 72060 768735 915294 161365 91671 451974 121863 498890 408674 670274 875754 967228 518...

output:

00010111111010100000101000101001111010010000100101001001001000001100111100010
000001011011010
01011011111111010011000100101100101010000110111000001100
0
Impossible
01
011001000010010011110011010100110010111110101000010001101101000011
Impossible
Impossible
010001111
0010000101001000000100110111100111...

result:

wrong answer 287th lines differ - expected: 'Impossible', found: '00100000100000110011101Impossible'