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 ll long long
#define pii pair<ll,ll>
#define pb push_back
#define fi first
#define se second
const ll N = 3e5+3;
const ll MOD = 1e9+7;
ll a[N],b[N],fac[N];
ll n,tmp,ans;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
fac[0] = 1;
for(int i=1; i<=n; i++) {
cin >> a[i];
b[i] = a[i];
fac[i] = fac[i-1] * i;
fac[i] %= MOD;
}
// sort(b+1,b+n+1);
// for(int i=1; i<=n; i++) {
// mp[b[i]] = i;
// }
// for(int i=1; i<=n; i++) a[i] = mp[a[i]];
for(int i=1; i<=n; i++) {
tmp = 0;
for(int j=i+1; j<=n; j++) {
if(a[i] > a[j]) tmp++;
}
ans += (fac[n-i] * tmp) % MOD;
ans %= MOD;
}
cout << ans + 1 << endl;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |