CodeForces 599B Spongebob and Joke(区间映射)

B. Spongebob and Joke

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

While Patrick wasgone shopping, Spongebob decided to play a little trick on his friend. Thenaughty Sponge browsed through Patrick's personal stuff and found a sequencea1, a2, ..., amof length m,consisting of integers from1 ton,not necessarily distinct. Then he picked some sequencef1, f2, ..., fnof length nand for each numberaigot numberbi = fai.To finish the prank he erased the initial sequence ai.

It's hard to expresshow sad Patrick was when he returned home from shopping! We will just say thatSpongebob immediately got really sorry about what he has done and he is nowtrying to restore the original sequence. Help him do this or determine thatthis is impossible.

Input

The first line of theinput contains two integersn andm(1 ≤ n, m ≤ 100 000) —the lengths of sequencesfiandbirespectively.

The second linecontains nintegers, determining sequencef1, f2, ..., fn(1 ≤ fi ≤ n).

The last linecontains mintegers, determining sequenceb1, b2, ..., bm(1 ≤ bi ≤ n).

Output

Print "Possible"if there is exactly one sequenceai,such thatbi = faifor all ifrom1tom.Then printmintegersa1, a2, ..., am.

If there are multiplesuitable sequencesai,print "Ambiguity".

If Spongebob has made a mistake in hiscalculations and no suitable sequenceaiexists, print "Impossible".

Examples

Input

3 3
3 2 1
1 2 3

Output

Possible
3 2 1

Input

3 3
1 1 1
1 1 1

Output

Ambiguity

Input

3 3
1 2 1
3 3 3

Output

Impossible

Note

In the first sample 3is replaced by1and vice versa, while2 never changes. Theanswer exists and is unique.

In the second sampleall numbers are replaced by1, so it is impossibleto unambiguously restore the original sequence.

In the third sample fi ≠ 3for all i,so no sequenceaitransforms into suchbiand we can say for sure that Spongebob has made a mistake.

 

题意:

有时间再写。


参考代码:

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#define MYDD 110300

using namespace std;

int main() {
	int n,m,val,A[MYDD],pos[MYDD],bol[MYDD],res[MYDD];
	scanf("%d %d",&n,&m);

	for(int i=1; i<=n; i++) {
		scanf("%d",&val);
		if (pos[val])
			bol[val]=true;
		else
			pos[val]=i;
	}

	for(int i=1; i<=m; i++) {
		scanf("%d",&A[i]);
		if (!pos[A[i]])
			return printf("Impossible\n"),0;
	}

	for(int i=1; i<=m; i++) {
		val=A[i];
		if (bol[val])
			return printf("Ambiguity\n"),0;
		res[i]=pos[val];
	}

	printf("Possible\n");
	for(int i=1; i<=m; i++)
		printf("%d ",res[i]);
	puts("");
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值