#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
#define ll long long
using namespace __gnu_pbds;
using namespace std;
int n, in, ord[300010], idx;
ll fac[3000010], mod = 1e9+7, ans;
vector<pair<int, int>> v;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ordered_set s;
int main() {
cin.tie(0)->sync_with_stdio(0);
fac[0] = 1;
for(int i=1; i<300010; i++) {
fac[i] = i*fac[i-1];
fac[i] %= mod;
}
cin >> n;
for(int i=1; i<=n; i++) {
cin >> in;
v.push_back({in, i});
}
sort(v.begin(), v.end());
for(int i=0; i<v.size(); i++) {
ord[v[i].second] = i;
}
for(int i=1; i<=n; i++) {
idx = s.order_of_key(ord[i]);
ans += ((ord[i]-idx)*fac[n-i])%mod;
ans %= mod;
s.insert(ord[i]);
}
cout << ans+1;
return 0;
}
Compilation message
Crypto.cpp: In function 'int main()':
Crypto.cpp:30:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for(int i=0; i<v.size(); i++) {
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4696 KB |
Output is correct |
2 |
Correct |
3 ms |
4700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4696 KB |
Output is correct |
2 |
Correct |
3 ms |
4700 KB |
Output is correct |
3 |
Correct |
3 ms |
4700 KB |
Output is correct |
4 |
Correct |
3 ms |
4700 KB |
Output is correct |
5 |
Correct |
3 ms |
4700 KB |
Output is correct |
6 |
Correct |
3 ms |
4700 KB |
Output is correct |
7 |
Correct |
3 ms |
4700 KB |
Output is correct |
8 |
Correct |
3 ms |
4700 KB |
Output is correct |
9 |
Correct |
3 ms |
4700 KB |
Output is correct |
10 |
Correct |
3 ms |
4696 KB |
Output is correct |
11 |
Correct |
3 ms |
4700 KB |
Output is correct |
12 |
Correct |
3 ms |
4744 KB |
Output is correct |
13 |
Correct |
3 ms |
4700 KB |
Output is correct |
14 |
Correct |
3 ms |
4740 KB |
Output is correct |
15 |
Correct |
3 ms |
4744 KB |
Output is correct |
16 |
Correct |
3 ms |
4696 KB |
Output is correct |
17 |
Correct |
3 ms |
4744 KB |
Output is correct |
18 |
Correct |
3 ms |
4700 KB |
Output is correct |
19 |
Correct |
3 ms |
4696 KB |
Output is correct |
20 |
Correct |
3 ms |
4700 KB |
Output is correct |
21 |
Correct |
3 ms |
4700 KB |
Output is correct |
22 |
Correct |
3 ms |
4700 KB |
Output is correct |
23 |
Correct |
3 ms |
4736 KB |
Output is correct |
24 |
Correct |
3 ms |
4700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4700 KB |
Output is correct |
2 |
Correct |
310 ms |
24908 KB |
Output is correct |
3 |
Correct |
320 ms |
24508 KB |
Output is correct |
4 |
Correct |
291 ms |
24756 KB |
Output is correct |
5 |
Correct |
328 ms |
25124 KB |
Output is correct |
6 |
Correct |
314 ms |
25792 KB |
Output is correct |
7 |
Correct |
308 ms |
24596 KB |
Output is correct |
8 |
Correct |
302 ms |
23996 KB |
Output is correct |
9 |
Correct |
299 ms |
25004 KB |
Output is correct |
10 |
Correct |
315 ms |
25336 KB |
Output is correct |
11 |
Correct |
301 ms |
24320 KB |
Output is correct |
12 |
Correct |
312 ms |
24080 KB |
Output is correct |
13 |
Correct |
309 ms |
25280 KB |
Output is correct |
14 |
Correct |
340 ms |
26284 KB |
Output is correct |
15 |
Correct |
309 ms |
24196 KB |
Output is correct |
16 |
Correct |
312 ms |
24092 KB |
Output is correct |
17 |
Correct |
309 ms |
24468 KB |
Output is correct |
18 |
Correct |
294 ms |
25260 KB |
Output is correct |
19 |
Correct |
316 ms |
24452 KB |
Output is correct |
20 |
Correct |
318 ms |
24764 KB |
Output is correct |
21 |
Correct |
316 ms |
23996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4700 KB |
Output is correct |
2 |
Correct |
246 ms |
25152 KB |
Output is correct |
3 |
Correct |
218 ms |
23484 KB |
Output is correct |
4 |
Correct |
280 ms |
23488 KB |
Output is correct |
5 |
Correct |
261 ms |
24256 KB |
Output is correct |
6 |
Correct |
225 ms |
24508 KB |
Output is correct |
7 |
Correct |
220 ms |
23476 KB |
Output is correct |
8 |
Correct |
296 ms |
24416 KB |
Output is correct |
9 |
Correct |
299 ms |
23428 KB |
Output is correct |
10 |
Correct |
257 ms |
25020 KB |
Output is correct |
11 |
Correct |
232 ms |
24768 KB |
Output is correct |
12 |
Correct |
220 ms |
24664 KB |
Output is correct |
13 |
Correct |
252 ms |
24268 KB |
Output is correct |
14 |
Correct |
225 ms |
23592 KB |
Output is correct |
15 |
Correct |
263 ms |
25012 KB |
Output is correct |
16 |
Correct |
240 ms |
25172 KB |
Output is correct |
17 |
Correct |
244 ms |
23992 KB |
Output is correct |
18 |
Correct |
230 ms |
24248 KB |
Output is correct |
19 |
Correct |
221 ms |
24768 KB |
Output is correct |
20 |
Correct |
221 ms |
24256 KB |
Output is correct |
21 |
Correct |
243 ms |
25128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4696 KB |
Output is correct |
2 |
Correct |
4 ms |
4696 KB |
Output is correct |
3 |
Correct |
4 ms |
4700 KB |
Output is correct |
4 |
Correct |
4 ms |
4756 KB |
Output is correct |
5 |
Correct |
4 ms |
4700 KB |
Output is correct |
6 |
Correct |
4 ms |
4700 KB |
Output is correct |
7 |
Correct |
4 ms |
4700 KB |
Output is correct |
8 |
Correct |
4 ms |
4700 KB |
Output is correct |
9 |
Correct |
4 ms |
4700 KB |
Output is correct |
10 |
Correct |
4 ms |
4752 KB |
Output is correct |
11 |
Correct |
4 ms |
4700 KB |
Output is correct |
12 |
Correct |
4 ms |
4760 KB |
Output is correct |
13 |
Correct |
4 ms |
4700 KB |
Output is correct |
14 |
Correct |
4 ms |
4700 KB |
Output is correct |
15 |
Incorrect |
3 ms |
4700 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4696 KB |
Output is correct |
2 |
Correct |
3 ms |
4700 KB |
Output is correct |
3 |
Correct |
3 ms |
4700 KB |
Output is correct |
4 |
Correct |
3 ms |
4700 KB |
Output is correct |
5 |
Correct |
3 ms |
4700 KB |
Output is correct |
6 |
Correct |
3 ms |
4700 KB |
Output is correct |
7 |
Correct |
3 ms |
4700 KB |
Output is correct |
8 |
Correct |
3 ms |
4700 KB |
Output is correct |
9 |
Correct |
3 ms |
4700 KB |
Output is correct |
10 |
Correct |
3 ms |
4696 KB |
Output is correct |
11 |
Correct |
3 ms |
4700 KB |
Output is correct |
12 |
Correct |
3 ms |
4744 KB |
Output is correct |
13 |
Correct |
3 ms |
4700 KB |
Output is correct |
14 |
Correct |
3 ms |
4740 KB |
Output is correct |
15 |
Correct |
3 ms |
4744 KB |
Output is correct |
16 |
Correct |
3 ms |
4696 KB |
Output is correct |
17 |
Correct |
3 ms |
4744 KB |
Output is correct |
18 |
Correct |
3 ms |
4700 KB |
Output is correct |
19 |
Correct |
3 ms |
4696 KB |
Output is correct |
20 |
Correct |
3 ms |
4700 KB |
Output is correct |
21 |
Correct |
3 ms |
4700 KB |
Output is correct |
22 |
Correct |
3 ms |
4700 KB |
Output is correct |
23 |
Correct |
3 ms |
4736 KB |
Output is correct |
24 |
Correct |
3 ms |
4700 KB |
Output is correct |
25 |
Correct |
3 ms |
4696 KB |
Output is correct |
26 |
Correct |
4 ms |
4696 KB |
Output is correct |
27 |
Correct |
4 ms |
4700 KB |
Output is correct |
28 |
Correct |
4 ms |
4756 KB |
Output is correct |
29 |
Correct |
4 ms |
4700 KB |
Output is correct |
30 |
Correct |
4 ms |
4700 KB |
Output is correct |
31 |
Correct |
4 ms |
4700 KB |
Output is correct |
32 |
Correct |
4 ms |
4700 KB |
Output is correct |
33 |
Correct |
4 ms |
4700 KB |
Output is correct |
34 |
Correct |
4 ms |
4752 KB |
Output is correct |
35 |
Correct |
4 ms |
4700 KB |
Output is correct |
36 |
Correct |
4 ms |
4760 KB |
Output is correct |
37 |
Correct |
4 ms |
4700 KB |
Output is correct |
38 |
Correct |
4 ms |
4700 KB |
Output is correct |
39 |
Incorrect |
3 ms |
4700 KB |
Output isn't correct |
40 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4700 KB |
Output is correct |
2 |
Correct |
246 ms |
25152 KB |
Output is correct |
3 |
Correct |
218 ms |
23484 KB |
Output is correct |
4 |
Correct |
280 ms |
23488 KB |
Output is correct |
5 |
Correct |
261 ms |
24256 KB |
Output is correct |
6 |
Correct |
225 ms |
24508 KB |
Output is correct |
7 |
Correct |
220 ms |
23476 KB |
Output is correct |
8 |
Correct |
296 ms |
24416 KB |
Output is correct |
9 |
Correct |
299 ms |
23428 KB |
Output is correct |
10 |
Correct |
257 ms |
25020 KB |
Output is correct |
11 |
Correct |
232 ms |
24768 KB |
Output is correct |
12 |
Correct |
220 ms |
24664 KB |
Output is correct |
13 |
Correct |
252 ms |
24268 KB |
Output is correct |
14 |
Correct |
225 ms |
23592 KB |
Output is correct |
15 |
Correct |
263 ms |
25012 KB |
Output is correct |
16 |
Correct |
240 ms |
25172 KB |
Output is correct |
17 |
Correct |
244 ms |
23992 KB |
Output is correct |
18 |
Correct |
230 ms |
24248 KB |
Output is correct |
19 |
Correct |
221 ms |
24768 KB |
Output is correct |
20 |
Correct |
221 ms |
24256 KB |
Output is correct |
21 |
Correct |
243 ms |
25128 KB |
Output is correct |
22 |
Correct |
3 ms |
4696 KB |
Output is correct |
23 |
Correct |
4 ms |
4696 KB |
Output is correct |
24 |
Correct |
4 ms |
4700 KB |
Output is correct |
25 |
Correct |
4 ms |
4756 KB |
Output is correct |
26 |
Correct |
4 ms |
4700 KB |
Output is correct |
27 |
Correct |
4 ms |
4700 KB |
Output is correct |
28 |
Correct |
4 ms |
4700 KB |
Output is correct |
29 |
Correct |
4 ms |
4700 KB |
Output is correct |
30 |
Correct |
4 ms |
4700 KB |
Output is correct |
31 |
Correct |
4 ms |
4752 KB |
Output is correct |
32 |
Correct |
4 ms |
4700 KB |
Output is correct |
33 |
Correct |
4 ms |
4760 KB |
Output is correct |
34 |
Correct |
4 ms |
4700 KB |
Output is correct |
35 |
Correct |
4 ms |
4700 KB |
Output is correct |
36 |
Incorrect |
3 ms |
4700 KB |
Output isn't correct |
37 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4696 KB |
Output is correct |
2 |
Correct |
3 ms |
4700 KB |
Output is correct |
3 |
Correct |
3 ms |
4700 KB |
Output is correct |
4 |
Correct |
3 ms |
4700 KB |
Output is correct |
5 |
Correct |
3 ms |
4700 KB |
Output is correct |
6 |
Correct |
3 ms |
4700 KB |
Output is correct |
7 |
Correct |
3 ms |
4700 KB |
Output is correct |
8 |
Correct |
3 ms |
4700 KB |
Output is correct |
9 |
Correct |
3 ms |
4700 KB |
Output is correct |
10 |
Correct |
3 ms |
4696 KB |
Output is correct |
11 |
Correct |
3 ms |
4700 KB |
Output is correct |
12 |
Correct |
3 ms |
4744 KB |
Output is correct |
13 |
Correct |
3 ms |
4700 KB |
Output is correct |
14 |
Correct |
3 ms |
4740 KB |
Output is correct |
15 |
Correct |
3 ms |
4744 KB |
Output is correct |
16 |
Correct |
3 ms |
4696 KB |
Output is correct |
17 |
Correct |
3 ms |
4744 KB |
Output is correct |
18 |
Correct |
3 ms |
4700 KB |
Output is correct |
19 |
Correct |
3 ms |
4696 KB |
Output is correct |
20 |
Correct |
3 ms |
4700 KB |
Output is correct |
21 |
Correct |
3 ms |
4700 KB |
Output is correct |
22 |
Correct |
3 ms |
4700 KB |
Output is correct |
23 |
Correct |
3 ms |
4736 KB |
Output is correct |
24 |
Correct |
3 ms |
4700 KB |
Output is correct |
25 |
Correct |
3 ms |
4700 KB |
Output is correct |
26 |
Correct |
310 ms |
24908 KB |
Output is correct |
27 |
Correct |
320 ms |
24508 KB |
Output is correct |
28 |
Correct |
291 ms |
24756 KB |
Output is correct |
29 |
Correct |
328 ms |
25124 KB |
Output is correct |
30 |
Correct |
314 ms |
25792 KB |
Output is correct |
31 |
Correct |
308 ms |
24596 KB |
Output is correct |
32 |
Correct |
302 ms |
23996 KB |
Output is correct |
33 |
Correct |
299 ms |
25004 KB |
Output is correct |
34 |
Correct |
315 ms |
25336 KB |
Output is correct |
35 |
Correct |
301 ms |
24320 KB |
Output is correct |
36 |
Correct |
312 ms |
24080 KB |
Output is correct |
37 |
Correct |
309 ms |
25280 KB |
Output is correct |
38 |
Correct |
340 ms |
26284 KB |
Output is correct |
39 |
Correct |
309 ms |
24196 KB |
Output is correct |
40 |
Correct |
312 ms |
24092 KB |
Output is correct |
41 |
Correct |
309 ms |
24468 KB |
Output is correct |
42 |
Correct |
294 ms |
25260 KB |
Output is correct |
43 |
Correct |
316 ms |
24452 KB |
Output is correct |
44 |
Correct |
318 ms |
24764 KB |
Output is correct |
45 |
Correct |
316 ms |
23996 KB |
Output is correct |
46 |
Correct |
3 ms |
4700 KB |
Output is correct |
47 |
Correct |
246 ms |
25152 KB |
Output is correct |
48 |
Correct |
218 ms |
23484 KB |
Output is correct |
49 |
Correct |
280 ms |
23488 KB |
Output is correct |
50 |
Correct |
261 ms |
24256 KB |
Output is correct |
51 |
Correct |
225 ms |
24508 KB |
Output is correct |
52 |
Correct |
220 ms |
23476 KB |
Output is correct |
53 |
Correct |
296 ms |
24416 KB |
Output is correct |
54 |
Correct |
299 ms |
23428 KB |
Output is correct |
55 |
Correct |
257 ms |
25020 KB |
Output is correct |
56 |
Correct |
232 ms |
24768 KB |
Output is correct |
57 |
Correct |
220 ms |
24664 KB |
Output is correct |
58 |
Correct |
252 ms |
24268 KB |
Output is correct |
59 |
Correct |
225 ms |
23592 KB |
Output is correct |
60 |
Correct |
263 ms |
25012 KB |
Output is correct |
61 |
Correct |
240 ms |
25172 KB |
Output is correct |
62 |
Correct |
244 ms |
23992 KB |
Output is correct |
63 |
Correct |
230 ms |
24248 KB |
Output is correct |
64 |
Correct |
221 ms |
24768 KB |
Output is correct |
65 |
Correct |
221 ms |
24256 KB |
Output is correct |
66 |
Correct |
243 ms |
25128 KB |
Output is correct |
67 |
Correct |
3 ms |
4696 KB |
Output is correct |
68 |
Correct |
4 ms |
4696 KB |
Output is correct |
69 |
Correct |
4 ms |
4700 KB |
Output is correct |
70 |
Correct |
4 ms |
4756 KB |
Output is correct |
71 |
Correct |
4 ms |
4700 KB |
Output is correct |
72 |
Correct |
4 ms |
4700 KB |
Output is correct |
73 |
Correct |
4 ms |
4700 KB |
Output is correct |
74 |
Correct |
4 ms |
4700 KB |
Output is correct |
75 |
Correct |
4 ms |
4700 KB |
Output is correct |
76 |
Correct |
4 ms |
4752 KB |
Output is correct |
77 |
Correct |
4 ms |
4700 KB |
Output is correct |
78 |
Correct |
4 ms |
4760 KB |
Output is correct |
79 |
Correct |
4 ms |
4700 KB |
Output is correct |
80 |
Correct |
4 ms |
4700 KB |
Output is correct |
81 |
Incorrect |
3 ms |
4700 KB |
Output isn't correct |
82 |
Halted |
0 ms |
0 KB |
- |