版本比较
题解:CF2161H Cycle Sort
正文
增加 3 行删除 3 行
93 行未改动9495969798989910010110210310310410510610736 行未改动14414514614714814814915015115213 行未改动93 行未改动void solve(){ // trans ordinary sequence into 01 sequence // focus on each 0 // if 0 is init at a[i], then it will never move // if 0 is at b[i], then it will check // if 0 is at b[i], then it will check // i%n, (i+m)%n, (i+2m)%n, ... // that is , for each 0 at a[i], put token value -1 at position i // for each 0 at b[i], put token value i at position i%n // then do operator: // for each position i with >=2 tokens, // for each position i with >=2 tokens, // replace all token except the smallest one to (i+m)%n, // all token replced value added m // due to (n,m)=1, so i -> (i+m)%n will be a cycle // let first reorder them36 行未改动 while(T--){ cin>>N>>M>>K; for(int i=1;i<=N;i++) cin>>A[i]; for(int i=1;i<=M;i++) cin>>B[i]; // make gcd(n,m)=1 // make gcd(n,m)=1 int g=__gcd(N,M); for(int t=1;t<=g;t++){ n=m=0; for(int i=t;i<=N;i+=g) a[++n]=A[i];13 行未改动