Submission #50960547


Source Code Expand

// LUOGU_RID: 149641945
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=1e5+5,M=4e3+5,K=1000+5,mod=1e9+7,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(263082);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#ifdef LOCAL
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
	#else 
	#define gdb(...) void()
	#endif
}using namespace Debug;
int n,k;
using per=array<int,N>;
per operator *(const per &A,const per &B){
	per C;for(int i=1;i<=n;i++) C[i]=B[A[i]];
	return C;
}
per inv(per A){
	per B;for(int i=1;i<=n;i++) B[A[i]]=i;
	return B;
}
per p,q;
per mpow(per x,int y){
	per ans;iota(ans.begin(),ans.end(),0);
	while(y) y&1&&(ans=ans*x,0),y>>=1,x=x*x;return ans;
}
void Solve(){
	int i,j;scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++) scanf("%d",&p[i]);
	for(i=1;i<=n;i++) scanf("%d",&q[i]);
	per a1=mpow(inv(q)*p*q*inv(p),(k-1)/6),a2=mpow(p*inv(q)*inv(p)*q,(k-1)/6);
	if(k%6==1) a1=a1*p;
	if(k%6==2) a1=a1*q;
	if(k%6==3) a1=a1*inv(p)*q;
	if(k%6==4) a1=a1*inv(q)*inv(p)*q;
	if(k%6==5) a1=a1*inv(q)*p*inv(q)*inv(p)*q;
	if(k%6==0) a1=a1*inv(q)*p*p*inv(q)*inv(p)*q;
	a1=a1*a2;
	for(int i=1;i<=n;i++) printf("%d ",a1[i]);
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Submission Info

Submission Time
Task D - A Sequence of Permutations
User fangxintong
Language C++ 20 (gcc 12.2)
Score 1000
Code Size 1895 Byte
Status AC
Exec Time 33 ms
Memory 10624 KiB

Compile Error

Main.cpp: In function ‘per mpow(per, int)’:
Main.cpp:41:9: warning: this ‘while’ clause does not guard... [-Wmisleading-indentation]
   41 |         while(y) y&1&&(ans=ans*x,0),y>>=1,x=x*x;return ans;
      |         ^~~~~
Main.cpp:41:49: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘while’
   41 |         while(y) y&1&&(ans=ans*x,0),y>>=1,x=x*x;return ans;
      |                                                 ^~~~~~
Main.cpp: In function ‘void Solve()’:
Main.cpp:44:15: warning: unused variable ‘j’ [-Wunused-variable]
   44 |         int i,j;scanf("%d%d",&n,&k);
      |               ^
Main.cpp:44:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   44 |         int i,j;scanf("%d%d",&n,&k);
      |                 ~~~~~^~~~~~~~~~~~~~
Main.cpp:45:32: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   45 |         for(i=1;i<=n;i++) scanf("%d",&p[i]);
      |                           ~~~~~^~~~~~~~~~~~
Main.cpp:46:32: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   46 |         for(i=1;i<=n;i++) scanf("%d",&q[i]);
      |                           ~~~~~^~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1000 / 1000
Status
AC × 3
AC × 43
Set Name Test Cases
Sample sample01.txt, sample02.txt, sample03.txt
All sample01.txt, sample02.txt, sample03.txt, in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, in35.txt, in36.txt, in37.txt, sample01.txt, sample02.txt, sample03.txt
Case Name Status Exec Time Memory
in01.txt AC 5 ms 9752 KiB
in02.txt AC 6 ms 9684 KiB
in03.txt AC 7 ms 9784 KiB
in04.txt AC 7 ms 9636 KiB
in05.txt AC 6 ms 9772 KiB
in06.txt AC 5 ms 9640 KiB
in07.txt AC 5 ms 9828 KiB
in08.txt AC 6 ms 9836 KiB
in09.txt AC 7 ms 9680 KiB
in10.txt AC 7 ms 9808 KiB
in11.txt AC 27 ms 10328 KiB
in12.txt AC 30 ms 10388 KiB
in13.txt AC 27 ms 10436 KiB
in14.txt AC 29 ms 10572 KiB
in15.txt AC 28 ms 10300 KiB
in16.txt AC 27 ms 10300 KiB
in17.txt AC 27 ms 10280 KiB
in18.txt AC 29 ms 10380 KiB
in19.txt AC 26 ms 10376 KiB
in20.txt AC 30 ms 10476 KiB
in21.txt AC 32 ms 10624 KiB
in22.txt AC 33 ms 10392 KiB
in23.txt AC 31 ms 10464 KiB
in24.txt AC 29 ms 10504 KiB
in25.txt AC 30 ms 10460 KiB
in26.txt AC 29 ms 10336 KiB
in27.txt AC 29 ms 10596 KiB
in28.txt AC 30 ms 10420 KiB
in29.txt AC 29 ms 10524 KiB
in30.txt AC 28 ms 10316 KiB
in31.txt AC 4 ms 9748 KiB
in32.txt AC 4 ms 9832 KiB
in33.txt AC 4 ms 9808 KiB
in34.txt AC 4 ms 9632 KiB
in35.txt AC 4 ms 9872 KiB
in36.txt AC 4 ms 9564 KiB
in37.txt AC 32 ms 10488 KiB
sample01.txt AC 4 ms 9692 KiB
sample02.txt AC 4 ms 9732 KiB
sample03.txt AC 5 ms 9700 KiB