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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
long long fac[300005];
long long mod = 1e9+7;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
fac[1]=1;
for(long long i = 2;i<=3e5;i++){
fac[i]=fac[i-1]*i;
fac[i]%=mod;
}
long long n;
cin >> n;
long long arr[n];
ordered_set pts;
for(long long i = 0;i<n;i++){
cin >> arr[i];
pts.insert(arr[i]);
}
long long ans = 0;
for(long long i = 0;i<n;i++){
ans+=1LL*pts.order_of_key(arr[i])*fac[n-i-1];
ans%=mod;
pts.erase(arr[i]);
}
ans++;
cout << ans;
return 0;
}
# | 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... |