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<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
int fac[100005];
int mod = 1e9+7;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
fac[1]=1;
for(int i = 2;i<=1e5;i++){
fac[i]=fac[i-1]*i;
fac[i]%=mod;
}
int n;
cin >> n;
int arr[n];
ordered_set pts;
for(int &i : arr){
cin >> i;
pts.insert(i);
}
long long ans = 0;
for(int i = 0;i<n;i++){
ans+=pts.order_of_key(arr[i])*fac[n-i-1];
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... |