# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
294551 | nandonathaniel | Cryptography (NOI20_crypto) | C++14 | 161 ms | 15976 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>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> pii;
const LL MAXN=300005,MOD=1000000007;
LL a[MAXN],bit[MAXN],n,fac[MAXN];
void update(LL now){
for(LL i=now;i<=n;i+=(i&(-i)))bit[i]++;
}
LL query(LL now){
LL ret=0;
if(now==0)return ret;
for(LL i=now;i>0;i-=(i&(-i)))ret+=bit[i];
return ret;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
fac[0]=1;
for(LL i=1;i<=MAXN-5;i++)fac[i]=(fac[i-1]*i)%MOD;
cin >> n;
vector<pii> v;
for(LL i=1;i<=n;i++){
cin >> a[i];
v.push_back({a[i],i});
}
sort(v.begin(),v.end());
for(int i=0;i<v.size();i++)a[v[i].second]=i+1;
LL ans=0;
for(int i=1;i<=n;i++){
ans=(ans+(((a[i]-1-query(a[i]-1))*fac[n-i])%MOD))%MOD;
update(a[i]);
}
cout << (ans+1)%MOD << '\n';
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... |