#include<bits/stdc++.h>
using namespace std;
long long n,a[300005],b[300005],fac[300005],fen[300005],c[300005],ans=0;
vector<long long> v;
map<long long,long long> mp;
void update(long long u,long long val)
{
while(u<=n)
{
fen[u]+=val;
fen[u]%=1000000007;
u+=(u&(-u));
}
}
long long query(long long u)
{
long long val=0;
while(u>=1)
{
val+=fen[u];
val%=1000000007;
u-=(u&(-u));
}
return val;
}
int main()
{
scanf("%lld",&n);
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
v.push_back(a[i]);
}
v.push_back(-1);
sort(v.begin(),v.end());
for(int i=1;i<=n;i++)
{
mp[v[i]]=i;
}
for(int i=1;i<=n;i++)
{
b[i]=mp[a[i]];
}
/*for(int i=1;i<=n;i++)
{
printf("%d ",b[i]);
}
printf("\n");*/
fac[0]=1;
for(int i=1;i<=300000;i++)
{
fac[i]=fac[i-1]*i;
fac[i]%=1000000007;
}
for(int i=n;i>=1;i--)
{
update(b[i],1);
c[i]=query(b[i]);
}
for(int i=1;i<=n;i++)
{
//printf("%d ",c[i]);
ans+=(c[i]-1)*fac[n-i];
ans%=1000000007;
}
printf("%lld\n",ans+1);
//printf("\n");
}
Compilation message
Crypto.cpp: In function 'int main()':
Crypto.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | scanf("%lld",&n);
| ~~~~~^~~~~~~~~~~
Crypto.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | scanf("%lld",&a[i]);
| ~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2636 KB |
Output is correct |
2 |
Correct |
4 ms |
2636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2636 KB |
Output is correct |
2 |
Correct |
4 ms |
2636 KB |
Output is correct |
3 |
Correct |
3 ms |
2636 KB |
Output is correct |
4 |
Correct |
3 ms |
2636 KB |
Output is correct |
5 |
Correct |
3 ms |
2636 KB |
Output is correct |
6 |
Correct |
3 ms |
2636 KB |
Output is correct |
7 |
Correct |
3 ms |
2564 KB |
Output is correct |
8 |
Correct |
4 ms |
2596 KB |
Output is correct |
9 |
Correct |
3 ms |
2636 KB |
Output is correct |
10 |
Correct |
3 ms |
2636 KB |
Output is correct |
11 |
Correct |
3 ms |
2560 KB |
Output is correct |
12 |
Correct |
3 ms |
2636 KB |
Output is correct |
13 |
Correct |
3 ms |
2636 KB |
Output is correct |
14 |
Correct |
3 ms |
2636 KB |
Output is correct |
15 |
Correct |
3 ms |
2636 KB |
Output is correct |
16 |
Correct |
3 ms |
2636 KB |
Output is correct |
17 |
Correct |
3 ms |
2636 KB |
Output is correct |
18 |
Correct |
3 ms |
2636 KB |
Output is correct |
19 |
Correct |
3 ms |
2636 KB |
Output is correct |
20 |
Correct |
4 ms |
2636 KB |
Output is correct |
21 |
Correct |
3 ms |
2636 KB |
Output is correct |
22 |
Correct |
3 ms |
2636 KB |
Output is correct |
23 |
Correct |
4 ms |
2636 KB |
Output is correct |
24 |
Correct |
3 ms |
2636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2636 KB |
Output is correct |
2 |
Correct |
238 ms |
33124 KB |
Output is correct |
3 |
Correct |
168 ms |
33104 KB |
Output is correct |
4 |
Correct |
167 ms |
33052 KB |
Output is correct |
5 |
Correct |
153 ms |
33132 KB |
Output is correct |
6 |
Correct |
158 ms |
33040 KB |
Output is correct |
7 |
Correct |
228 ms |
33180 KB |
Output is correct |
8 |
Correct |
163 ms |
33064 KB |
Output is correct |
9 |
Correct |
180 ms |
33068 KB |
Output is correct |
10 |
Correct |
184 ms |
33084 KB |
Output is correct |
11 |
Correct |
229 ms |
33136 KB |
Output is correct |
12 |
Correct |
169 ms |
33164 KB |
Output is correct |
13 |
Correct |
185 ms |
33120 KB |
Output is correct |
14 |
Correct |
202 ms |
33056 KB |
Output is correct |
15 |
Correct |
227 ms |
33064 KB |
Output is correct |
16 |
Correct |
176 ms |
33144 KB |
Output is correct |
17 |
Correct |
186 ms |
33148 KB |
Output is correct |
18 |
Correct |
176 ms |
33060 KB |
Output is correct |
19 |
Correct |
152 ms |
33136 KB |
Output is correct |
20 |
Correct |
170 ms |
33112 KB |
Output is correct |
21 |
Correct |
154 ms |
33088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2636 KB |
Output is correct |
2 |
Correct |
160 ms |
33120 KB |
Output is correct |
3 |
Correct |
152 ms |
33132 KB |
Output is correct |
4 |
Correct |
198 ms |
33212 KB |
Output is correct |
5 |
Correct |
170 ms |
33156 KB |
Output is correct |
6 |
Correct |
157 ms |
33140 KB |
Output is correct |
7 |
Correct |
156 ms |
33152 KB |
Output is correct |
8 |
Correct |
192 ms |
33084 KB |
Output is correct |
9 |
Correct |
184 ms |
33068 KB |
Output is correct |
10 |
Correct |
190 ms |
33132 KB |
Output is correct |
11 |
Correct |
178 ms |
33052 KB |
Output is correct |
12 |
Correct |
190 ms |
33064 KB |
Output is correct |
13 |
Correct |
155 ms |
33072 KB |
Output is correct |
14 |
Correct |
150 ms |
33140 KB |
Output is correct |
15 |
Correct |
183 ms |
33164 KB |
Output is correct |
16 |
Correct |
155 ms |
33104 KB |
Output is correct |
17 |
Correct |
168 ms |
33140 KB |
Output is correct |
18 |
Correct |
179 ms |
33136 KB |
Output is correct |
19 |
Correct |
157 ms |
33064 KB |
Output is correct |
20 |
Correct |
167 ms |
33128 KB |
Output is correct |
21 |
Correct |
183 ms |
33052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2636 KB |
Output is correct |
2 |
Correct |
6 ms |
2892 KB |
Output is correct |
3 |
Correct |
4 ms |
2868 KB |
Output is correct |
4 |
Correct |
5 ms |
2892 KB |
Output is correct |
5 |
Correct |
5 ms |
2892 KB |
Output is correct |
6 |
Correct |
4 ms |
2892 KB |
Output is correct |
7 |
Correct |
6 ms |
2892 KB |
Output is correct |
8 |
Correct |
4 ms |
2892 KB |
Output is correct |
9 |
Correct |
5 ms |
2892 KB |
Output is correct |
10 |
Correct |
4 ms |
2892 KB |
Output is correct |
11 |
Correct |
6 ms |
2892 KB |
Output is correct |
12 |
Correct |
4 ms |
2892 KB |
Output is correct |
13 |
Correct |
4 ms |
2892 KB |
Output is correct |
14 |
Correct |
4 ms |
2892 KB |
Output is correct |
15 |
Incorrect |
3 ms |
2636 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2636 KB |
Output is correct |
2 |
Correct |
4 ms |
2636 KB |
Output is correct |
3 |
Correct |
3 ms |
2636 KB |
Output is correct |
4 |
Correct |
3 ms |
2636 KB |
Output is correct |
5 |
Correct |
3 ms |
2636 KB |
Output is correct |
6 |
Correct |
3 ms |
2636 KB |
Output is correct |
7 |
Correct |
3 ms |
2564 KB |
Output is correct |
8 |
Correct |
4 ms |
2596 KB |
Output is correct |
9 |
Correct |
3 ms |
2636 KB |
Output is correct |
10 |
Correct |
3 ms |
2636 KB |
Output is correct |
11 |
Correct |
3 ms |
2560 KB |
Output is correct |
12 |
Correct |
3 ms |
2636 KB |
Output is correct |
13 |
Correct |
3 ms |
2636 KB |
Output is correct |
14 |
Correct |
3 ms |
2636 KB |
Output is correct |
15 |
Correct |
3 ms |
2636 KB |
Output is correct |
16 |
Correct |
3 ms |
2636 KB |
Output is correct |
17 |
Correct |
3 ms |
2636 KB |
Output is correct |
18 |
Correct |
3 ms |
2636 KB |
Output is correct |
19 |
Correct |
3 ms |
2636 KB |
Output is correct |
20 |
Correct |
4 ms |
2636 KB |
Output is correct |
21 |
Correct |
3 ms |
2636 KB |
Output is correct |
22 |
Correct |
3 ms |
2636 KB |
Output is correct |
23 |
Correct |
4 ms |
2636 KB |
Output is correct |
24 |
Correct |
3 ms |
2636 KB |
Output is correct |
25 |
Correct |
3 ms |
2636 KB |
Output is correct |
26 |
Correct |
6 ms |
2892 KB |
Output is correct |
27 |
Correct |
4 ms |
2868 KB |
Output is correct |
28 |
Correct |
5 ms |
2892 KB |
Output is correct |
29 |
Correct |
5 ms |
2892 KB |
Output is correct |
30 |
Correct |
4 ms |
2892 KB |
Output is correct |
31 |
Correct |
6 ms |
2892 KB |
Output is correct |
32 |
Correct |
4 ms |
2892 KB |
Output is correct |
33 |
Correct |
5 ms |
2892 KB |
Output is correct |
34 |
Correct |
4 ms |
2892 KB |
Output is correct |
35 |
Correct |
6 ms |
2892 KB |
Output is correct |
36 |
Correct |
4 ms |
2892 KB |
Output is correct |
37 |
Correct |
4 ms |
2892 KB |
Output is correct |
38 |
Correct |
4 ms |
2892 KB |
Output is correct |
39 |
Incorrect |
3 ms |
2636 KB |
Output isn't correct |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2636 KB |
Output is correct |
2 |
Correct |
160 ms |
33120 KB |
Output is correct |
3 |
Correct |
152 ms |
33132 KB |
Output is correct |
4 |
Correct |
198 ms |
33212 KB |
Output is correct |
5 |
Correct |
170 ms |
33156 KB |
Output is correct |
6 |
Correct |
157 ms |
33140 KB |
Output is correct |
7 |
Correct |
156 ms |
33152 KB |
Output is correct |
8 |
Correct |
192 ms |
33084 KB |
Output is correct |
9 |
Correct |
184 ms |
33068 KB |
Output is correct |
10 |
Correct |
190 ms |
33132 KB |
Output is correct |
11 |
Correct |
178 ms |
33052 KB |
Output is correct |
12 |
Correct |
190 ms |
33064 KB |
Output is correct |
13 |
Correct |
155 ms |
33072 KB |
Output is correct |
14 |
Correct |
150 ms |
33140 KB |
Output is correct |
15 |
Correct |
183 ms |
33164 KB |
Output is correct |
16 |
Correct |
155 ms |
33104 KB |
Output is correct |
17 |
Correct |
168 ms |
33140 KB |
Output is correct |
18 |
Correct |
179 ms |
33136 KB |
Output is correct |
19 |
Correct |
157 ms |
33064 KB |
Output is correct |
20 |
Correct |
167 ms |
33128 KB |
Output is correct |
21 |
Correct |
183 ms |
33052 KB |
Output is correct |
22 |
Correct |
3 ms |
2636 KB |
Output is correct |
23 |
Correct |
6 ms |
2892 KB |
Output is correct |
24 |
Correct |
4 ms |
2868 KB |
Output is correct |
25 |
Correct |
5 ms |
2892 KB |
Output is correct |
26 |
Correct |
5 ms |
2892 KB |
Output is correct |
27 |
Correct |
4 ms |
2892 KB |
Output is correct |
28 |
Correct |
6 ms |
2892 KB |
Output is correct |
29 |
Correct |
4 ms |
2892 KB |
Output is correct |
30 |
Correct |
5 ms |
2892 KB |
Output is correct |
31 |
Correct |
4 ms |
2892 KB |
Output is correct |
32 |
Correct |
6 ms |
2892 KB |
Output is correct |
33 |
Correct |
4 ms |
2892 KB |
Output is correct |
34 |
Correct |
4 ms |
2892 KB |
Output is correct |
35 |
Correct |
4 ms |
2892 KB |
Output is correct |
36 |
Incorrect |
3 ms |
2636 KB |
Output isn't correct |
37 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2636 KB |
Output is correct |
2 |
Correct |
4 ms |
2636 KB |
Output is correct |
3 |
Correct |
3 ms |
2636 KB |
Output is correct |
4 |
Correct |
3 ms |
2636 KB |
Output is correct |
5 |
Correct |
3 ms |
2636 KB |
Output is correct |
6 |
Correct |
3 ms |
2636 KB |
Output is correct |
7 |
Correct |
3 ms |
2564 KB |
Output is correct |
8 |
Correct |
4 ms |
2596 KB |
Output is correct |
9 |
Correct |
3 ms |
2636 KB |
Output is correct |
10 |
Correct |
3 ms |
2636 KB |
Output is correct |
11 |
Correct |
3 ms |
2560 KB |
Output is correct |
12 |
Correct |
3 ms |
2636 KB |
Output is correct |
13 |
Correct |
3 ms |
2636 KB |
Output is correct |
14 |
Correct |
3 ms |
2636 KB |
Output is correct |
15 |
Correct |
3 ms |
2636 KB |
Output is correct |
16 |
Correct |
3 ms |
2636 KB |
Output is correct |
17 |
Correct |
3 ms |
2636 KB |
Output is correct |
18 |
Correct |
3 ms |
2636 KB |
Output is correct |
19 |
Correct |
3 ms |
2636 KB |
Output is correct |
20 |
Correct |
4 ms |
2636 KB |
Output is correct |
21 |
Correct |
3 ms |
2636 KB |
Output is correct |
22 |
Correct |
3 ms |
2636 KB |
Output is correct |
23 |
Correct |
4 ms |
2636 KB |
Output is correct |
24 |
Correct |
3 ms |
2636 KB |
Output is correct |
25 |
Correct |
4 ms |
2636 KB |
Output is correct |
26 |
Correct |
238 ms |
33124 KB |
Output is correct |
27 |
Correct |
168 ms |
33104 KB |
Output is correct |
28 |
Correct |
167 ms |
33052 KB |
Output is correct |
29 |
Correct |
153 ms |
33132 KB |
Output is correct |
30 |
Correct |
158 ms |
33040 KB |
Output is correct |
31 |
Correct |
228 ms |
33180 KB |
Output is correct |
32 |
Correct |
163 ms |
33064 KB |
Output is correct |
33 |
Correct |
180 ms |
33068 KB |
Output is correct |
34 |
Correct |
184 ms |
33084 KB |
Output is correct |
35 |
Correct |
229 ms |
33136 KB |
Output is correct |
36 |
Correct |
169 ms |
33164 KB |
Output is correct |
37 |
Correct |
185 ms |
33120 KB |
Output is correct |
38 |
Correct |
202 ms |
33056 KB |
Output is correct |
39 |
Correct |
227 ms |
33064 KB |
Output is correct |
40 |
Correct |
176 ms |
33144 KB |
Output is correct |
41 |
Correct |
186 ms |
33148 KB |
Output is correct |
42 |
Correct |
176 ms |
33060 KB |
Output is correct |
43 |
Correct |
152 ms |
33136 KB |
Output is correct |
44 |
Correct |
170 ms |
33112 KB |
Output is correct |
45 |
Correct |
154 ms |
33088 KB |
Output is correct |
46 |
Correct |
3 ms |
2636 KB |
Output is correct |
47 |
Correct |
160 ms |
33120 KB |
Output is correct |
48 |
Correct |
152 ms |
33132 KB |
Output is correct |
49 |
Correct |
198 ms |
33212 KB |
Output is correct |
50 |
Correct |
170 ms |
33156 KB |
Output is correct |
51 |
Correct |
157 ms |
33140 KB |
Output is correct |
52 |
Correct |
156 ms |
33152 KB |
Output is correct |
53 |
Correct |
192 ms |
33084 KB |
Output is correct |
54 |
Correct |
184 ms |
33068 KB |
Output is correct |
55 |
Correct |
190 ms |
33132 KB |
Output is correct |
56 |
Correct |
178 ms |
33052 KB |
Output is correct |
57 |
Correct |
190 ms |
33064 KB |
Output is correct |
58 |
Correct |
155 ms |
33072 KB |
Output is correct |
59 |
Correct |
150 ms |
33140 KB |
Output is correct |
60 |
Correct |
183 ms |
33164 KB |
Output is correct |
61 |
Correct |
155 ms |
33104 KB |
Output is correct |
62 |
Correct |
168 ms |
33140 KB |
Output is correct |
63 |
Correct |
179 ms |
33136 KB |
Output is correct |
64 |
Correct |
157 ms |
33064 KB |
Output is correct |
65 |
Correct |
167 ms |
33128 KB |
Output is correct |
66 |
Correct |
183 ms |
33052 KB |
Output is correct |
67 |
Correct |
3 ms |
2636 KB |
Output is correct |
68 |
Correct |
6 ms |
2892 KB |
Output is correct |
69 |
Correct |
4 ms |
2868 KB |
Output is correct |
70 |
Correct |
5 ms |
2892 KB |
Output is correct |
71 |
Correct |
5 ms |
2892 KB |
Output is correct |
72 |
Correct |
4 ms |
2892 KB |
Output is correct |
73 |
Correct |
6 ms |
2892 KB |
Output is correct |
74 |
Correct |
4 ms |
2892 KB |
Output is correct |
75 |
Correct |
5 ms |
2892 KB |
Output is correct |
76 |
Correct |
4 ms |
2892 KB |
Output is correct |
77 |
Correct |
6 ms |
2892 KB |
Output is correct |
78 |
Correct |
4 ms |
2892 KB |
Output is correct |
79 |
Correct |
4 ms |
2892 KB |
Output is correct |
80 |
Correct |
4 ms |
2892 KB |
Output is correct |
81 |
Incorrect |
3 ms |
2636 KB |
Output isn't correct |
82 |
Halted |
0 ms |
0 KB |
- |