Submission #737437

#TimeUsernameProblemLanguageResultExecution timeMemory
737437Ronin13Cryptography (NOI20_crypto)C++14
100 / 100
392 ms61232 KiB
#include <bits/stdc++.h> #define ll long long #define ull unsigned ll #define f first #define s second #define pii pair<int,int> #define pll pair<ll,ll> #define pb push_back #define epb emplace_back using namespace std; const int nmax = 10000001; vector <int> bit(nmax); const ll mod = 1e9 + 7; int lsb(int x){ return x & -x; } void add(int pos, int v, int n){ while(pos <= n){ bit[pos] += v; pos += lsb(pos); } } int get(int pos){ int res = 0; while(pos){ res += bit[pos]; pos -= lsb(pos); } return res; } int main(){ int n; cin >> n; int p[n + 1]; for(int i = 1; i <= n ;++i) cin >> p[i]; map <int,int> mp; int b[n + 1]; for(int i = 1;i <= n ;i++){ b[i] = p[i]; } sort(b + 1, b + 1 + n); for(int i = 1; i <= n; i++){ mp[b[i]] = i; } for(int i = 1; i <= n; ++i){ add(i, 1, n); p[i] = mp[p[i]]; } ll fact[n + 1]; fact[0] = 1; for(int i = 1; i <= n; i++){ fact[i] = fact[i - 1] * (ll)i % mod; } ll curans = 1; for(int i = 1; i <= n; i++){ int x = p[i]; ll o = get(x - 1); curans += fact[n - i] * o; curans %= mod; add(x, -1, n); } cout << curans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...