#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
int fac[300005];
int mod = 1e9+7;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
fac[1]=1;
for(int i = 2;i<=3e5;i++){
fac[i]=fac[i-1]*i;
fac[i]%=mod;
}
int n;
cin >> n;
long long arr[n];
ordered_set pts;
for(int i = 0;i<n;i++){
cin >> arr[i];
pts.insert(arr[i]);
}
long long ans = 0;
for(int i = 0;i<n;i++){
ans+=1LL*pts.order_of_key(arr[i])*fac[n-i-1];
ans%=mod;
pts.erase(arr[i]);
}
ans++;
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1616 KB |
Output is correct |
2 |
Correct |
3 ms |
1616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1616 KB |
Output is correct |
2 |
Correct |
3 ms |
1616 KB |
Output is correct |
3 |
Correct |
3 ms |
1788 KB |
Output is correct |
4 |
Correct |
3 ms |
1616 KB |
Output is correct |
5 |
Correct |
3 ms |
1616 KB |
Output is correct |
6 |
Correct |
3 ms |
1616 KB |
Output is correct |
7 |
Correct |
3 ms |
1616 KB |
Output is correct |
8 |
Correct |
3 ms |
1616 KB |
Output is correct |
9 |
Correct |
3 ms |
1400 KB |
Output is correct |
10 |
Correct |
4 ms |
1616 KB |
Output is correct |
11 |
Correct |
3 ms |
1628 KB |
Output is correct |
12 |
Correct |
3 ms |
1616 KB |
Output is correct |
13 |
Correct |
3 ms |
1616 KB |
Output is correct |
14 |
Correct |
3 ms |
1616 KB |
Output is correct |
15 |
Correct |
3 ms |
1616 KB |
Output is correct |
16 |
Correct |
3 ms |
1616 KB |
Output is correct |
17 |
Correct |
3 ms |
1632 KB |
Output is correct |
18 |
Correct |
3 ms |
1616 KB |
Output is correct |
19 |
Correct |
3 ms |
1616 KB |
Output is correct |
20 |
Correct |
3 ms |
1616 KB |
Output is correct |
21 |
Correct |
3 ms |
1616 KB |
Output is correct |
22 |
Correct |
3 ms |
1616 KB |
Output is correct |
23 |
Correct |
3 ms |
1616 KB |
Output is correct |
24 |
Correct |
3 ms |
1460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1616 KB |
Output is correct |
2 |
Incorrect |
288 ms |
22680 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1616 KB |
Output is correct |
2 |
Incorrect |
266 ms |
22632 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1616 KB |
Output is correct |
2 |
Incorrect |
4 ms |
1616 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1616 KB |
Output is correct |
2 |
Correct |
3 ms |
1616 KB |
Output is correct |
3 |
Correct |
3 ms |
1788 KB |
Output is correct |
4 |
Correct |
3 ms |
1616 KB |
Output is correct |
5 |
Correct |
3 ms |
1616 KB |
Output is correct |
6 |
Correct |
3 ms |
1616 KB |
Output is correct |
7 |
Correct |
3 ms |
1616 KB |
Output is correct |
8 |
Correct |
3 ms |
1616 KB |
Output is correct |
9 |
Correct |
3 ms |
1400 KB |
Output is correct |
10 |
Correct |
4 ms |
1616 KB |
Output is correct |
11 |
Correct |
3 ms |
1628 KB |
Output is correct |
12 |
Correct |
3 ms |
1616 KB |
Output is correct |
13 |
Correct |
3 ms |
1616 KB |
Output is correct |
14 |
Correct |
3 ms |
1616 KB |
Output is correct |
15 |
Correct |
3 ms |
1616 KB |
Output is correct |
16 |
Correct |
3 ms |
1616 KB |
Output is correct |
17 |
Correct |
3 ms |
1632 KB |
Output is correct |
18 |
Correct |
3 ms |
1616 KB |
Output is correct |
19 |
Correct |
3 ms |
1616 KB |
Output is correct |
20 |
Correct |
3 ms |
1616 KB |
Output is correct |
21 |
Correct |
3 ms |
1616 KB |
Output is correct |
22 |
Correct |
3 ms |
1616 KB |
Output is correct |
23 |
Correct |
3 ms |
1616 KB |
Output is correct |
24 |
Correct |
3 ms |
1460 KB |
Output is correct |
25 |
Correct |
3 ms |
1616 KB |
Output is correct |
26 |
Incorrect |
4 ms |
1616 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1616 KB |
Output is correct |
2 |
Incorrect |
266 ms |
22632 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1616 KB |
Output is correct |
2 |
Correct |
3 ms |
1616 KB |
Output is correct |
3 |
Correct |
3 ms |
1788 KB |
Output is correct |
4 |
Correct |
3 ms |
1616 KB |
Output is correct |
5 |
Correct |
3 ms |
1616 KB |
Output is correct |
6 |
Correct |
3 ms |
1616 KB |
Output is correct |
7 |
Correct |
3 ms |
1616 KB |
Output is correct |
8 |
Correct |
3 ms |
1616 KB |
Output is correct |
9 |
Correct |
3 ms |
1400 KB |
Output is correct |
10 |
Correct |
4 ms |
1616 KB |
Output is correct |
11 |
Correct |
3 ms |
1628 KB |
Output is correct |
12 |
Correct |
3 ms |
1616 KB |
Output is correct |
13 |
Correct |
3 ms |
1616 KB |
Output is correct |
14 |
Correct |
3 ms |
1616 KB |
Output is correct |
15 |
Correct |
3 ms |
1616 KB |
Output is correct |
16 |
Correct |
3 ms |
1616 KB |
Output is correct |
17 |
Correct |
3 ms |
1632 KB |
Output is correct |
18 |
Correct |
3 ms |
1616 KB |
Output is correct |
19 |
Correct |
3 ms |
1616 KB |
Output is correct |
20 |
Correct |
3 ms |
1616 KB |
Output is correct |
21 |
Correct |
3 ms |
1616 KB |
Output is correct |
22 |
Correct |
3 ms |
1616 KB |
Output is correct |
23 |
Correct |
3 ms |
1616 KB |
Output is correct |
24 |
Correct |
3 ms |
1460 KB |
Output is correct |
25 |
Correct |
4 ms |
1616 KB |
Output is correct |
26 |
Incorrect |
288 ms |
22680 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |