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. kotlin之null值安全性

    var a: String =null // 编译错误 var a: String? =null // 编译通过 要允许null值, 需要将变量声明为可为null的字符串类型:String? fun ...

  2. 阶段5 3.微服务项目【学成在线】_day03 CMS页面管理开发_08-新增页面-前端-Api调用

    表单数据提交到后台 export const page_add = paramas => { return http.requestPost(apiUrl+'/cms/page/add',par ...

  3. Qt编写安防视频监控系统6-面板开关

    一.前言 面板开关功能是整个系统最人性化的功能之一,可以对主界面中左侧右侧的各个小面板进行显示和隐藏,当隐藏的时候,另外的同级面板自动拉伸填充,这样就不会显得空洞,直接在每个面板的右上角提供了关闭按钮 ...

  4. mybatis plus foreach 的用法

    一: foreach 用于 select * from tablename where colname in (A,B,C……); 1:service 层: Set<String> tea ...

  5. maven编译正常,运行报错:中没有主清单属性

    在pom.xml添加插件 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId&g ...

  6. Flutter 底部的renderflex溢出

    一开始直接使用Scaffold布局,body:new Column  然后模拟器会提示捕获异常: 然后百度了一下Flutter的溢出问题,发现解决办法是使用SingleChildScrollView包 ...

  7. 46.前端html5标签学习

    HTML:TR  TD  TH  OL  UL  LI 这几个标签要区别 一.什么是HTML: 超文本标记语言(HyperText Markup Language),标准通用标记语言下的一个应用: 是 ...

  8. 36.HTTP协议

    HTTP简介 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的传送 ...

  9. react新特性hook

    一.hook示例.   import React, { useState } from 'react'; function Example() { // 声明一个叫 “count” 的 state 变 ...

  10. js延迟2秒执行事件

    有时候,我们在做修改回显数据时,就需要默认触发一些事件,但是由于数据没有很快从服务器中取回,所以就有延迟执行js事件 setTimeout(function () { // 这里就是处理的事件 }, ...