# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
958028 | Zena_Hossam | Cryptography (NOI20_crypto) | C++14 | 0 ms | 0 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>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define ll int
using namespace std;
namespace __gnu_pbds
{
typedef tree<ll,
null_type,
less_equal<ll>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
}
using namespace __gnu_pbds;
#define fi ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//#define ll double
#define ll1 long long
#define F first
#define S second
#define sz size()
#define all(s) s.begin(),s.end()
#define all1(s) s.rbegin(),s.rend()
ll mod=1e9+7;
int main()
{
fi
//freopen("stdin.in","r",stdin);freopen("stdout.out","w",stdout);
//cin>>T;ll oo=0;
ll n;
cin>>n;
map<ll,ll>d
ll m[n+5]={},dd[n+5]={};
ll o=1;
for(ll i=1;i<=n;i++){
o=(i*o)%mod;
m[i]=o;
}
ll arr[n],a[n];
for(ll i=0;i<n;i++){
cin>>a[i];
arr[i]=a[i];
}
sort(a,a+n);
for(ll i=0;i<n;i++){
d[a[i]]=i+1;
}
for(ll i=1;i<=n;i++){
dd[d[arr[i-1]]]=i;
}
ll k[n+5]={};ll c=0;
ordered_set q;
for(ll i=1;i<=n;i++){
//cout<<i-q.order_of_key(dd[i])-1<<" ";
c+=((m[(n-dd[i])]%mod)*((i-1-q.order_of_key(dd[i]))%mod))%mod;q.insert(dd[i]);
}cout<<(c+1)%mod;
}