Language: C++

#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

#define LL long long
#define fgx cerr<<"--------------"<<endl;
#define dgx cerr<<"=============="<<endl;

inline int read(){
	int x=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
const int MAXN = 100010;
const int INF = 2147483600;

int N,K; int b[MAXN+1],c[MAXN+1]; bool vis[MAXN+1]; int sta[MAXN+1],top;
struct data{
	int a[MAXN+1];
	inline void Pow(LL k){
		for(int i=1;i<=N;i++) vis[i]=0;
		for(int i=1;i<=N;i++){
			if(vis[i]) continue;
			int nw=i; top=0; while(!vis[a[nw]]) sta[top++]=nw=a[nw],vis[nw]=1;
			nw=k%top; for(int j=0;j<top;j++){
				b[sta[j]]=sta[nw],++nw; if(nw>=top) nw-=top; }
		} for(int i=1;i<=N;i++) a[i]=b[i];
		return ;
	}
}An[9];
data operator * (const data p,const data q){
	data nw; for(int i=1;i<=N;i++) nw.a[i]=p.a[q.a[i]]; return nw;
}
inline data Inv(data n){
	data ret; for(int i=1;i<=N;i++) b[n.a[i]]=i;
	for(int i=1;i<=N;i++) ret.a[i]=b[i]; return ret;
}

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	N=read(); K=read();
	for(int i=1;i<=N;i++) An[1].a[i]=read();
	for(int i=1;i<=N;i++) An[2].a[i]=read();
	for(int i=3;i<=7;i++) An[i]=An[i-1]*Inv(An[i-2]);
	int m=(K-1)/6,n=(K-1)%6+1;
	data p,q; p=An[1]; q=An[2];
	data A; A=q; A=A*Inv(p); A=A*Inv(q); A=A*p;
	data ivA; ivA=Inv(A);
	A.Pow(m); ivA.Pow(m);
	data ret; ret=A; ret=ret*An[n]; ret=ret*ivA;
	for(int i=1;i<=N;i++) printf("%d ",ret.a[i]);
	return 0;
}




Compiler output:
a.cc:36:1: error: reference to 'data' is ambiguous
   36 | data operator * (const data p,const data q){
      | ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:23:8: note:                 'struct data'
   23 | struct data{
      |        ^~~~
a.cc:39:8: error: reference to 'data' is ambiguous
   39 | inline data Inv(data n){
      |        ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:23:8: note:                 'struct data'
   23 | struct data{
      |        ^~~~
a.cc: In function 'int main()':
a.cc:50:45: error: 'Inv' was not declared in this scope
   50 |         for(int i=3;i<=7;i++) An[i]=An[i-1]*Inv(An[i-2]);
      |                                             ^~~
a.cc:52:9: error: reference to 'data' is ambiguous
   52 |         data p,q; p=An[1]; q=An[2];
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:23:8: note:                 'struct data'
   23 | struct data{
      |        ^~~~
a.cc:52:19: error: 'p' was not declared in this scope
   52 |         data p,q; p=An[1]; q=An[2];
      |                   ^
a.cc:52:28: error: 'q' was not declared in this scope
   52 |         data p,q; p=An[1]; q=An[2];
      |                            ^
a.cc:53:9: error: reference to 'data' is ambiguous
   53 |         data A; A=q; A=A*Inv(p); A=A*Inv(q); A=A*p;
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:23:8: note:                 'struct data'
   23 | struct data{
      |        ^~~~
a.cc:53:17: error: 'A' was not declared in this scope
   53 |         data A; A=q; A=A*Inv(p); A=A*Inv(q); A=A*p;
      |                 ^
a.cc:53:26: error: 'Inv' was not declared in this scope
   53 |         data A; A=q; A=A*Inv(p); A=A*Inv(q); A=A*p;
      |                          ^~~
a.cc:54:9: error: reference to 'data' is ambiguous
   54 |         data ivA; ivA=Inv(A);
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:23:8: note:                 'struct data'
   23 | struct data{
      |        ^~~~
a.cc:54:19: error: 'ivA' was not declared in this scope
   54 |         data ivA; ivA=Inv(A);
      |                   ^~~
a.cc:56:9: error: reference to 'data' is ambiguous
   56 |         data ret; ret=A; ret=ret*An[n]; ret=ret*ivA;
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:23:8: note:                 'struct data'
   23 | struct data{
      |        ^~~~
a.cc:56:19: error: 'ret' was not declared in this scope
   56 |         data ret; ret=A; ret=ret*An[n]; ret=ret*ivA;
      |                   ^~~