#include <iostream>
#include <vector>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define orderedset tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define lgm cin.tie(0)->sync_with_stdio(0);
const int mod = 1e9+7;
using namespace std;
signed main() {
lgm;
orderedset s;
int n;
cin >> n;
vector<pair<int,int>> o(n);
vector<int> num(n);
for (int i=0;i<n;i++) {
cin >> num[i];
o[i]={num[i],i};
}
sort(o.begin(),o.end());
int ans=0;
for (int i=0;i<n;i++) {
num[o[i].second]=i;
}
vector<int> lesscnt(n);
int f[n+1];
f[0]=1;
f[1]=1;
for (int i=2;i<=n;i++) {
f[i]=i*f[i-1]%mod;
}
for (int i=n-1;i>=0;i--) {
int l=0,r=n-1-i,m;
while (l<r) {
m=(l+r)>>1;
if (*s.find_by_order(m) >= num[i]) {
r=m;
} else {
l=m+1;
}
}
lesscnt[i]=l;
s.insert(num[i]);
}
for (int i=0;i<n;i++) {
ans=(ans+f[n-i-1]*lesscnt[i]%mod)%mod;
}
cout << ans+1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
600 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
600 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
799 ms |
30944 KB |
Output is correct |
3 |
Correct |
813 ms |
30804 KB |
Output is correct |
4 |
Correct |
783 ms |
30832 KB |
Output is correct |
5 |
Correct |
808 ms |
30800 KB |
Output is correct |
6 |
Correct |
784 ms |
31060 KB |
Output is correct |
7 |
Correct |
789 ms |
30804 KB |
Output is correct |
8 |
Correct |
805 ms |
30960 KB |
Output is correct |
9 |
Correct |
842 ms |
30828 KB |
Output is correct |
10 |
Correct |
789 ms |
30808 KB |
Output is correct |
11 |
Correct |
839 ms |
30800 KB |
Output is correct |
12 |
Correct |
839 ms |
30768 KB |
Output is correct |
13 |
Correct |
801 ms |
30848 KB |
Output is correct |
14 |
Correct |
789 ms |
30804 KB |
Output is correct |
15 |
Correct |
853 ms |
30804 KB |
Output is correct |
16 |
Correct |
803 ms |
30912 KB |
Output is correct |
17 |
Correct |
813 ms |
30816 KB |
Output is correct |
18 |
Correct |
846 ms |
30916 KB |
Output is correct |
19 |
Correct |
811 ms |
30744 KB |
Output is correct |
20 |
Correct |
781 ms |
30740 KB |
Output is correct |
21 |
Correct |
776 ms |
30804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
836 ms |
30840 KB |
Output is correct |
3 |
Correct |
866 ms |
30800 KB |
Output is correct |
4 |
Correct |
817 ms |
30748 KB |
Output is correct |
5 |
Correct |
848 ms |
30800 KB |
Output is correct |
6 |
Correct |
738 ms |
30804 KB |
Output is correct |
7 |
Correct |
781 ms |
30804 KB |
Output is correct |
8 |
Correct |
763 ms |
30760 KB |
Output is correct |
9 |
Correct |
781 ms |
30716 KB |
Output is correct |
10 |
Correct |
802 ms |
30820 KB |
Output is correct |
11 |
Correct |
766 ms |
30808 KB |
Output is correct |
12 |
Correct |
759 ms |
30800 KB |
Output is correct |
13 |
Correct |
816 ms |
30800 KB |
Output is correct |
14 |
Correct |
791 ms |
30948 KB |
Output is correct |
15 |
Correct |
812 ms |
30800 KB |
Output is correct |
16 |
Correct |
783 ms |
30836 KB |
Output is correct |
17 |
Correct |
810 ms |
30808 KB |
Output is correct |
18 |
Correct |
813 ms |
30936 KB |
Output is correct |
19 |
Correct |
840 ms |
30848 KB |
Output is correct |
20 |
Correct |
857 ms |
30904 KB |
Output is correct |
21 |
Correct |
879 ms |
30812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
3 |
Correct |
4 ms |
604 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
3 ms |
604 KB |
Output is correct |
6 |
Correct |
3 ms |
604 KB |
Output is correct |
7 |
Correct |
3 ms |
604 KB |
Output is correct |
8 |
Correct |
4 ms |
604 KB |
Output is correct |
9 |
Correct |
3 ms |
604 KB |
Output is correct |
10 |
Correct |
3 ms |
604 KB |
Output is correct |
11 |
Correct |
3 ms |
604 KB |
Output is correct |
12 |
Correct |
3 ms |
600 KB |
Output is correct |
13 |
Correct |
3 ms |
604 KB |
Output is correct |
14 |
Correct |
3 ms |
628 KB |
Output is correct |
15 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
600 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
600 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
3 ms |
604 KB |
Output is correct |
27 |
Correct |
4 ms |
604 KB |
Output is correct |
28 |
Correct |
3 ms |
604 KB |
Output is correct |
29 |
Correct |
3 ms |
604 KB |
Output is correct |
30 |
Correct |
3 ms |
604 KB |
Output is correct |
31 |
Correct |
3 ms |
604 KB |
Output is correct |
32 |
Correct |
4 ms |
604 KB |
Output is correct |
33 |
Correct |
3 ms |
604 KB |
Output is correct |
34 |
Correct |
3 ms |
604 KB |
Output is correct |
35 |
Correct |
3 ms |
604 KB |
Output is correct |
36 |
Correct |
3 ms |
600 KB |
Output is correct |
37 |
Correct |
3 ms |
604 KB |
Output is correct |
38 |
Correct |
3 ms |
628 KB |
Output is correct |
39 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
836 ms |
30840 KB |
Output is correct |
3 |
Correct |
866 ms |
30800 KB |
Output is correct |
4 |
Correct |
817 ms |
30748 KB |
Output is correct |
5 |
Correct |
848 ms |
30800 KB |
Output is correct |
6 |
Correct |
738 ms |
30804 KB |
Output is correct |
7 |
Correct |
781 ms |
30804 KB |
Output is correct |
8 |
Correct |
763 ms |
30760 KB |
Output is correct |
9 |
Correct |
781 ms |
30716 KB |
Output is correct |
10 |
Correct |
802 ms |
30820 KB |
Output is correct |
11 |
Correct |
766 ms |
30808 KB |
Output is correct |
12 |
Correct |
759 ms |
30800 KB |
Output is correct |
13 |
Correct |
816 ms |
30800 KB |
Output is correct |
14 |
Correct |
791 ms |
30948 KB |
Output is correct |
15 |
Correct |
812 ms |
30800 KB |
Output is correct |
16 |
Correct |
783 ms |
30836 KB |
Output is correct |
17 |
Correct |
810 ms |
30808 KB |
Output is correct |
18 |
Correct |
813 ms |
30936 KB |
Output is correct |
19 |
Correct |
840 ms |
30848 KB |
Output is correct |
20 |
Correct |
857 ms |
30904 KB |
Output is correct |
21 |
Correct |
879 ms |
30812 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
3 ms |
604 KB |
Output is correct |
24 |
Correct |
4 ms |
604 KB |
Output is correct |
25 |
Correct |
3 ms |
604 KB |
Output is correct |
26 |
Correct |
3 ms |
604 KB |
Output is correct |
27 |
Correct |
3 ms |
604 KB |
Output is correct |
28 |
Correct |
3 ms |
604 KB |
Output is correct |
29 |
Correct |
4 ms |
604 KB |
Output is correct |
30 |
Correct |
3 ms |
604 KB |
Output is correct |
31 |
Correct |
3 ms |
604 KB |
Output is correct |
32 |
Correct |
3 ms |
604 KB |
Output is correct |
33 |
Correct |
3 ms |
600 KB |
Output is correct |
34 |
Correct |
3 ms |
604 KB |
Output is correct |
35 |
Correct |
3 ms |
628 KB |
Output is correct |
36 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
37 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
600 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
600 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
600 KB |
Output is correct |
26 |
Correct |
799 ms |
30944 KB |
Output is correct |
27 |
Correct |
813 ms |
30804 KB |
Output is correct |
28 |
Correct |
783 ms |
30832 KB |
Output is correct |
29 |
Correct |
808 ms |
30800 KB |
Output is correct |
30 |
Correct |
784 ms |
31060 KB |
Output is correct |
31 |
Correct |
789 ms |
30804 KB |
Output is correct |
32 |
Correct |
805 ms |
30960 KB |
Output is correct |
33 |
Correct |
842 ms |
30828 KB |
Output is correct |
34 |
Correct |
789 ms |
30808 KB |
Output is correct |
35 |
Correct |
839 ms |
30800 KB |
Output is correct |
36 |
Correct |
839 ms |
30768 KB |
Output is correct |
37 |
Correct |
801 ms |
30848 KB |
Output is correct |
38 |
Correct |
789 ms |
30804 KB |
Output is correct |
39 |
Correct |
853 ms |
30804 KB |
Output is correct |
40 |
Correct |
803 ms |
30912 KB |
Output is correct |
41 |
Correct |
813 ms |
30816 KB |
Output is correct |
42 |
Correct |
846 ms |
30916 KB |
Output is correct |
43 |
Correct |
811 ms |
30744 KB |
Output is correct |
44 |
Correct |
781 ms |
30740 KB |
Output is correct |
45 |
Correct |
776 ms |
30804 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
836 ms |
30840 KB |
Output is correct |
48 |
Correct |
866 ms |
30800 KB |
Output is correct |
49 |
Correct |
817 ms |
30748 KB |
Output is correct |
50 |
Correct |
848 ms |
30800 KB |
Output is correct |
51 |
Correct |
738 ms |
30804 KB |
Output is correct |
52 |
Correct |
781 ms |
30804 KB |
Output is correct |
53 |
Correct |
763 ms |
30760 KB |
Output is correct |
54 |
Correct |
781 ms |
30716 KB |
Output is correct |
55 |
Correct |
802 ms |
30820 KB |
Output is correct |
56 |
Correct |
766 ms |
30808 KB |
Output is correct |
57 |
Correct |
759 ms |
30800 KB |
Output is correct |
58 |
Correct |
816 ms |
30800 KB |
Output is correct |
59 |
Correct |
791 ms |
30948 KB |
Output is correct |
60 |
Correct |
812 ms |
30800 KB |
Output is correct |
61 |
Correct |
783 ms |
30836 KB |
Output is correct |
62 |
Correct |
810 ms |
30808 KB |
Output is correct |
63 |
Correct |
813 ms |
30936 KB |
Output is correct |
64 |
Correct |
840 ms |
30848 KB |
Output is correct |
65 |
Correct |
857 ms |
30904 KB |
Output is correct |
66 |
Correct |
879 ms |
30812 KB |
Output is correct |
67 |
Correct |
1 ms |
348 KB |
Output is correct |
68 |
Correct |
3 ms |
604 KB |
Output is correct |
69 |
Correct |
4 ms |
604 KB |
Output is correct |
70 |
Correct |
3 ms |
604 KB |
Output is correct |
71 |
Correct |
3 ms |
604 KB |
Output is correct |
72 |
Correct |
3 ms |
604 KB |
Output is correct |
73 |
Correct |
3 ms |
604 KB |
Output is correct |
74 |
Correct |
4 ms |
604 KB |
Output is correct |
75 |
Correct |
3 ms |
604 KB |
Output is correct |
76 |
Correct |
3 ms |
604 KB |
Output is correct |
77 |
Correct |
3 ms |
604 KB |
Output is correct |
78 |
Correct |
3 ms |
600 KB |
Output is correct |
79 |
Correct |
3 ms |
604 KB |
Output is correct |
80 |
Correct |
3 ms |
628 KB |
Output is correct |
81 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
82 |
Halted |
0 ms |
0 KB |
- |