#include <bits/stdc++.h>
#define fo(i, d, c) for (int i = d; i <= c; i++)
#define fod(i, c, d) for (int i = c; i >= d; i--)
#define maxn 1000010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout << "\n";
#define int long long
#define inf (int)1e18
#define pii pair<int, int>
#define vii vector<pii>
#define lb(x) x & -x
#define bit(i, j) ((i >> j) & 1)
#define offbit(i, j) (i ^ (1LL << j))
#define onbit(i, j) (i | (1LL << j))
#define vi vector<int>
#define all(x) x.begin(),x.end()
template <typename T1, typename T2>
bool minimize(T1 &a, T2 b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <typename T1, typename T2>
bool maximize(T1 &a, T2 b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
using namespace std;
const int nsqrt = 450;
const int mod = 1e9 + 7;
int n,a[maxn];
vi nen;
int f[maxn];
struct BIT
{
int t[maxn];
void up(int x,int val)
{
for( ; x < maxn ; x += lb(x)) t[x] += val;
}
int get(int x)
{
int ans = 0;
for( ; x ; x -= lb(x)) ans += t[x];
return ans;
}
}t;
main()
{
#define name "TASK"
if (fopen(name ".inp", "r"))
{
freopen(name ".inp", "r", stdin);
freopen(name ".out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
fo(i,1,n)
{
cin >> a[i];
nen.pb(a[i]);
}
sort(all(nen));
nen.erase(unique(all(nen)),nen.end());
fo(i,1,n) a[i] = lower_bound(all(nen),a[i]) - nen.begin() + 1;
f[0] = 1;
fo(i,1,n) f[i] = f[i - 1] * i % mod;
int ans = 0;
fo(i,1,n)
{
ans = (ans + (a[i] - 1 - t.get(a[i] - 1)) * f[n - i] % mod) % mod;
t.up(a[i],1);
}
cout << ans + 1;
}
Compilation message
Crypto.cpp:60:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
60 | main()
| ^~~~
Crypto.cpp: In function 'int main()':
Crypto.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
65 | freopen(name ".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Crypto.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
66 | freopen(name ".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8536 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
8664 KB |
Output is correct |
11 |
Correct |
1 ms |
8660 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
8540 KB |
Output is correct |
15 |
Correct |
1 ms |
8700 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
18 |
Correct |
1 ms |
8796 KB |
Output is correct |
19 |
Correct |
1 ms |
8540 KB |
Output is correct |
20 |
Correct |
1 ms |
8540 KB |
Output is correct |
21 |
Correct |
1 ms |
8540 KB |
Output is correct |
22 |
Correct |
1 ms |
8540 KB |
Output is correct |
23 |
Correct |
1 ms |
8540 KB |
Output is correct |
24 |
Correct |
1 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
50 ms |
17760 KB |
Output is correct |
3 |
Correct |
49 ms |
17496 KB |
Output is correct |
4 |
Correct |
50 ms |
16316 KB |
Output is correct |
5 |
Correct |
56 ms |
17348 KB |
Output is correct |
6 |
Correct |
51 ms |
16320 KB |
Output is correct |
7 |
Correct |
53 ms |
18372 KB |
Output is correct |
8 |
Correct |
53 ms |
18884 KB |
Output is correct |
9 |
Correct |
55 ms |
18628 KB |
Output is correct |
10 |
Correct |
54 ms |
18120 KB |
Output is correct |
11 |
Correct |
62 ms |
18628 KB |
Output is correct |
12 |
Correct |
49 ms |
17596 KB |
Output is correct |
13 |
Correct |
51 ms |
17596 KB |
Output is correct |
14 |
Correct |
48 ms |
16316 KB |
Output is correct |
15 |
Correct |
56 ms |
19652 KB |
Output is correct |
16 |
Correct |
54 ms |
18804 KB |
Output is correct |
17 |
Correct |
55 ms |
19140 KB |
Output is correct |
18 |
Correct |
54 ms |
18112 KB |
Output is correct |
19 |
Correct |
51 ms |
17340 KB |
Output is correct |
20 |
Correct |
48 ms |
18112 KB |
Output is correct |
21 |
Correct |
48 ms |
16676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
46 ms |
18412 KB |
Output is correct |
3 |
Correct |
46 ms |
18696 KB |
Output is correct |
4 |
Correct |
46 ms |
17600 KB |
Output is correct |
5 |
Correct |
45 ms |
17852 KB |
Output is correct |
6 |
Correct |
45 ms |
17852 KB |
Output is correct |
7 |
Correct |
49 ms |
16572 KB |
Output is correct |
8 |
Correct |
50 ms |
18120 KB |
Output is correct |
9 |
Correct |
50 ms |
17608 KB |
Output is correct |
10 |
Correct |
45 ms |
18884 KB |
Output is correct |
11 |
Correct |
44 ms |
17492 KB |
Output is correct |
12 |
Correct |
45 ms |
17604 KB |
Output is correct |
13 |
Correct |
49 ms |
17596 KB |
Output is correct |
14 |
Correct |
44 ms |
18368 KB |
Output is correct |
15 |
Correct |
46 ms |
18372 KB |
Output is correct |
16 |
Correct |
46 ms |
18336 KB |
Output is correct |
17 |
Correct |
45 ms |
18880 KB |
Output is correct |
18 |
Correct |
44 ms |
18380 KB |
Output is correct |
19 |
Correct |
47 ms |
17772 KB |
Output is correct |
20 |
Correct |
44 ms |
17344 KB |
Output is correct |
21 |
Correct |
46 ms |
17816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
2 ms |
8788 KB |
Output is correct |
5 |
Correct |
2 ms |
8540 KB |
Output is correct |
6 |
Correct |
2 ms |
8676 KB |
Output is correct |
7 |
Correct |
2 ms |
8540 KB |
Output is correct |
8 |
Correct |
2 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8676 KB |
Output is correct |
10 |
Correct |
2 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
2 ms |
8540 KB |
Output is correct |
13 |
Correct |
2 ms |
8540 KB |
Output is correct |
14 |
Correct |
2 ms |
8540 KB |
Output is correct |
15 |
Incorrect |
1 ms |
8540 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8536 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
8664 KB |
Output is correct |
11 |
Correct |
1 ms |
8660 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
8540 KB |
Output is correct |
15 |
Correct |
1 ms |
8700 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
18 |
Correct |
1 ms |
8796 KB |
Output is correct |
19 |
Correct |
1 ms |
8540 KB |
Output is correct |
20 |
Correct |
1 ms |
8540 KB |
Output is correct |
21 |
Correct |
1 ms |
8540 KB |
Output is correct |
22 |
Correct |
1 ms |
8540 KB |
Output is correct |
23 |
Correct |
1 ms |
8540 KB |
Output is correct |
24 |
Correct |
1 ms |
8540 KB |
Output is correct |
25 |
Correct |
1 ms |
8540 KB |
Output is correct |
26 |
Correct |
1 ms |
8540 KB |
Output is correct |
27 |
Correct |
1 ms |
8540 KB |
Output is correct |
28 |
Correct |
2 ms |
8788 KB |
Output is correct |
29 |
Correct |
2 ms |
8540 KB |
Output is correct |
30 |
Correct |
2 ms |
8676 KB |
Output is correct |
31 |
Correct |
2 ms |
8540 KB |
Output is correct |
32 |
Correct |
2 ms |
8540 KB |
Output is correct |
33 |
Correct |
1 ms |
8676 KB |
Output is correct |
34 |
Correct |
2 ms |
8540 KB |
Output is correct |
35 |
Correct |
1 ms |
8540 KB |
Output is correct |
36 |
Correct |
2 ms |
8540 KB |
Output is correct |
37 |
Correct |
2 ms |
8540 KB |
Output is correct |
38 |
Correct |
2 ms |
8540 KB |
Output is correct |
39 |
Incorrect |
1 ms |
8540 KB |
Output isn't correct |
40 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
46 ms |
18412 KB |
Output is correct |
3 |
Correct |
46 ms |
18696 KB |
Output is correct |
4 |
Correct |
46 ms |
17600 KB |
Output is correct |
5 |
Correct |
45 ms |
17852 KB |
Output is correct |
6 |
Correct |
45 ms |
17852 KB |
Output is correct |
7 |
Correct |
49 ms |
16572 KB |
Output is correct |
8 |
Correct |
50 ms |
18120 KB |
Output is correct |
9 |
Correct |
50 ms |
17608 KB |
Output is correct |
10 |
Correct |
45 ms |
18884 KB |
Output is correct |
11 |
Correct |
44 ms |
17492 KB |
Output is correct |
12 |
Correct |
45 ms |
17604 KB |
Output is correct |
13 |
Correct |
49 ms |
17596 KB |
Output is correct |
14 |
Correct |
44 ms |
18368 KB |
Output is correct |
15 |
Correct |
46 ms |
18372 KB |
Output is correct |
16 |
Correct |
46 ms |
18336 KB |
Output is correct |
17 |
Correct |
45 ms |
18880 KB |
Output is correct |
18 |
Correct |
44 ms |
18380 KB |
Output is correct |
19 |
Correct |
47 ms |
17772 KB |
Output is correct |
20 |
Correct |
44 ms |
17344 KB |
Output is correct |
21 |
Correct |
46 ms |
17816 KB |
Output is correct |
22 |
Correct |
1 ms |
8540 KB |
Output is correct |
23 |
Correct |
1 ms |
8540 KB |
Output is correct |
24 |
Correct |
1 ms |
8540 KB |
Output is correct |
25 |
Correct |
2 ms |
8788 KB |
Output is correct |
26 |
Correct |
2 ms |
8540 KB |
Output is correct |
27 |
Correct |
2 ms |
8676 KB |
Output is correct |
28 |
Correct |
2 ms |
8540 KB |
Output is correct |
29 |
Correct |
2 ms |
8540 KB |
Output is correct |
30 |
Correct |
1 ms |
8676 KB |
Output is correct |
31 |
Correct |
2 ms |
8540 KB |
Output is correct |
32 |
Correct |
1 ms |
8540 KB |
Output is correct |
33 |
Correct |
2 ms |
8540 KB |
Output is correct |
34 |
Correct |
2 ms |
8540 KB |
Output is correct |
35 |
Correct |
2 ms |
8540 KB |
Output is correct |
36 |
Incorrect |
1 ms |
8540 KB |
Output isn't correct |
37 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8536 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
8664 KB |
Output is correct |
11 |
Correct |
1 ms |
8660 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
8540 KB |
Output is correct |
15 |
Correct |
1 ms |
8700 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
18 |
Correct |
1 ms |
8796 KB |
Output is correct |
19 |
Correct |
1 ms |
8540 KB |
Output is correct |
20 |
Correct |
1 ms |
8540 KB |
Output is correct |
21 |
Correct |
1 ms |
8540 KB |
Output is correct |
22 |
Correct |
1 ms |
8540 KB |
Output is correct |
23 |
Correct |
1 ms |
8540 KB |
Output is correct |
24 |
Correct |
1 ms |
8540 KB |
Output is correct |
25 |
Correct |
1 ms |
8540 KB |
Output is correct |
26 |
Correct |
50 ms |
17760 KB |
Output is correct |
27 |
Correct |
49 ms |
17496 KB |
Output is correct |
28 |
Correct |
50 ms |
16316 KB |
Output is correct |
29 |
Correct |
56 ms |
17348 KB |
Output is correct |
30 |
Correct |
51 ms |
16320 KB |
Output is correct |
31 |
Correct |
53 ms |
18372 KB |
Output is correct |
32 |
Correct |
53 ms |
18884 KB |
Output is correct |
33 |
Correct |
55 ms |
18628 KB |
Output is correct |
34 |
Correct |
54 ms |
18120 KB |
Output is correct |
35 |
Correct |
62 ms |
18628 KB |
Output is correct |
36 |
Correct |
49 ms |
17596 KB |
Output is correct |
37 |
Correct |
51 ms |
17596 KB |
Output is correct |
38 |
Correct |
48 ms |
16316 KB |
Output is correct |
39 |
Correct |
56 ms |
19652 KB |
Output is correct |
40 |
Correct |
54 ms |
18804 KB |
Output is correct |
41 |
Correct |
55 ms |
19140 KB |
Output is correct |
42 |
Correct |
54 ms |
18112 KB |
Output is correct |
43 |
Correct |
51 ms |
17340 KB |
Output is correct |
44 |
Correct |
48 ms |
18112 KB |
Output is correct |
45 |
Correct |
48 ms |
16676 KB |
Output is correct |
46 |
Correct |
1 ms |
8536 KB |
Output is correct |
47 |
Correct |
46 ms |
18412 KB |
Output is correct |
48 |
Correct |
46 ms |
18696 KB |
Output is correct |
49 |
Correct |
46 ms |
17600 KB |
Output is correct |
50 |
Correct |
45 ms |
17852 KB |
Output is correct |
51 |
Correct |
45 ms |
17852 KB |
Output is correct |
52 |
Correct |
49 ms |
16572 KB |
Output is correct |
53 |
Correct |
50 ms |
18120 KB |
Output is correct |
54 |
Correct |
50 ms |
17608 KB |
Output is correct |
55 |
Correct |
45 ms |
18884 KB |
Output is correct |
56 |
Correct |
44 ms |
17492 KB |
Output is correct |
57 |
Correct |
45 ms |
17604 KB |
Output is correct |
58 |
Correct |
49 ms |
17596 KB |
Output is correct |
59 |
Correct |
44 ms |
18368 KB |
Output is correct |
60 |
Correct |
46 ms |
18372 KB |
Output is correct |
61 |
Correct |
46 ms |
18336 KB |
Output is correct |
62 |
Correct |
45 ms |
18880 KB |
Output is correct |
63 |
Correct |
44 ms |
18380 KB |
Output is correct |
64 |
Correct |
47 ms |
17772 KB |
Output is correct |
65 |
Correct |
44 ms |
17344 KB |
Output is correct |
66 |
Correct |
46 ms |
17816 KB |
Output is correct |
67 |
Correct |
1 ms |
8540 KB |
Output is correct |
68 |
Correct |
1 ms |
8540 KB |
Output is correct |
69 |
Correct |
1 ms |
8540 KB |
Output is correct |
70 |
Correct |
2 ms |
8788 KB |
Output is correct |
71 |
Correct |
2 ms |
8540 KB |
Output is correct |
72 |
Correct |
2 ms |
8676 KB |
Output is correct |
73 |
Correct |
2 ms |
8540 KB |
Output is correct |
74 |
Correct |
2 ms |
8540 KB |
Output is correct |
75 |
Correct |
1 ms |
8676 KB |
Output is correct |
76 |
Correct |
2 ms |
8540 KB |
Output is correct |
77 |
Correct |
1 ms |
8540 KB |
Output is correct |
78 |
Correct |
2 ms |
8540 KB |
Output is correct |
79 |
Correct |
2 ms |
8540 KB |
Output is correct |
80 |
Correct |
2 ms |
8540 KB |
Output is correct |
81 |
Incorrect |
1 ms |
8540 KB |
Output isn't correct |
82 |
Halted |
0 ms |
0 KB |
- |