#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;
}
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;
}
}
s.insert(num[i]);
ans=(ans+f[n-i-1]*l%mod)%mod;
}
cout << (ans+1)%mod;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 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 |
400 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
805 ms |
28528 KB |
Output is correct |
3 |
Correct |
759 ms |
28480 KB |
Output is correct |
4 |
Correct |
766 ms |
28492 KB |
Output is correct |
5 |
Correct |
729 ms |
28496 KB |
Output is correct |
6 |
Correct |
730 ms |
28580 KB |
Output is correct |
7 |
Correct |
800 ms |
28488 KB |
Output is correct |
8 |
Correct |
864 ms |
28492 KB |
Output is correct |
9 |
Correct |
841 ms |
28500 KB |
Output is correct |
10 |
Correct |
844 ms |
28612 KB |
Output is correct |
11 |
Correct |
842 ms |
28540 KB |
Output is correct |
12 |
Correct |
816 ms |
28416 KB |
Output is correct |
13 |
Correct |
826 ms |
28396 KB |
Output is correct |
14 |
Correct |
823 ms |
28576 KB |
Output is correct |
15 |
Correct |
803 ms |
28492 KB |
Output is correct |
16 |
Correct |
846 ms |
28440 KB |
Output is correct |
17 |
Correct |
840 ms |
28584 KB |
Output is correct |
18 |
Correct |
845 ms |
28464 KB |
Output is correct |
19 |
Correct |
799 ms |
28444 KB |
Output is correct |
20 |
Correct |
785 ms |
28592 KB |
Output is correct |
21 |
Correct |
804 ms |
28752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
862 ms |
28576 KB |
Output is correct |
3 |
Correct |
863 ms |
28444 KB |
Output is correct |
4 |
Correct |
843 ms |
28520 KB |
Output is correct |
5 |
Correct |
858 ms |
28484 KB |
Output is correct |
6 |
Correct |
824 ms |
28508 KB |
Output is correct |
7 |
Correct |
793 ms |
28500 KB |
Output is correct |
8 |
Correct |
803 ms |
28416 KB |
Output is correct |
9 |
Correct |
799 ms |
28496 KB |
Output is correct |
10 |
Correct |
793 ms |
28496 KB |
Output is correct |
11 |
Correct |
813 ms |
28372 KB |
Output is correct |
12 |
Correct |
811 ms |
28500 KB |
Output is correct |
13 |
Correct |
812 ms |
28756 KB |
Output is correct |
14 |
Correct |
795 ms |
28596 KB |
Output is correct |
15 |
Correct |
804 ms |
28444 KB |
Output is correct |
16 |
Correct |
785 ms |
28576 KB |
Output is correct |
17 |
Correct |
786 ms |
28500 KB |
Output is correct |
18 |
Correct |
824 ms |
28460 KB |
Output is correct |
19 |
Correct |
847 ms |
28436 KB |
Output is correct |
20 |
Correct |
828 ms |
28528 KB |
Output is correct |
21 |
Correct |
845 ms |
28528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
3 |
Correct |
3 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 |
3 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 |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
3 ms |
604 KB |
Output is correct |
14 |
Correct |
3 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
604 KB |
Output is correct |
18 |
Correct |
3 ms |
604 KB |
Output is correct |
19 |
Correct |
3 ms |
604 KB |
Output is correct |
20 |
Correct |
3 ms |
604 KB |
Output is correct |
21 |
Correct |
2 ms |
604 KB |
Output is correct |
22 |
Correct |
3 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 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 |
400 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 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 |
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 |
3 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 |
2 ms |
604 KB |
Output is correct |
37 |
Correct |
3 ms |
604 KB |
Output is correct |
38 |
Correct |
3 ms |
604 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
3 ms |
604 KB |
Output is correct |
41 |
Correct |
3 ms |
604 KB |
Output is correct |
42 |
Correct |
3 ms |
604 KB |
Output is correct |
43 |
Correct |
3 ms |
604 KB |
Output is correct |
44 |
Correct |
3 ms |
604 KB |
Output is correct |
45 |
Correct |
2 ms |
604 KB |
Output is correct |
46 |
Correct |
3 ms |
604 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
4 ms |
616 KB |
Output is correct |
49 |
Correct |
3 ms |
604 KB |
Output is correct |
50 |
Correct |
3 ms |
604 KB |
Output is correct |
51 |
Correct |
3 ms |
604 KB |
Output is correct |
52 |
Correct |
3 ms |
604 KB |
Output is correct |
53 |
Correct |
3 ms |
572 KB |
Output is correct |
54 |
Correct |
3 ms |
604 KB |
Output is correct |
55 |
Correct |
3 ms |
604 KB |
Output is correct |
56 |
Correct |
3 ms |
604 KB |
Output is correct |
57 |
Correct |
3 ms |
604 KB |
Output is correct |
58 |
Correct |
3 ms |
604 KB |
Output is correct |
59 |
Correct |
3 ms |
604 KB |
Output is correct |
60 |
Correct |
3 ms |
604 KB |
Output is correct |
61 |
Correct |
0 ms |
348 KB |
Output is correct |
62 |
Correct |
4 ms |
604 KB |
Output is correct |
63 |
Correct |
3 ms |
604 KB |
Output is correct |
64 |
Correct |
4 ms |
524 KB |
Output is correct |
65 |
Correct |
3 ms |
604 KB |
Output is correct |
66 |
Correct |
3 ms |
676 KB |
Output is correct |
67 |
Correct |
3 ms |
604 KB |
Output is correct |
68 |
Correct |
3 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
862 ms |
28576 KB |
Output is correct |
3 |
Correct |
863 ms |
28444 KB |
Output is correct |
4 |
Correct |
843 ms |
28520 KB |
Output is correct |
5 |
Correct |
858 ms |
28484 KB |
Output is correct |
6 |
Correct |
824 ms |
28508 KB |
Output is correct |
7 |
Correct |
793 ms |
28500 KB |
Output is correct |
8 |
Correct |
803 ms |
28416 KB |
Output is correct |
9 |
Correct |
799 ms |
28496 KB |
Output is correct |
10 |
Correct |
793 ms |
28496 KB |
Output is correct |
11 |
Correct |
813 ms |
28372 KB |
Output is correct |
12 |
Correct |
811 ms |
28500 KB |
Output is correct |
13 |
Correct |
812 ms |
28756 KB |
Output is correct |
14 |
Correct |
795 ms |
28596 KB |
Output is correct |
15 |
Correct |
804 ms |
28444 KB |
Output is correct |
16 |
Correct |
785 ms |
28576 KB |
Output is correct |
17 |
Correct |
786 ms |
28500 KB |
Output is correct |
18 |
Correct |
824 ms |
28460 KB |
Output is correct |
19 |
Correct |
847 ms |
28436 KB |
Output is correct |
20 |
Correct |
828 ms |
28528 KB |
Output is correct |
21 |
Correct |
845 ms |
28528 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
3 ms |
604 KB |
Output is correct |
24 |
Correct |
3 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 |
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 |
3 ms |
604 KB |
Output is correct |
33 |
Correct |
2 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 |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
3 ms |
604 KB |
Output is correct |
38 |
Correct |
3 ms |
604 KB |
Output is correct |
39 |
Correct |
3 ms |
604 KB |
Output is correct |
40 |
Correct |
3 ms |
604 KB |
Output is correct |
41 |
Correct |
3 ms |
604 KB |
Output is correct |
42 |
Correct |
2 ms |
604 KB |
Output is correct |
43 |
Correct |
3 ms |
604 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
979 ms |
28568 KB |
Output is correct |
46 |
Execution timed out |
1012 ms |
28380 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 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 |
400 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
805 ms |
28528 KB |
Output is correct |
27 |
Correct |
759 ms |
28480 KB |
Output is correct |
28 |
Correct |
766 ms |
28492 KB |
Output is correct |
29 |
Correct |
729 ms |
28496 KB |
Output is correct |
30 |
Correct |
730 ms |
28580 KB |
Output is correct |
31 |
Correct |
800 ms |
28488 KB |
Output is correct |
32 |
Correct |
864 ms |
28492 KB |
Output is correct |
33 |
Correct |
841 ms |
28500 KB |
Output is correct |
34 |
Correct |
844 ms |
28612 KB |
Output is correct |
35 |
Correct |
842 ms |
28540 KB |
Output is correct |
36 |
Correct |
816 ms |
28416 KB |
Output is correct |
37 |
Correct |
826 ms |
28396 KB |
Output is correct |
38 |
Correct |
823 ms |
28576 KB |
Output is correct |
39 |
Correct |
803 ms |
28492 KB |
Output is correct |
40 |
Correct |
846 ms |
28440 KB |
Output is correct |
41 |
Correct |
840 ms |
28584 KB |
Output is correct |
42 |
Correct |
845 ms |
28464 KB |
Output is correct |
43 |
Correct |
799 ms |
28444 KB |
Output is correct |
44 |
Correct |
785 ms |
28592 KB |
Output is correct |
45 |
Correct |
804 ms |
28752 KB |
Output is correct |
46 |
Correct |
1 ms |
344 KB |
Output is correct |
47 |
Correct |
862 ms |
28576 KB |
Output is correct |
48 |
Correct |
863 ms |
28444 KB |
Output is correct |
49 |
Correct |
843 ms |
28520 KB |
Output is correct |
50 |
Correct |
858 ms |
28484 KB |
Output is correct |
51 |
Correct |
824 ms |
28508 KB |
Output is correct |
52 |
Correct |
793 ms |
28500 KB |
Output is correct |
53 |
Correct |
803 ms |
28416 KB |
Output is correct |
54 |
Correct |
799 ms |
28496 KB |
Output is correct |
55 |
Correct |
793 ms |
28496 KB |
Output is correct |
56 |
Correct |
813 ms |
28372 KB |
Output is correct |
57 |
Correct |
811 ms |
28500 KB |
Output is correct |
58 |
Correct |
812 ms |
28756 KB |
Output is correct |
59 |
Correct |
795 ms |
28596 KB |
Output is correct |
60 |
Correct |
804 ms |
28444 KB |
Output is correct |
61 |
Correct |
785 ms |
28576 KB |
Output is correct |
62 |
Correct |
786 ms |
28500 KB |
Output is correct |
63 |
Correct |
824 ms |
28460 KB |
Output is correct |
64 |
Correct |
847 ms |
28436 KB |
Output is correct |
65 |
Correct |
828 ms |
28528 KB |
Output is correct |
66 |
Correct |
845 ms |
28528 KB |
Output is correct |
67 |
Correct |
0 ms |
348 KB |
Output is correct |
68 |
Correct |
3 ms |
604 KB |
Output is correct |
69 |
Correct |
3 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 |
3 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 |
2 ms |
604 KB |
Output is correct |
79 |
Correct |
3 ms |
604 KB |
Output is correct |
80 |
Correct |
3 ms |
604 KB |
Output is correct |
81 |
Correct |
0 ms |
348 KB |
Output is correct |
82 |
Correct |
3 ms |
604 KB |
Output is correct |
83 |
Correct |
3 ms |
604 KB |
Output is correct |
84 |
Correct |
3 ms |
604 KB |
Output is correct |
85 |
Correct |
3 ms |
604 KB |
Output is correct |
86 |
Correct |
3 ms |
604 KB |
Output is correct |
87 |
Correct |
2 ms |
604 KB |
Output is correct |
88 |
Correct |
3 ms |
604 KB |
Output is correct |
89 |
Correct |
0 ms |
348 KB |
Output is correct |
90 |
Correct |
4 ms |
616 KB |
Output is correct |
91 |
Correct |
3 ms |
604 KB |
Output is correct |
92 |
Correct |
3 ms |
604 KB |
Output is correct |
93 |
Correct |
3 ms |
604 KB |
Output is correct |
94 |
Correct |
3 ms |
604 KB |
Output is correct |
95 |
Correct |
3 ms |
572 KB |
Output is correct |
96 |
Correct |
3 ms |
604 KB |
Output is correct |
97 |
Correct |
3 ms |
604 KB |
Output is correct |
98 |
Correct |
3 ms |
604 KB |
Output is correct |
99 |
Correct |
3 ms |
604 KB |
Output is correct |
100 |
Correct |
3 ms |
604 KB |
Output is correct |
101 |
Correct |
3 ms |
604 KB |
Output is correct |
102 |
Correct |
3 ms |
604 KB |
Output is correct |
103 |
Correct |
0 ms |
348 KB |
Output is correct |
104 |
Correct |
4 ms |
604 KB |
Output is correct |
105 |
Correct |
3 ms |
604 KB |
Output is correct |
106 |
Correct |
4 ms |
524 KB |
Output is correct |
107 |
Correct |
3 ms |
604 KB |
Output is correct |
108 |
Correct |
3 ms |
676 KB |
Output is correct |
109 |
Correct |
3 ms |
604 KB |
Output is correct |
110 |
Correct |
3 ms |
604 KB |
Output is correct |
111 |
Correct |
0 ms |
348 KB |
Output is correct |
112 |
Correct |
979 ms |
28568 KB |
Output is correct |
113 |
Execution timed out |
1012 ms |
28380 KB |
Time limit exceeded |
114 |
Halted |
0 ms |
0 KB |
- |