#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define ll long long
#define ull unsigned long long
#define llll __int128
#define ld long double
#define pll pair<ll, ll>
#define pii pair<int, int>
#define coutpair(p) cout << p.first << " " << p.second << "|"
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll MOD = 1e9+7;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n; cin >> n;
ll p[n];
ordered_set<ll> s;
for (int i=0; i<n; i++){
cin >> p[i];
s.insert(p[i]);
}
ll pre[n+5];
pre[0] = 0, pre[1] = 1;
for (int i=2; i<=n; i++) pre[i] = (pre[i-1]*i)%MOD;
ll ans = 0;
for (int i=0; i<n; i++){
ll x = s.order_of_key(p[i]);
//cerr << x << "\n";
ans += x*pre[n-i-1];
ans %= MOD;
s.erase(p[i]);
}
ans++; ans %= MOD;
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... |