学长讲座讲过的,代码也讲过了,然而,当时上课没来听,听代码的时候也一脸o((⊙﹏⊙))o
我的妈呀,语文不好是硬伤,看题意看了好久好久好久(死一死)。。。
数学+思维题,代码懂了,也能写出来,但是还是有一点不懂,明天继续。
感谢我的队友不嫌弃我是他的猪队友(可能他心里已经骂了无数次我是猪队友了_(:з」∠)_ )
Function
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 2021 Accepted Submission(s): 956
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.
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<bitset>
#include<set>
#include<map>
#include<time.h>
using namespace std;
typedef long long ll;
const int maxn=+;
const int mod=1e9+;
map<int,int>mp1,mp2;
map<int,int>::iterator it1,it2;
int a[maxn],b[maxn],vis[maxn];
int n,m;
void solve(int n,int *f,map<int,int> &mp)
{
memset(vis,,sizeof(vis));
int j,k;
for(int i=;i<n;i++)
{
j=i,k=;
while(!vis[j])
{
k++;
vis[j]=;
j=f[j];
}
if(k)
mp[k]++;
}
}
int main()
{
int kase=;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=;i<n;i++)
scanf("%d",&a[i]);
for(int i=;i<m;i++)
scanf("%d",&b[i]);
mp1.clear();
mp2.clear();
solve(n,a,mp1);
solve(m,b,mp2);
ll ans=;
for(it1=mp1.begin();it1!=mp1.end();it1++)
{
ll cnt=,x=it1->first,t=it1->second;
for(it2=mp2.begin();it2!=mp2.end();it2++)
{
int y=it2->first,num=it2->second;
if(x%y==)cnt=(cnt+y*num)%mod;
}
for(int i=;i<=t;i++)
ans=(ans*cnt)%mod;
}
printf("Case #%d: %lld\n",++kase,ans);
}
return ;
}
学长的代码比我队友的快_(:з」∠)_
溜了溜了。不想喝拿铁咖啡。
加油加油_(:з」∠)_