#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];
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++) {
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4696 KB |
Output is correct |
2 |
Correct |
3 ms |
4696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4696 KB |
Output is correct |
2 |
Correct |
3 ms |
4696 KB |
Output is correct |
3 |
Correct |
3 ms |
4696 KB |
Output is correct |
4 |
Correct |
3 ms |
4700 KB |
Output is correct |
5 |
Correct |
3 ms |
4748 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 |
4696 KB |
Output is correct |
10 |
Correct |
3 ms |
4700 KB |
Output is correct |
11 |
Correct |
3 ms |
4700 KB |
Output is correct |
12 |
Correct |
3 ms |
4700 KB |
Output is correct |
13 |
Correct |
3 ms |
4700 KB |
Output is correct |
14 |
Correct |
3 ms |
4700 KB |
Output is correct |
15 |
Correct |
3 ms |
4700 KB |
Output is correct |
16 |
Correct |
3 ms |
4956 KB |
Output is correct |
17 |
Correct |
3 ms |
4700 KB |
Output is correct |
18 |
Correct |
3 ms |
4744 KB |
Output is correct |
19 |
Correct |
3 ms |
4700 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 |
4700 KB |
Output is correct |
24 |
Correct |
3 ms |
4744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4700 KB |
Output is correct |
2 |
Correct |
312 ms |
25604 KB |
Output is correct |
3 |
Correct |
301 ms |
25788 KB |
Output is correct |
4 |
Correct |
323 ms |
24752 KB |
Output is correct |
5 |
Correct |
305 ms |
25648 KB |
Output is correct |
6 |
Correct |
329 ms |
26352 KB |
Output is correct |
7 |
Correct |
309 ms |
26780 KB |
Output is correct |
8 |
Correct |
288 ms |
25024 KB |
Output is correct |
9 |
Correct |
310 ms |
24880 KB |
Output is correct |
10 |
Correct |
312 ms |
26044 KB |
Output is correct |
11 |
Correct |
302 ms |
24880 KB |
Output is correct |
12 |
Correct |
300 ms |
26328 KB |
Output is correct |
13 |
Correct |
319 ms |
26140 KB |
Output is correct |
14 |
Correct |
296 ms |
26048 KB |
Output is correct |
15 |
Correct |
314 ms |
26300 KB |
Output is correct |
16 |
Correct |
305 ms |
25832 KB |
Output is correct |
17 |
Correct |
309 ms |
26300 KB |
Output is correct |
18 |
Correct |
308 ms |
25340 KB |
Output is correct |
19 |
Correct |
296 ms |
25828 KB |
Output is correct |
20 |
Correct |
268 ms |
26336 KB |
Output is correct |
21 |
Correct |
293 ms |
25792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4696 KB |
Output is correct |
2 |
Correct |
263 ms |
25232 KB |
Output is correct |
3 |
Correct |
216 ms |
24772 KB |
Output is correct |
4 |
Correct |
290 ms |
25768 KB |
Output is correct |
5 |
Correct |
267 ms |
24272 KB |
Output is correct |
6 |
Correct |
225 ms |
24032 KB |
Output is correct |
7 |
Correct |
219 ms |
25028 KB |
Output is correct |
8 |
Correct |
304 ms |
25436 KB |
Output is correct |
9 |
Correct |
303 ms |
25272 KB |
Output is correct |
10 |
Correct |
257 ms |
25452 KB |
Output is correct |
11 |
Correct |
238 ms |
24624 KB |
Output is correct |
12 |
Correct |
214 ms |
24984 KB |
Output is correct |
13 |
Correct |
255 ms |
25576 KB |
Output is correct |
14 |
Correct |
228 ms |
23932 KB |
Output is correct |
15 |
Correct |
272 ms |
24688 KB |
Output is correct |
16 |
Correct |
247 ms |
24072 KB |
Output is correct |
17 |
Correct |
250 ms |
24508 KB |
Output is correct |
18 |
Correct |
235 ms |
25184 KB |
Output is correct |
19 |
Correct |
224 ms |
23996 KB |
Output is correct |
20 |
Correct |
220 ms |
24900 KB |
Output is correct |
21 |
Correct |
240 ms |
24348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4700 KB |
Output is correct |
2 |
Correct |
4 ms |
4952 KB |
Output is correct |
3 |
Correct |
4 ms |
4700 KB |
Output is correct |
4 |
Correct |
4 ms |
4696 KB |
Output is correct |
5 |
Correct |
4 ms |
4696 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 |
4700 KB |
Output is correct |
11 |
Correct |
4 ms |
4736 KB |
Output is correct |
12 |
Correct |
4 ms |
4700 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 |
4696 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4696 KB |
Output is correct |
2 |
Correct |
3 ms |
4696 KB |
Output is correct |
3 |
Correct |
3 ms |
4696 KB |
Output is correct |
4 |
Correct |
3 ms |
4700 KB |
Output is correct |
5 |
Correct |
3 ms |
4748 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 |
4696 KB |
Output is correct |
10 |
Correct |
3 ms |
4700 KB |
Output is correct |
11 |
Correct |
3 ms |
4700 KB |
Output is correct |
12 |
Correct |
3 ms |
4700 KB |
Output is correct |
13 |
Correct |
3 ms |
4700 KB |
Output is correct |
14 |
Correct |
3 ms |
4700 KB |
Output is correct |
15 |
Correct |
3 ms |
4700 KB |
Output is correct |
16 |
Correct |
3 ms |
4956 KB |
Output is correct |
17 |
Correct |
3 ms |
4700 KB |
Output is correct |
18 |
Correct |
3 ms |
4744 KB |
Output is correct |
19 |
Correct |
3 ms |
4700 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 |
4700 KB |
Output is correct |
24 |
Correct |
3 ms |
4744 KB |
Output is correct |
25 |
Correct |
3 ms |
4700 KB |
Output is correct |
26 |
Correct |
4 ms |
4952 KB |
Output is correct |
27 |
Correct |
4 ms |
4700 KB |
Output is correct |
28 |
Correct |
4 ms |
4696 KB |
Output is correct |
29 |
Correct |
4 ms |
4696 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 |
4700 KB |
Output is correct |
35 |
Correct |
4 ms |
4736 KB |
Output is correct |
36 |
Correct |
4 ms |
4700 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 |
4696 KB |
Output isn't correct |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4696 KB |
Output is correct |
2 |
Correct |
263 ms |
25232 KB |
Output is correct |
3 |
Correct |
216 ms |
24772 KB |
Output is correct |
4 |
Correct |
290 ms |
25768 KB |
Output is correct |
5 |
Correct |
267 ms |
24272 KB |
Output is correct |
6 |
Correct |
225 ms |
24032 KB |
Output is correct |
7 |
Correct |
219 ms |
25028 KB |
Output is correct |
8 |
Correct |
304 ms |
25436 KB |
Output is correct |
9 |
Correct |
303 ms |
25272 KB |
Output is correct |
10 |
Correct |
257 ms |
25452 KB |
Output is correct |
11 |
Correct |
238 ms |
24624 KB |
Output is correct |
12 |
Correct |
214 ms |
24984 KB |
Output is correct |
13 |
Correct |
255 ms |
25576 KB |
Output is correct |
14 |
Correct |
228 ms |
23932 KB |
Output is correct |
15 |
Correct |
272 ms |
24688 KB |
Output is correct |
16 |
Correct |
247 ms |
24072 KB |
Output is correct |
17 |
Correct |
250 ms |
24508 KB |
Output is correct |
18 |
Correct |
235 ms |
25184 KB |
Output is correct |
19 |
Correct |
224 ms |
23996 KB |
Output is correct |
20 |
Correct |
220 ms |
24900 KB |
Output is correct |
21 |
Correct |
240 ms |
24348 KB |
Output is correct |
22 |
Correct |
3 ms |
4700 KB |
Output is correct |
23 |
Correct |
4 ms |
4952 KB |
Output is correct |
24 |
Correct |
4 ms |
4700 KB |
Output is correct |
25 |
Correct |
4 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 |
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 |
4700 KB |
Output is correct |
32 |
Correct |
4 ms |
4736 KB |
Output is correct |
33 |
Correct |
4 ms |
4700 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 |
4696 KB |
Output isn't correct |
37 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4696 KB |
Output is correct |
2 |
Correct |
3 ms |
4696 KB |
Output is correct |
3 |
Correct |
3 ms |
4696 KB |
Output is correct |
4 |
Correct |
3 ms |
4700 KB |
Output is correct |
5 |
Correct |
3 ms |
4748 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 |
4696 KB |
Output is correct |
10 |
Correct |
3 ms |
4700 KB |
Output is correct |
11 |
Correct |
3 ms |
4700 KB |
Output is correct |
12 |
Correct |
3 ms |
4700 KB |
Output is correct |
13 |
Correct |
3 ms |
4700 KB |
Output is correct |
14 |
Correct |
3 ms |
4700 KB |
Output is correct |
15 |
Correct |
3 ms |
4700 KB |
Output is correct |
16 |
Correct |
3 ms |
4956 KB |
Output is correct |
17 |
Correct |
3 ms |
4700 KB |
Output is correct |
18 |
Correct |
3 ms |
4744 KB |
Output is correct |
19 |
Correct |
3 ms |
4700 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 |
4700 KB |
Output is correct |
24 |
Correct |
3 ms |
4744 KB |
Output is correct |
25 |
Correct |
3 ms |
4700 KB |
Output is correct |
26 |
Correct |
312 ms |
25604 KB |
Output is correct |
27 |
Correct |
301 ms |
25788 KB |
Output is correct |
28 |
Correct |
323 ms |
24752 KB |
Output is correct |
29 |
Correct |
305 ms |
25648 KB |
Output is correct |
30 |
Correct |
329 ms |
26352 KB |
Output is correct |
31 |
Correct |
309 ms |
26780 KB |
Output is correct |
32 |
Correct |
288 ms |
25024 KB |
Output is correct |
33 |
Correct |
310 ms |
24880 KB |
Output is correct |
34 |
Correct |
312 ms |
26044 KB |
Output is correct |
35 |
Correct |
302 ms |
24880 KB |
Output is correct |
36 |
Correct |
300 ms |
26328 KB |
Output is correct |
37 |
Correct |
319 ms |
26140 KB |
Output is correct |
38 |
Correct |
296 ms |
26048 KB |
Output is correct |
39 |
Correct |
314 ms |
26300 KB |
Output is correct |
40 |
Correct |
305 ms |
25832 KB |
Output is correct |
41 |
Correct |
309 ms |
26300 KB |
Output is correct |
42 |
Correct |
308 ms |
25340 KB |
Output is correct |
43 |
Correct |
296 ms |
25828 KB |
Output is correct |
44 |
Correct |
268 ms |
26336 KB |
Output is correct |
45 |
Correct |
293 ms |
25792 KB |
Output is correct |
46 |
Correct |
3 ms |
4696 KB |
Output is correct |
47 |
Correct |
263 ms |
25232 KB |
Output is correct |
48 |
Correct |
216 ms |
24772 KB |
Output is correct |
49 |
Correct |
290 ms |
25768 KB |
Output is correct |
50 |
Correct |
267 ms |
24272 KB |
Output is correct |
51 |
Correct |
225 ms |
24032 KB |
Output is correct |
52 |
Correct |
219 ms |
25028 KB |
Output is correct |
53 |
Correct |
304 ms |
25436 KB |
Output is correct |
54 |
Correct |
303 ms |
25272 KB |
Output is correct |
55 |
Correct |
257 ms |
25452 KB |
Output is correct |
56 |
Correct |
238 ms |
24624 KB |
Output is correct |
57 |
Correct |
214 ms |
24984 KB |
Output is correct |
58 |
Correct |
255 ms |
25576 KB |
Output is correct |
59 |
Correct |
228 ms |
23932 KB |
Output is correct |
60 |
Correct |
272 ms |
24688 KB |
Output is correct |
61 |
Correct |
247 ms |
24072 KB |
Output is correct |
62 |
Correct |
250 ms |
24508 KB |
Output is correct |
63 |
Correct |
235 ms |
25184 KB |
Output is correct |
64 |
Correct |
224 ms |
23996 KB |
Output is correct |
65 |
Correct |
220 ms |
24900 KB |
Output is correct |
66 |
Correct |
240 ms |
24348 KB |
Output is correct |
67 |
Correct |
3 ms |
4700 KB |
Output is correct |
68 |
Correct |
4 ms |
4952 KB |
Output is correct |
69 |
Correct |
4 ms |
4700 KB |
Output is correct |
70 |
Correct |
4 ms |
4696 KB |
Output is correct |
71 |
Correct |
4 ms |
4696 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 |
4700 KB |
Output is correct |
77 |
Correct |
4 ms |
4736 KB |
Output is correct |
78 |
Correct |
4 ms |
4700 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 |
4696 KB |
Output isn't correct |
82 |
Halted |
0 ms |
0 KB |
- |