제출 #261257

#제출 시각아이디문제언어결과실행 시간메모리
261257BertedCryptography (NOI20_crypto)C++14
100 / 100
119 ms9284 KiB
#include <iostream> #include <algorithm> #define pii pair<int, int> #define ll long long #define fst first #define snd second using namespace std; const ll MD = (1e9) + 7; int n; pii ar[300001] = {}; ll fkt[300001] = {}, rs = 0; int fwk[300001] = {}; void upd(int x) { for (; x <= n; x += x & (-x)) {fwk[x]++;} } int query(int x) { int to = 0; for (; x; x -= x & (-x)) {to += fwk[x];} return to; } int main() { ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; fkt[0] = 1; for (int i = 1; i <= n; i++) {fkt[i] = (fkt[i - 1] * i) % MD;} for (int i = 0; i < n; i++) { cin >> ar[i].fst; ar[i].snd = i; } sort(ar, ar + n); for (int i = 0; i < n; i++) { rs += (fkt[n - 1 - ar[i].snd] * (i - query(ar[i].snd))) % MD; rs %= MD; upd(ar[i].snd + 1); } cout << (rs + 1) % MD << "\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...