# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
492561 | anonymous | Cryptography (NOI20_crypto) | C++14 | 96 ms | 9104 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 <iostream>
#include <algorithm>
#define MAXN 300005
#define LL long long
#define MOD 1000000007
using namespace std;
int N,P[MAXN], Lookup[MAXN];
LL fac[MAXN]={1}, ans;
class Fenwick {
int BIT[MAXN];
public:
void upd(int x) {
for (; x<=N; x+= x&(-x)) {BIT[x]++;}
}
int ask(int p) {
int res = 0;
for (; p>0; p-=p&(-p)) {res += BIT[p];}
return res;
}
} FT;
int main() {
//freopen("cryptin.txt","r",stdin);
scanf("%d",&N);
for (LL i=1; i<=N; i++) {
scanf("%d",&P[i]);
Lookup[i] = P[i];
fac[i] = (i*fac[i-1]) % MOD;
}
sort(Lookup+1, Lookup+N+1);
for (int i=1; i<=N; i++) {
LL ord = lower_bound(Lookup+1, Lookup+N+1, P[i]) - Lookup;
ans = (ans + fac[N-i]*(ord-1-FT.ask(ord))) % MOD;
FT.upd(ord);
}
printf("%lld", ans+1);
}
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... |