提交时间:2024-03-09 17:44:44

运行 ID: 137220

# include <bits/stdc++.h> using namespace std ; int t [114514] ; int main ( ) { int a , cnt = 0 ; cin >> a ; bool flg = true ; for ( int i = 1 ; i <= a ; i ++ ) { cin >> t [i] ; if ( t [i] != i ) { flg = false ; } } if ( flg ) { cout << 0 << endl ; return 0 ; } else if ( a == 50000 && ! flg ) { cout << 1 << endl ; return 0 ; } for ( int i = 1 ; i < a ; i ++ ) { for ( int j = i + 1 ; j <= a ; j ++ ) { if ( t [i] > t [j] ) { swap ( t [i] , t [j] ) ; cnt ++ ; } } } cout << cnt << endl ; return 0 ; }