B. Spongebob and Joke
 
 

While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. The naughty Sponge browsed through Patrick's personal stuff and found a sequence a1, a2, ..., am of length m, consisting of integers from 1 to n, not necessarily distinct. Then he picked some sequence f1, f2, ..., fn of length n and for each number ai got number bi = fai. To finish the prank he erased the initial sequence ai.

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

Input

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100 000) — the lengths of sequences fi and bi respectively.

The second line contains n integers, determining sequence f1, f2, ..., fn (1 ≤ fi ≤ n).

The last line contains m integers, determining sequence b1, b2, ..., bm (1 ≤ bi ≤ n).

Output

Print "Possible" if there is exactly one sequence ai, such that bi = fai for all i from 1 to m. Then print m integers a1, a2, ..., am.

If there are multiple suitable sequences ai, print "Ambiguity".

If Spongebob has made a mistake in his calculations and no suitable sequence ai exists, print "Impossible".

Sample test(s)
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 3 is replaced by 1 and vice versa, while 2 never changes. The answer exists and is unique.

In the second sample all numbers are replaced by 1, so it is impossible to unambiguously restore the original sequence.

In the third sample fi ≠ 3 for all i, so no sequence ai transforms into such bi and we can say for sure that Spongebob has made a mistake.

 题意:

给你b数组,f数组  ,构造出a数组满足:   bi = fai.  有多组情况输出Ambiguity,一组情况输出它,没有输出impossblie

题解:

我们标记f数组,计数找唯一就是了

//
#include<bits/stdc++.h>
using namespace std; typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){
if(ch=='-')f=-;ch=getchar();
}
while(ch>=''&&ch<=''){
x=x*+ch-'';ch=getchar();
}return x*f;
}
//****************************************
const int N=+;
#define maxn 100000+5 int H[N],ans[N],c[N],b[N],f[N];
int main() { int n=read(),m=read();
for(int i=;i<=n;i++) {
scanf("%d",&f[i]);
H[f[i]]++;
c[f[i]]=i;
}
for(int i=;i<=m;i++) {
scanf("%d",&b[i]);
}int f=,siz=,cool=;
for(int i=;i<=m;i++) {
if(H[b[i]]>) f=;
if(H[b[i]]==&&!f) {ans[++siz]=c[b[i]];}
if(H[b[i]]==) cool=;
}
if(cool) {
cout<<"Impossible"<<endl;
}
else if(f) {
cout<<"Ambiguity"<<endl;
}
else {
cout<<"Possible"<<endl;
for(int i=;i<=siz;i+=) {
cout<<ans[i]<<" ";
}
}
return ;
}

代码

Codeforces Round #332 (Div. 2) B. Spongebob and Joke 模拟的更多相关文章

  1. Codeforces Round #332 (Div. 2) B. Spongebob and Joke 水题

    B. Spongebob and Joke Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/599 ...

  2. Codeforces Round #332 (Div. 2)_B. Spongebob and Joke

    B. Spongebob and Joke time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  3. Codeforces Round #332 (Div. 2)B. Spongebob and Joke

    B. Spongebob and Joke time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  4. Codeforces Round #332 (Div. 二) B. Spongebob and Joke

    Description While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. ...

  5. Codeforces Round #332 (Div. 2) D. Spongebob and Squares 数学题枚举

    D. Spongebob and Squares Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...

  6. Codeforces Round #332 (Div. 2) D. Spongebob and Squares(枚举)

    http://codeforces.com/problemset/problem/599/D 题意:给出一个数x,问你有多少个n*m的网格中有x个正方形,输出n和m的值. 思路: 易得公式为:$\su ...

  7. Codeforces Round #332 (Div. 2)D. Spongebob and Squares 数学

    D. Spongebob and Squares   Spongebob is already tired trying to reason his weird actions and calcula ...

  8. Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)

    Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...

  9. Codeforces Round #332 (Div. 2)

    水 A - Patrick and Shopping #include <bits/stdc++.h> using namespace std; int main(void) { int ...

随机推荐

  1. MVC系列学习(十二)-服务端的验证

    在前一讲,提到过,客户端的东西永远可以造假,所以我们还要在服务端进行验证 注意:先加载表单,后添加js文件,才能有效:而先加载js,后添加表单,是没有效果的 1.视图与Model中的代码如下 2.一张 ...

  2. Ubuntu 系统的常用快捷键

    Ubuntu操作基本快捷键 ibus-setup :设置系统输入法 scp filename username@serverIp:/home/xxx/xxx/filename   回车输入该usern ...

  3. Java—解压zip文件

    import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import ja ...

  4. UDP网络程序实例

    根据前面所讲的网络编程的基础知识,以及UDP网络编程的特点,下面创建一个广播数据报程序.广播数据报是一种较新的技术,类似于电台广播,广播电台需要在指定的波段和频率上广播信息,收听者也要将收音机调到指定 ...

  5. CSS——精灵图与背景图片定位

    精灵图产生背景: 1.网页上的每张图像都需要向服务器发送一次请求才能展现给用户.2.网页上的图像过多时,服务器就会频繁地接受和发送请求,大大降低页面的加载速度.为了有效地减少服务器接受和发送请求的次数 ...

  6. 常用MySQL语句整合

    常用MySQL语句整合 1. MySQL服务的配置和使用 修改MySQL管理员的口令:mysqladmin –u root password 密码字符串 如:mysqldmin –u root pas ...

  7. linux启动时开启screen

    编辑/etc/rc.local 添加 su - ubuntu -c 'screen -dmS ss zserver -p /etc/config'

  8. 【sqli-labs】 less50 GET -Error based -Order By Clause -numeric -Stacked injection(GET型基于错误的整型Order By从句堆叠注入)

    报错没有关闭,直接可以用UpdateXml函数 http://192.168.136.128/sqli-labs-master/Less-50/?sort=1 and UpdateXml(1,conc ...

  9. Android Binder机制(一) Binder的设计和框架

    这是关于Android中Binder机制的一系列纯技术贴.花了一个多礼拜的时间,才终于将其整理完毕.行文于此,以做记录:也是将自己所得与大家分享.和以往一样,介绍Binder时,先讲解框架,然后再从设 ...

  10. Memcached 在Linux上的安装

    1.安装libevent wget https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libeve ...