This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
void slove(){
int n,tmp=0,ans=0;
vector <int> a,b;
cin >> n;
for(int i=0;i<n;i++){
int x;
cin >> x;
a.push_back(x);
b.push_back(x);
}
sort(b.begin(),b.end(),greater <int>());
for(int i=0;i<n && tmp<n;i++){
if(a[tmp]==b[tmp]) tmp++;
else if(a[n-1]==b[tmp]){
reverse(a.begin()+tmp,a.end());
ans++;
tmp++;
}
else{
for(int j=tmp+1;j<n-1;j++){
if(a[j]==b[tmp]){
reverse(a.begin()+j,a.end());
ans++;
reverse(a.begin()+tmp,a.end());
ans++;
tmp++;
}
}
}
}
cout << ans << "\n";
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int tc=1;
cin >> tc;
while(tc--) slove();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |