Submission #973098

#TimeUsernameProblemLanguageResultExecution timeMemory
973098jadai007Cryptography (NOI20_crypto)C++17
14 / 100
231 ms34872 KiB
#include<bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; set<int> s; map<int, int> mt; int arr[300300], n, cnt = 1, fac[300300], fw[300300], ans = 1; void update(int idx, int val){ for(int i = idx; i<=n; i+=(i&-i)) fw[i]+=val; } int query(int idx){ int sum = 0; for(int i = idx; i>0; i-=(i&-i)) sum+=fw[i]; return sum; } int main(){ cin.tie(nullptr)->sync_with_stdio(false); cin >> n; fac[0] = 1; for(int i = 1; i<=n; ++i) fac[i] = (fac[i - 1]*i)%mod; for(int i = 1; i<=n; ++i) cin >> arr[i], s.insert(arr[i]); for(auto x:s) mt[x] = cnt++; for(int i = 1; i<=n; ++i){ ans = (ans + fac[n - i]*(mt[arr[i]] - query(mt[arr[i]]) - 1)%mod)%mod; update(mt[arr[i]], 1); } cout << ans; }
#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...