vector的函数
https://codeforces.com/contest/1650/problem/D
注意到第n位的数只能在第n次改变,所以从第n位开始倒着翻转。(用函数会方便很多)
find 函数和 rotate 函数
rotae 函数用法:调换一个序列中子序列[first, middle)与[middle ,last)的位置。
(https://jingyan.baidu.com/article/63acb44a046d8c61fcc17ece.html)
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int>pii; const int N=2e3+5; void solve(){ int n; cin>>n; vector<int>a(n),b(n); for(int i=0;i<n;i++)cin>>a[i]; for(int i=n-1;i>=0;i--){ int pos=find(a.begin(),a.end(),i+1)-a.begin(); b[i]=(pos+1)%(i+1); rotate(a.begin(),a.begin()+pos+1,a.begin()+i+1); } for(int i=0;i<n;i++){ cout<<b[i]<<" \n"[i==n-1]; } } int main(){ ios::sync_with_stdio(false); cin.tie(0); int t; cin>>t; while(t--){ solve(); } return 0; }