이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |