B. Spongebob and Joke
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

用哈希过的

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std; const int max1 = 101000; struct node {
int x, y;
}a[max1]; int b[max1];
int f[max1];
int a1[max1]; int main() {
memset(f, 0, sizeof(f));
memset(a, 0, sizeof(a));
memset(a1, 0, sizeof(a1));
memset(b, 0, sizeof(b));
for (int i = 0; i<max1; i++)
a[i].x = 0;
int n, m;
cin >> n>> m;
for (int i = 1; i<=n; i++) {
cin >> f[i];
a[f[i]].x ++ ;
a[f[i]].y = i;
}
for (int i = 1; i<=m; i++)
cin >> b[i];
int flag1 = 0;
int flag = 0;
int num = 1;
for (int i = 1; i<=m; i++) {
if (a[b[i]].x == 1) {
a1[num++] = a[b[i]].y;
}
else if (a[b[i]].x >= 2) {
a1[num++] = a[b[i]].y;
flag = 1;
}
else if (a[b[i]].x == 0) {
flag = 2;
break;
}
}
if (flag == 2)
cout << "Impossible" << endl;
else if (flag == 1)
cout << "Ambiguity" << endl;
else {
cout << "Possible" << endl;
for (int i = 1; i<num-1; i++)
cout << a1[i] << " " ;
cout << a1[num-1] << endl; }
return 0; }

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     While Patrick was gone shopping, Spongebob decided to play a little trick ...

  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 #332 (Div. 2)

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

  9. Codeforces Round #332 (Div. 2) C. Day at the Beach 线段树

    C. Day at the Beach Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/599/p ...

随机推荐

  1. CET——4 常用短语

    在网上看到的,先拔到自己这来,四级大大,求过!!!!

  2. jsp上的九个隐含对象

    首先说一说件jsp的原理.jsp被认为最经典的解释是  “嵌入了java 代码的html”. 在网上查了一些资料,和我本身对jsp的认识,总结如下: jsp本质上是一个servlet,继承自 当第一次 ...

  3. [置顶] xamarin android 布局尺寸了解

    为了使UI界面在不同大小的移动端显示器上能够正常显示,大家可能都知道使用sp作为字体大小的单位,dp作为其他元素长度的单位. 前几天看了一篇文章关于 App设计规范的,文章用心写的非常好,这里是链接  ...

  4. [Maximize ∑arr[i]*i of an Array]

    Given an array of N integers. Your task is to write a program to find the maximum value of ∑arr[i]*i ...

  5. 安装MongoDB步骤

    1.第一步是从官网下载匹配自己操作系统的安装文件或压缩文件: 2.随便找个文件夹先解压安装文件,然后在C盘根目录建立一个新文件夹命名为mongodb: 3.将打开刚刚安装的文件,将bin文件夹拷贝到C ...

  6. 了解数组中的队列方法,DOM中节点的一些操作

    队列的概念 栈是一种后进先出的结构,而队列是一种先进先出的结构.如银行排队,排在前面的人先办业务然后离开,后来的人站在最后.可以用队列的push()方法插入元素到队列的末尾,可以用shift()方法删 ...

  7. MySql监控优化

    MySQL监控   MySQL服务器硬件和OS(操作系统)调优:   1.有足够的物理内存,能将整个InnoDB文件加载到内存里 —— 如果访问的文件在内存里,而不是在磁盘上,InnoDB会快很多. ...

  8. 实现全屏轮播,并且轮播div中的文字盒子一直自动垂直居中

    效果如下: 直接上代码了: 说明:轮播图基于swiper.js,自行下载.css在最后 <!DOCTYPE html> <html lang="en"> & ...

  9. Django ORM详解

    ORM:(在django中,根据代码中的类自动生成数据库的表也叫--code first) ORM:Object Relational Mapping(关系对象映射) 我们写的类表示数据库中的表 我们 ...

  10. npm 项目更换目录后无法启动

    问题描述: 使用 Vue-cli 创建的项目,当文件移动到其他目录后,无法正常启动,报错信息如下: 分析原因: npm 项目,在安装依赖(node_modules)的时候,会记录当前的文件路径.当路径 ...