Submission #504589

#TimeUsernameProblemLanguageResultExecution timeMemory
504589JomnoiCryptography (NOI20_crypto)C++17
100 / 100
621 ms36220 KiB
#include <bits/stdc++.h> #define DEBUG 0 using namespace std; const int N = 3e5 + 10; const int MOD = 1e9 + 7; int p[N]; map <int, int> cmp; int fenwick[N]; long long fac[N]; void update(int idx, int val) { for(; idx < N; idx += (idx & -idx)) { fenwick[idx] += val; } } int query(int idx) { int res = 0; for(; idx > 0; idx -= (idx & -idx)) { res += fenwick[idx]; } return res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; fac[0] = 1; for(int i = 1; i <= n; i++) { fac[i] = fac[i - 1] * i % MOD; } set <int> s; for(int i = 1; i <= n; i++) { cin >> p[i]; s.insert(p[i]); } int cnt = 0; for(auto v : s) { cmp[v] = ++cnt; } long long ans = 1; for(int i = 1; i <= n; i++) { ans = (ans + fac[n - i] * (cmp[p[i]] - query(cmp[p[i]]) - 1) % MOD) % MOD; update(cmp[p[i]], 1); } cout << ans; 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...