Permute K times

2024-08-27 12:04
文章标签 permute times

本文主要是介绍Permute K times,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

题目链接:Permute K times

首先我们考虑暴力的作法,就是将一个点走k步,最后所在的那个点即为所求,考虑数据范围显然不可以,因此我们可以采用倍增的写法去实现。每个点的步数转化成二进制形式去求,用st表。

代码:

#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
using namespace std;
const int inf = 0x3f3f3f3f3f3f3f3f;
const int N = 2e5+5;
int n,k;
int a[N],b[N];
int f[N][105];void solve(){cin>>n>>k;for(int i=1;i<=n;i++){cin>>f[i][0];}for(int i=1;i<=n;i++){cin>>a[i];b[i] = i;}for(int j=1;j<=63;j++){for(int i=1;i<=n;i++){f[i][j] = f[f[i][j-1]][j-1];}}int t = 0;while(k){if(k&1){for(int i=1;i<=n;i++){b[i] = f[b[i]][t];}}t++;k>>=1;}for(int i=1;i<=n;i++)cout<<a[b[i]]<<" ";cout<<"\n";}signed main(){ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);int T=1;while(T--){solve();}return 0;
}

这篇关于Permute K times的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1111617

相关文章

hadoop执行分词时报错:System times on machines may be out of sync. Check system time and time zones.

解决办法: 1、安装ntpdate工具 yum -y install ntp ntpdate 2、 设置系统时间与网络时间同步 ntpdate cn.pool.ntp.org

How to working with dates and times?

1.How to formatting date for display? Problem You need to format dates or time for output Solution Use the date command with a strftime format specification. 3. How to automating date Ranges?

pytorch中的维度变换操作性质大总结:view, reshape, transpose, permute

在深度学习中,张量的维度变换是很重要的操作。在pytorch中,有四个用于维度变换的函数,view, reshape, transpose, permute。其中view, reshape都用于改变张量的形状,transpose, permute都用于重新排列张量的维度,但它们的功能和使用场景有所不同,下面将进行详细介绍,并给出测试验证代码,经过全面的了解,我们才能知道如何正确的使用这四个函数。

$L(x) = (\frac{1}{2}x^HAx-b^Hx)^2, x\in C^{n \times 1}$是凸的

L ( x ) = ( 1 2 x H A x − b H x ) 2 , x ∈ C n × 1 L(x) = (\frac{1}{2}x^HAx-b^Hx)^2, x\in C^{n \times 1} L(x)=(21​xHAx−bHx)2,x∈Cn×1是凸的 已知: L ( x ) = ( 1 2 x H A x − b H x ) 2 , x ∈ C n × 1 L(x) =

10,09_维度变换,view、reshape,unsqueeze,Squeeze,expand,repeat,矩阵转置,transpose维度交换,permute,Broadcasting

1.9.Tensor维度变换 1.9.1.view、reshape 1.9.2.unsqueeze 1.9.3.Squeeze 1.9.4.expand 1.9.5.repeat 1.9.6.矩阵转置 1.9.7.transpose维度交换 1.9.8.permute 1.10.Broadcasting 1.9.Tensor维度变换 1.9.1.view、reshape 1.两者功能一样:将

why 3 tcp times

. TCP的三次握手最主要是防止已过期的连接再次传到被连接的主机。如果采用两次的话,会出现下面这种情况。比如是A机要连到B机,结果发送的连接信息由于某种原因没有到达B机;于是,A机又发了一次,结果这次B收到了,于是就发信息回来,两机就连接。传完东西后,断开。结果这时候,原先没有到达的连接信息突然又传到了B机,于是B机发信息给A,然后B机就以为和A连上了,这个时候B机就在等待A传东西过去。(此

ACM-ICPC 2018 焦作赛区网络预赛 H. String and Times—— 后缀自动机

Now you have a string consists of uppercase letters, two integers AA A and BB B. We call a substring wonderful substring when the times it appears in that string is between AA A and BB B ( A≤times≤BA

Delphi 报错 Type androidx.collection.ArraySet is defined multiple times

Delphi 11 建立一个新的 Multi-Device Application 编译成app的时候报错 报错信息 [PAClient Error] Error: E7688 Unable to execute '"E:\Program\Java\jdk1.8.0_301\bin\java.exe" -cp "e:\program\embarcadero\studio\22.0\bin\An

对keras.permute_dimensions和numpy.transpose空间维度转置过程的理解(Axis的理解)

keras.permute_dimensions和numpy.transpose,这两个函数的作用是对矩阵进行维度的转置, 具体请参考官方文档,这里只给出矩阵维度转置是怎么理解的? 1. 写在前面 今天遇到一个时间序列分析的任务,使用了Attention机制,看代码之后,有几个空间转置的过程其实有点懵。 所以通过查资料理解了一下空间维度转置,顺便理解了一下三维矩阵的沿着某一个轴的加法,我把自

加权中值滤波(WMF)——100+ Times Faster Weighted Median Filter-CVPR 2014论文解读

中值滤波 图像中值滤波是一种非线性的图像平滑技术,它将每一像素点的灰度值设置为该点某邻域窗口内的所有像素点灰度值的中值。中值滤波能有效去除椒盐噪声,参考http://blog.csdn.net/weixin_37720172/article/details/72627543如下图 加权中值滤波(weight median filter) 加权中值滤波是将窗口内的每一个像素都乘上一个相