Submission #676486

#TimeUsernameProblemLanguageResultExecution timeMemory
676486penguin133Cryptography (NOI20_crypto)C++17
100 / 100
93 ms10344 KiB
#include <bits/stdc++.h> using namespace std; int ft[300005]; pair<int, int> d[300005]; int n; int ls(int x){ return x & (-x); } void update(int p, int v){ for(;p<=n;p+=ls(p)){ ft[p] += v; } } void update1(int p){ for(;p<=n;p+=ls(p))ft[p] = 0; } int query(int p){ int sum = 0; for(;p;p-=ls(p)){ sum += ft[p]; } return sum; } int main(){ ios::sync_with_stdio(0);cin.tie(0); cin >> n; int arr[n+1]; long long f[n+1]; f[1] = 1; f[0] = 0; for(int i=1;i<=n;i++)cin >> arr[i]; for(int i=1;i<=n;i++)update(i, 1); for(int i=2;i<=n;i++)f[i] = (i * f[i-1])%1000000007; for(int i = 1; i <= n; i++){ d[i].first = arr[i]; d[i].second = i; } sort(d + 1, d + n + 1); int cnt2 = 1; for(int i = 1; i <= n; i++){ if (i > 1 && d[i].first != d[i-1].first) cnt2++; arr[d[i].second] = cnt2; } long long cnt = 1; for(int i=1;i<=n;i++){ int e = arr[i]; cnt += f[n-i] * (query(e)- 1); cnt %= 1000000007; update(e, -1); } cout << cnt; }
#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...