ZOJ4104 Sequence in the Pocket(2019浙江省赛)
思维~
#include<bits/stdc++.h> using namespace std; const int maxn=1e6+14; int a[maxn]; int b[maxn]; int N; int main () { int T; scanf ("%d",&T); while (T--) { scanf ("%d",&N); for (int i=1;i<=N;i++) { scanf ("%d",&a[i]); b[i]=a[i]; } sort (b+1,b+N+1); int ans=0; for (int i=N;i>=1;i--) { if (a[i]==b[i+ans]) continue; else ans++; } printf ("%d\n",ans); } return 0; }