# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
973232 | njoop | Cryptography (NOI20_crypto) | C++17 | 328 ms | 25076 KiB |
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 <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
#define ll long long
using namespace __gnu_pbds;
using namespace std;
int n, in, ord[300010], idx;
ll fac[300010], mod = 1e9+7, ans;
vector<pair<int, int>> v;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ordered_set s;
int main() {
cin.tie(0)->sync_with_stdio(0);
fac[0] = 1;
for(int i=1; i<300010; i++) {
fac[i] = i*fac[i-1];
fac[i] %= mod;
}
cin >> n;
for(int i=1; i<=n; i++) {
cin >> in;
v.push_back({in, i});
}
sort(v.begin(), v.end());
for(int i=0; i<v.size(); i++) {
ord[v[i].second] = i;
}
for(int i=1; i<=n; i++) {
idx = s.order_of_key(ord[i]);
ans += ((ord[i]-idx)*fac[n-i])%mod;
ans %= mod;
s.insert(ord[i]);
}
cout << (ans+1)%mod;
return 0;
}
Compilation message (stderr)
# | 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... |