https://ac.nowcoder.com/acm/contest/5667/J

题目大意:给你一个置换A,使得置换P^k=A,让你求出置换P。

思路:我们根据置换A再置换z次,那么就等于置换p 置换z*k次,如果z*k%len==0,那么将会回到单位序列,那我们再置换一次则是置换p,即是z*k%len==1,则z是k在模len下的逆元。我们求出A的每一个循环,再求出z,就可以求出该循环内的对应位置。因为满足gcd(len,k)==1,那我们可以直接在循环中将i后移z个位置。

#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <cstdlib>
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define FILL(a,b) (memset(a,b,sizeof(a)))
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(a) ((a)&-(a))
#define ios std::ios::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);
#define fi first
#define sc second
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define ac cout<<ans<<"\n"
#define pb push_back
#define endl '\n'
using namespace std;
typedef long long  ll;
typedef unsigned long long  ull;
typedef pair<ll,ll> pii;
int dx[4]= {-1,1,0,0},dy[4]= {0,0,1,-1};
const ll mod=998244353;
const ll N =5e5+10;
const ll M =250000;
const double eps = 1e-4;
//const double pi=acos(-1);
ll re(){ll x;scanf("%lld",&x);return x;
}
ll n,k;
int a[N];
int vis[N];
int b[N];
vector<int> g;
void gg(){ll l=g.size(),p=0;for(ll i=0;i<l;i++) if((i*k)%l==1) {p=i;break;}for(ll i=0;i<l;i++) b[g[i]]=g[(i+p)%l];
}
void slove(){n=re(),k=re();for(int i=1;i<=n;i++) a[i]=re();for(int i=1;i<=n;i++){if(vis[i]) continue;int x=i;g.clear();while(!vis[x]){vis[x]=1;g.pb(x);x=a[x];}gg();}for(int i=1;i<=n;i++) printf("%d ",b[i]);
}
int main(){int t=1;// t=re();while(t--) slove();return 0;
}

2020牛客暑期多校训练营(第二场)Just Shuffle相关推荐

  1. 2020牛客暑期多校训练营(第九场)E题 Groundhog Chasing Death

    题意 计算 ∏ i = a b ∏ j = c d g c d ( x i , y j ) \prod_{i=a}^{b}\prod_{j=c}^{d}gcd(x^i,y^j) i=a∏b​j=c∏d ...

  2. 2020牛客暑期多校训练营(第二场)

    2020牛客暑期多校训练营(第二场) 最烦英语题 文章目录 A All with Pairs B Boundary C Cover the Tree D Duration E Exclusive OR ...

  3. 2020牛客暑期多校训练营(第六场)

    2020牛客暑期多校训练营(第六场) 额,睡了一下午,直接错过了比赛... 文章目录 A African Sort 题意: 题解: 代码: B Binary Vector C Combination ...

  4. 2020牛客暑期多校训练营(第四场)

    2020牛客暑期多校训练营(第四场) 这场属实有点难受 文章目录 A Ancient Distance B Basic Gcd Problem 题目 代码: C Count New String D ...

  5. 2020牛客暑期多校训练营(第一场)

    文章目录 A B-Suffix Array B Infinite Tree C Domino D Quadratic Form E Counting Spanning Trees F Infinite ...

  6. 2020牛客暑期多校训练营(第七场)J.Pointer Analysis

    2020牛客暑期多校训练营(第七场)J.Pointer Analysis 题目链接 题目描述 Pointer analysis, which aims to figure out which obje ...

  7. 2020牛客暑期多校训练营(第三场)A.Clam and Fish

    2020牛客暑期多校训练营(第三场)A.Clam and Fish 题目链接 题目描述 There is a fishing game as following: The game contains ...

  8. 2020牛客暑期多校训练营(第五场)——E Bogo Sort

    2020牛客暑期多校训练营(第五场)--E Bogo Sort 题目描述 Today Tonnnny the monkey learned a new algorithm called Bogo So ...

  9. E Groundhog Chasing Death(2020牛客暑期多校训练营(第九场))(思维+费马小定理+质因子分解)

    E Groundhog Chasing Death(2020牛客暑期多校训练营(第九场))(思维+费马小定理+质因子分解) 链接:https://ac.nowcoder.com/acm/contest ...

  10. 2020牛客暑期多校训练营(第一场)A B-Suffix Array(后缀数组,思维)

    链接:https://ac.nowcoder.com/acm/contest/5666/A 来源:牛客网 题目描述 The BBB-function B(t1t2-tk)=b1b2-bkB(t_1 t ...

最新文章

  1. runtime自动归档/解档
  2. python程序的控制结构
  3. 攻击 xxs_“吃鸡”又出现1招炸队友不受惩罚,xxs乐坏了,请别手误打载具
  4. SAFESEH 映像的模块不安全
  5. 计算机网络之网络层:10、IP组播、IGMP协议、组播路由选择协议
  6. CentOS7安装Mono和MonoDevelop
  7. python全局变量可以改变吗_在Python中避免我的全局变量,我有几个函数可以改变一个变量...
  8. 微信小程序富文本去除首行缩进样式_小程序富文本处理wxParse
  9. Java单元测试用例的编写
  10. 【每日一题】(D0723)strcpy 智能指针
  11. windows添加hosts
  12. 关于冯诺依曼结构、哈佛结构、增强型的哈佛结构
  13. C# 实现类似SMSS的执行脚本的功能
  14. 国密SSL通信协议详细介绍与抓包分析
  15. 迅雷同时下载的人数越多,BT下载越快的奥秘——另辟蹊径的P2P应用
  16. 致敬Gif之父,使用Java生成Gif图片
  17. 输入被除数和除数,求商。
  18. 刷屏了!高校硕士毕业论文研究“董明珠的自恋对企业的影响” 网友:这也行?...
  19. Android Webview打开第三方APP(高德地图 淘宝 QQ等等)
  20. c#未能加载基类System

热门文章

  1. 如何保持纯洁男女关系……
  2. 我的电脑不联网,很安全!黑客:你还有风扇呢
  3. 12星座程序员写代码
  4. 推荐系统相关算法(1):SVD
  5. 电脑重新分区扩大c盘_两种方法,给电脑C盘增加10G的容量,电脑焕然一新
  6. linux配置ip地址 routes,CentOS 7 设置网络IP地址(示例代码)
  7. myclipes 配置php,myclipse使用技巧
  8. android 开启一个定时线程_Android 定时任务刷新的多种实现方式
  9. php 数据导出到excel文件,PHP导出数据到excel文件
  10. java jdbc分页_使用JDBC进行分页查询