Function

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 838    Accepted Submission(s): 369

Problem Description
You are given a permutation a from 0 to n−1 and a permutation b from 0 to m−1.

Define that the domain of function f is the set of integers from 0 to n−1, and the range of it is the set of integers from 0 to m−1.

Please calculate the quantity of different functions f satisfying that f(i)=bf(ai) for each i from 0 to n−1.

Two functions are different if and only if there exists at least one integer from 0 to n−1 mapped into different integers in these two functions.

The answer may be too large, so please output it in modulo 109+7.

 
Input
The input contains multiple test cases.

For each case:

The first line contains two numbers n, m. (1≤n≤100000,1≤m≤100000)

The second line contains n numbers, ranged from 0 to n−1, the i-th number of which represents ai−1.

The third line contains m numbers, ranged from 0 to m−1, the i-th number of which represents bi−1.

It is guaranteed that ∑n≤106, ∑m≤106.

 
Output
For each test case, output "Case #x: y" in one line (without quotes), where x indicates the case number starting from 1 and y denotes the answer of corresponding case.
 
Sample Input
3 2
1 0 2
0 1
3 4
2 0 1
0 2 3 1
 
Sample Output
Case #1: 4
Case #2: 4
 
比赛的时候想到了环这个东西,怀疑自己的思路,没有继续向下推了。果然专注度和练习的强度不够。继续加油。
 AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
ll a[],b[];
vector<ll> edgea,edgeb;
const ll mod=1e9+;
ll n,m;
void solve(int Case)
{
ll visa[],visb[];
memset(visb,,sizeof(visb));
memset(visa,,sizeof(visa));
for(int i=;i<m;i++)
{
if(visb[i]) continue;
ll ret=;
ll next_pos=b[i];
visb[next_pos]=;
while(next_pos!=i)
{ ret++;
next_pos=b[next_pos];
visb[next_pos]=;
}
// cout<<ret<<endl;
edgeb.push_back(ret);
}
ll f=;
for(int i=;i<n;i++)
{
if(visa[i]) continue;
ll ret=;
ll next_pos=a[i];
visa[next_pos]=;
while(next_pos!=i)
{
ret++;
next_pos=a[next_pos];
visa[next_pos]=;
}
ll temp=;
//cout<<ret<<endl;
for(int j=;j<edgeb.size();j++)
{
if(ret%edgeb[j]== || ret==edgeb[j]) temp=(temp+edgeb[j])%mod;
}
f=f*temp%mod;
}
printf("Case #%d: %d\n",Case,f);
}
int main()
{
cin.sync_with_stdio(false);
int Case=;
while(cin>>n>>m)
{
edgea.clear();
edgeb.clear();
for(int i=;i<n;i++) cin>>a[i];
for(int j=;j<m;j++) cin>>b[j];
solve(Case++);
}
return ;
}

2017多校赛 Function的更多相关文章

  1. 2017 浙大校赛 [Cloned]

    https://vjudge.net/contest/285902#overview A.Marjar Cola #include <bits/stdc++.h> using namesp ...

  2. 2017 Fzu校赛 [Cloned]

    A - Salty Fish 海边躺着一排咸鱼,一些有梦想的咸鱼成功翻身(然而没有什么卵用),一些则是继续当咸鱼.一个善良的渔夫想要帮这些咸鱼翻身,但是渔夫比较懒,所以只会从某只咸鱼开始,往一个方向, ...

  3. 2017校赛 问题 F: 懒人得多动脑

    题目描述 小D的家A和学校B都恰好在以点F为焦点的双曲线上,而小D每日所需的生活水源在一条平行该双曲线准线的直线上,设它的值为v.大家都知道,每天都是要喝水的,但是小D有点懒,他希望自己能在去上学或者 ...

  4. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  5. SCNU省选校赛第二场B题题解

    今晚的校赛又告一段落啦,终于"开斋"了! AC了两题,还算是满意的,英语还是硬伤. 来看题目吧! B. Array time limit per test 2 seconds me ...

  6. 2014上半年acm总结(1)(入门+校赛)

    大一下学期才开始了acm,不得不说有一点迟,但是acm确实使我的生活充实了很多,,不至于像以前一样经常没事干=  = 上学期的颓废使我的c语言学的渣的一笔..靠考前突击才基本掌握了语法 寒假突然醒悟, ...

  7. 2017河工大校赛补题CGH and 赛后小结

    网页设计课上实在无聊,便开始补题,发现比赛时候僵着的东西突然相通了不少 首先,"追妹"这题,两个队友讨论半天,分好多种情况最后放弃(可是我连题目都没看啊),今天看了之后试试是不是直 ...

  8. 2017CUIT校赛-线上赛

    2017Pwnhub杯-CUIT校赛 这是CUIT第十三届校赛啦,也是我参加的第一次校赛. 在被虐到崩溃的过程中也学到了一些东西. 这次比赛是从5.27早上十点打到5.28晚上十点,共36小时,中间睡 ...

  9. [蓝桥杯]2017蓝桥省赛B组题目及详解

    /*——————————————————————————————————————————————————————————— [结果填空题]T1 (分值:5) 题目:购物单 小明刚刚找到工作,老板人很好 ...

随机推荐

  1. 007-springboot 控制台中文乱码

    处理方式 1.FIle encoding 设置为UTF-8 2.-Dfile.encoding=UTF-8 配置tomcat 的的VM启动参数:-Dfile.encoding=UTF-8 3.idea ...

  2. JAVA 基础编程练习题42 【程序 42 求数字】

    42 [程序 42 求数字] 题目:809*??=800*??+9*??+1 其中??代表的两位数,8*??的结果为两位数,9*??的结果为 3 位数.求??代表的两位数,及 809*??后的结 果. ...

  3. TextView的封装和自定义

    实现的效果如下: #import <UIKit/UIKit.h> @interface CustomTextView : UITextView @property (nonatomic , ...

  4. 开发工具之GIT

    GIT WORKFLOW this readme created on 2019.07.28 by Suarez7988 这是一遍介绍git版本控制流程的中文说明,必须通篇阅读一下 https://g ...

  5. mfc中循环显示图片

    UINT CPalmIdentDlg::UpdateCImg(LPVOID p) { struct params *pa = (struct params*)p; int *imgarray = pa ...

  6. 【并行计算-CUDA开发】英伟达硬件解码器分析

    这篇文章主要分析 NVCUVID 提供的解码器,里面提到的所有的源文件都可以在英伟达的 nvenc_sdk 中找到. 解码器的代码分析 SDK 中的 sample 文件夹下的 NvTranscoder ...

  7. Qt——鼠标拖动缩放窗口源码

    #ifndef MOVEWIDGET_H #define MOVEWIDGET_H #include <QWidget> #include <QEvent> class Mov ...

  8. Ubuntu修改终端显示的主机名、用户名、目录不同颜色

    打开终端输入:echo $PS1 输入:gedit ~/.bashrc #定位到如下代码: if [ "$color_prompt" = yes ]; then PS1='${de ...

  9. spring中的BeanDefinitionRegistryPostProcessor

    spring中的BeanDefinitionRegistryPostProcessor是BeanFactoryPostProcessor的子接口,BeanFactoryPostProcessor的作用 ...

  10. css设置滚动条并显示或隐藏

    看效果,没有滚动条,超出div,开发中肯定不行. 有滚动条 最后就是想隐藏滚动条 代码 有滚动条并显示 <!DOCTYPE html> <html lang="en&quo ...