2017多校赛 Function
Function
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 838 Accepted Submission(s): 369
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.
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.
1 0 2
0 1
3 4
2 0 1
0 2 3 1
#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的更多相关文章
- 2017 浙大校赛 [Cloned]
https://vjudge.net/contest/285902#overview A.Marjar Cola #include <bits/stdc++.h> using namesp ...
- 2017 Fzu校赛 [Cloned]
A - Salty Fish 海边躺着一排咸鱼,一些有梦想的咸鱼成功翻身(然而没有什么卵用),一些则是继续当咸鱼.一个善良的渔夫想要帮这些咸鱼翻身,但是渔夫比较懒,所以只会从某只咸鱼开始,往一个方向, ...
- 2017校赛 问题 F: 懒人得多动脑
题目描述 小D的家A和学校B都恰好在以点F为焦点的双曲线上,而小D每日所需的生活水源在一条平行该双曲线准线的直线上,设它的值为v.大家都知道,每天都是要喝水的,但是小D有点懒,他希望自己能在去上学或者 ...
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- SCNU省选校赛第二场B题题解
今晚的校赛又告一段落啦,终于"开斋"了! AC了两题,还算是满意的,英语还是硬伤. 来看题目吧! B. Array time limit per test 2 seconds me ...
- 2014上半年acm总结(1)(入门+校赛)
大一下学期才开始了acm,不得不说有一点迟,但是acm确实使我的生活充实了很多,,不至于像以前一样经常没事干= = 上学期的颓废使我的c语言学的渣的一笔..靠考前突击才基本掌握了语法 寒假突然醒悟, ...
- 2017河工大校赛补题CGH and 赛后小结
网页设计课上实在无聊,便开始补题,发现比赛时候僵着的东西突然相通了不少 首先,"追妹"这题,两个队友讨论半天,分好多种情况最后放弃(可是我连题目都没看啊),今天看了之后试试是不是直 ...
- 2017CUIT校赛-线上赛
2017Pwnhub杯-CUIT校赛 这是CUIT第十三届校赛啦,也是我参加的第一次校赛. 在被虐到崩溃的过程中也学到了一些东西. 这次比赛是从5.27早上十点打到5.28晚上十点,共36小时,中间睡 ...
- [蓝桥杯]2017蓝桥省赛B组题目及详解
/*——————————————————————————————————————————————————————————— [结果填空题]T1 (分值:5) 题目:购物单 小明刚刚找到工作,老板人很好 ...
随机推荐
- vs.net2017在编辑的wpf的xaml文件引用本程序集下的类提示“找不到”
local对应就是当前exe程序下的类,会提示“...命令空间...找不到...” 因为我调整过生成的,于是尝试调回来anyCPU 问题解决. 看了一下vs.net2017的所在目录"C:\ ...
- 从UDP的”连接性”说起–告知你不为人知的UDP
原文地址:http://bbs.utest.qq.com/?p=631 很早就计划写篇关于UDP的文章,尽管UDP协议远没TCP协议那么庞大.复杂,但是,要想将UDP描述清楚,用好UDP却要比TCP难 ...
- insmod mknod
insmod module 會在 /proc/devices/ 下產生 major number 及 device name ---------------------------- mknod 會使 ...
- 01背包---P2392 kkksc03考前临时抱佛脚
P2392 kkksc03考前临时抱佛脚 题解 01背包,类似于这道题,相似度99.999999%: 01-背包 P2663 越越的组队 一共有4科,每科的时间独立,然后每一科做一遍 P2663越 ...
- mac安装mysql数据库及配置环境变量
mac安装mysql数据库及配置环境变量 mac安装mysql数据库及配置环境变量 原文文链接:https://blog.csdn.net/qq_36004521/article/details/80 ...
- 使用.NET Framework开发IIS 7.0模块和处理程序拦截请求实现跳转
扩展IIS的两种方法:模块与处理程序. 模块,类似于以前的IIS版本中的ISAPI筛选器,它参与每个请求处理.IIS中一些现成的模块包括身份验证模块(用于处理请求的身份验证状态),压缩模块(用于压缩返 ...
- Web Service 实例基于Socket创建Web服务
ServerSocket服务器端代码如下: public static void main(String[] args) throws IOException { // 1:建立服务器端的tcp so ...
- 关于一个GPGPU优化中Bank Conflict的讨论
出自OpenGPU: 关于去除bank conflict的一个例子程序
- flask的post,get请求及获取不同格式的参数
flask的post,get请求及获取不同格式的参数 1 获取不同格式参数 1.0 获取json参数 Demo from flask import Flask, request, jsonify ap ...
- ubuntu Tensorflow object detection API 开发环境搭建
https://blog.csdn.net/dy_guox/article/details/79111949 luo@luo-All-Series:~$ luo@luo-All-Series:~$ s ...