B. Spongebob and Joke

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/599/problem/B

Description

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 Input

3 3
3 2 1
1 2 3

Sample Output

Possible
3 2 1

HINT

题意

给你n个f[i],m个b[i],然后问你能不能找到m个a[i],使得b[i]=f[a[i]]

题解:

暴力存一下这个数在f[i]中出现了多少次,如果没出现就输出impossilbe,如果出现多次,就多解,如果出现一次就输出这个数。(注意impossible的优先级大于多解,这是hack点

注意ai可以等于aj

代码

#include<iostream>
#include<math.h>
#include<vector>
#include<stdio.h>
using namespace std;
#define maxn 100005
int a[maxn];
int f[maxn];
int b[maxn];
vector<int> Q[maxn];
int main()
{
int n,m;scanf("%d%d",&n,&m);
for(int i=;i<n;i++)
scanf("%d",&f[i]);
for(int i=;i<m;i++)
scanf("%d",&b[i]);
for(int i=;i<n;i++)
Q[f[i]].push_back(i);
int flag = ;
for(int i=;i<m;i++)
{
if(Q[b[i]].size()==)
return puts("Impossible");
if(Q[b[i]].size()>)
flag = ;
}
if(flag == )
return puts("Ambiguity");
puts("Possible");
for(int i=;i<m;i++)
printf("%d ",Q[b[i]][]+);
printf("\n");
}

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 per test 2 seconds memory limit per test 256 megabytes input standa ...

  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) A. Patrick and Shopping 水题

    A. Patrick and Shopping Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  6. Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题

    Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  ...

  7. Codeforces Round #290 (Div. 2) A. Fox And Snake 水题

    A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...

  8. Codeforces Round #322 (Div. 2) A. Vasya the Hipster 水题

    A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...

  9. Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题

    B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly liv ...

随机推荐

  1. 移动设备3G网站制作的detail

    说明一下,在此所说的移动设备前端开发是指针对高端智能手机(如Iphone.Android),所以需要对webkit内核的浏览器有一定的了解. 1.webkit内核中的一些私有的meta标签 <m ...

  2. MySQL基础之第7章 索引

    第7章 索引 MySQL中,所有的数据类型都可以被索引,包括普通索引,唯一性索引,全文索引,单列索引,多列索引和空间索引等. 7.1.索引简介 7.1.1.索引的含义和特点 BTREE索引,HASH索 ...

  3. POJ 1519 Digital Roots

    题意:求数根. 解法:一个数的数根就是mod9的值,0换成9,只是没想到给的是一个大数……只好先把每位都加起来再mod9…… 代码: #include<stdio.h> #include& ...

  4. C# 一次查询多表,填充DataSet并指定表名

    lhrhi 原文 NET 一次查询多表,填充DataSet并指定表名(DataSet指定DataTable名称的技巧) 现实中的场景,有时可能需要一次查询数据库中表张.在使用SqlDataAdapte ...

  5. STL六大组件之——容器知识大扫盲

    STL中的容器主要涉及顺序容器类型:vector.list.deque,顺序容器适配器类型:stack.queue.priority_queue.标准库中的容器分为顺序容器和关联容器.顺序容器(seq ...

  6. bzoj 1778 [Usaco2010 Hol]Dotp 驱逐猪猡(高斯消元)

    [题意] 炸弹从1开始运动,每次有P/Q的概率爆炸,否则等概率沿边移动,问在每个城市爆炸的概率. [思路] 设M表示移动一次后i->j的概率.Mk为移动k次后的概率,则有: Mk=M^k 设S= ...

  7. 在Ubuntu6.06 在搭建SVN服务器及在windows建立svn+ssh客户端 (续)

    接上篇.本篇主要介绍windows下建立svn+ssh客户端. 9.在windows下安装svn客户端,则需安装“TortoiseSVN”.“Puttygen”和“Pageant”    9.1.下载 ...

  8. [Hive - LanguageManual] VirtualColumns

    Virtual Columns Simple Examples Virtual Columns Hive 0.8.0 provides support for two virtual columns: ...

  9. Spark系列(七)Master中的资源调度

    资源调度 说明: Application的调度算法有两种,分别为spreadOutApps和非spreadOutApps spreadOutApps 在spark-submit脚本中,可以指定要多少个 ...

  10. redis在mac上的安装

    mac 上安装 redis 首先必须保证mac 已经安装 xcode. 因为make时要用到 Xcode 的command Tools . (1)下载 redis   http://redis.goo ...