# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
258754 | ryangohca | Cryptography (NOI20_crypto) | C++17 | 296 ms | 15340 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 <bits/stdc++.h>
#define int long long
using namespace std;
int fw[300001];
int fact[300001];
const int N = 300000;
const int LOGN = log2(N) + 1;
const int MOD = 1000000007;
void update(int x, int v) {
for (; x<=N; x+=x&(-x)) fw[x] += v;
}
int sum(int x) {
int res = 0;
for(; x; x-=x&(-x)) res += fw[x];
return res;
}
vector<int> discretize(const vector<int>& V){
vector<int> dis = V;
vector<int> v(V.size());
sort(dis.begin(), dis.end());
dis.resize(unique(dis.begin(), dis.end()) - dis.begin());
for (int i = 0; i < V.size(); i++){
v[i] = lower_bound(dis.begin(), dis.end(), V[i]) - dis.begin() + 1;
}
return v;
}
main(){
int n; cin >> n;
vector<int> nums;
fact[0] = 1;
for (int i = 0; i < n; i++){
int h; cin >> h;
nums.push_back(h);
update(i + 1, 1);
fact[i+1] = fact[i] * (i + 1);
fact[i+1] %= MOD;
}
nums = discretize(nums);
int ans = 1;
for (int i = 0; i < n; i++){
int target = nums[i];
ans += (sum(target) - 1) * fact[n - i - 1];
ans %= MOD;
update(target, -1);
}
cout << ans << endl;
}
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... |