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 <iostream>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
long long int a[300005], f[300005], mod = 1e9 + 7;
int main() {
int n;
cin >> n;
ordered_set s;
for (int i = 1; i <= n; i++) {
cin >> a[i];
s.insert(a[i]);
}
f[n + 1] = 1;
for (int i = n; i >= 1; i--) {
f[i] = f[i + 1] * (n - i + 1) % mod;
}
long long int res = 0;
for (int i = 1; i <= n; i++) {
res = (res + s.order_of_key(a[i]) * f[i + 1]) % mod;
s.erase(s.find(a[i]));
}
cout << (res + 1) % mod;
}
# | 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... |