#include <bits/stdc++.h>
using namespace std;
#define MAXN 300001
long long n;
long long h[MAXN];
map<long long,long long> kompresija;
long long fenw[MAXN];
long long sol[MAXN];
void update(long long pos)
{
for (long long i=pos;i<=n;i+=(i&(-i))) fenw[i]++;
}
long long query(long long pos)
{
long long sum=0;
for (long long i=pos;i>=1;i-=(i&(-i))) sum+=fenw[i];
return sum;
}
int main()
{
cin>>n;
for (long long i=1;i<=n;i++) cin>>h[i];
for (long long i=1;i<=n;i++) kompresija[h[i]]=1;
long long idx=0;
for (auto&p:kompresija) {idx++;p.second=idx;}
for (long long i=1;i<=n;i++) h[i]=kompresija[h[i]];
for (long long i=1;i<=n;i++) {sol[i]=query(h[i]-1);update(h[i]);}
for (long long i=0;i<MAXN;i++) fenw[i]=0;
for (long long i=n;i>=1;i--) {sol[i]*=query(h[i]-1);update(h[i]);}
long long ans=0;
for (long long i=1;i<=n;i++) ans+=sol[i];
cout<<ans<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
211 ms |
31832 KB |
Output is correct |
3 |
Correct |
227 ms |
31572 KB |
Output is correct |
4 |
Correct |
226 ms |
31684 KB |
Output is correct |
5 |
Correct |
219 ms |
31636 KB |
Output is correct |
6 |
Correct |
222 ms |
31572 KB |
Output is correct |
7 |
Correct |
219 ms |
31892 KB |
Output is correct |
8 |
Correct |
241 ms |
31896 KB |
Output is correct |
9 |
Correct |
207 ms |
22612 KB |
Output is correct |
10 |
Correct |
243 ms |
22692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
7908 KB |
Output is correct |
2 |
Correct |
60 ms |
8272 KB |
Output is correct |
3 |
Correct |
63 ms |
8016 KB |
Output is correct |
4 |
Correct |
62 ms |
8000 KB |
Output is correct |
5 |
Correct |
60 ms |
8016 KB |
Output is correct |
6 |
Correct |
61 ms |
7928 KB |
Output is correct |
7 |
Correct |
60 ms |
8048 KB |
Output is correct |
8 |
Correct |
53 ms |
8020 KB |
Output is correct |
9 |
Correct |
57 ms |
7904 KB |
Output is correct |
10 |
Correct |
2 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
7908 KB |
Output is correct |
2 |
Correct |
60 ms |
8272 KB |
Output is correct |
3 |
Correct |
63 ms |
8016 KB |
Output is correct |
4 |
Correct |
62 ms |
8000 KB |
Output is correct |
5 |
Correct |
60 ms |
8016 KB |
Output is correct |
6 |
Correct |
61 ms |
7928 KB |
Output is correct |
7 |
Correct |
60 ms |
8048 KB |
Output is correct |
8 |
Correct |
53 ms |
8020 KB |
Output is correct |
9 |
Correct |
57 ms |
7904 KB |
Output is correct |
10 |
Correct |
2 ms |
2652 KB |
Output is correct |
11 |
Correct |
86 ms |
8124 KB |
Output is correct |
12 |
Correct |
71 ms |
8272 KB |
Output is correct |
13 |
Correct |
71 ms |
8320 KB |
Output is correct |
14 |
Correct |
74 ms |
8276 KB |
Output is correct |
15 |
Correct |
70 ms |
8272 KB |
Output is correct |
16 |
Correct |
86 ms |
8276 KB |
Output is correct |
17 |
Correct |
73 ms |
8288 KB |
Output is correct |
18 |
Correct |
55 ms |
8276 KB |
Output is correct |
19 |
Correct |
57 ms |
8276 KB |
Output is correct |
20 |
Correct |
2 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
2 ms |
2788 KB |
Output is correct |
3 |
Correct |
2 ms |
2648 KB |
Output is correct |
4 |
Correct |
2 ms |
2800 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
2 ms |
2648 KB |
Output is correct |
7 |
Correct |
2 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
2 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
2 ms |
2788 KB |
Output is correct |
3 |
Correct |
2 ms |
2648 KB |
Output is correct |
4 |
Correct |
2 ms |
2800 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
2 ms |
2648 KB |
Output is correct |
7 |
Correct |
2 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
2 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
10 ms |
3676 KB |
Output is correct |
12 |
Correct |
9 ms |
3648 KB |
Output is correct |
13 |
Correct |
8 ms |
3676 KB |
Output is correct |
14 |
Correct |
10 ms |
3752 KB |
Output is correct |
15 |
Correct |
9 ms |
3540 KB |
Output is correct |
16 |
Correct |
9 ms |
3676 KB |
Output is correct |
17 |
Correct |
9 ms |
3672 KB |
Output is correct |
18 |
Correct |
8 ms |
3164 KB |
Output is correct |
19 |
Correct |
5 ms |
2908 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
7908 KB |
Output is correct |
2 |
Correct |
60 ms |
8272 KB |
Output is correct |
3 |
Correct |
63 ms |
8016 KB |
Output is correct |
4 |
Correct |
62 ms |
8000 KB |
Output is correct |
5 |
Correct |
60 ms |
8016 KB |
Output is correct |
6 |
Correct |
61 ms |
7928 KB |
Output is correct |
7 |
Correct |
60 ms |
8048 KB |
Output is correct |
8 |
Correct |
53 ms |
8020 KB |
Output is correct |
9 |
Correct |
57 ms |
7904 KB |
Output is correct |
10 |
Correct |
2 ms |
2652 KB |
Output is correct |
11 |
Correct |
86 ms |
8124 KB |
Output is correct |
12 |
Correct |
71 ms |
8272 KB |
Output is correct |
13 |
Correct |
71 ms |
8320 KB |
Output is correct |
14 |
Correct |
74 ms |
8276 KB |
Output is correct |
15 |
Correct |
70 ms |
8272 KB |
Output is correct |
16 |
Correct |
86 ms |
8276 KB |
Output is correct |
17 |
Correct |
73 ms |
8288 KB |
Output is correct |
18 |
Correct |
55 ms |
8276 KB |
Output is correct |
19 |
Correct |
57 ms |
8276 KB |
Output is correct |
20 |
Correct |
2 ms |
2652 KB |
Output is correct |
21 |
Correct |
218 ms |
15024 KB |
Output is correct |
22 |
Correct |
215 ms |
15184 KB |
Output is correct |
23 |
Correct |
212 ms |
15120 KB |
Output is correct |
24 |
Correct |
206 ms |
14928 KB |
Output is correct |
25 |
Correct |
212 ms |
15036 KB |
Output is correct |
26 |
Correct |
218 ms |
14932 KB |
Output is correct |
27 |
Correct |
210 ms |
14928 KB |
Output is correct |
28 |
Correct |
124 ms |
14928 KB |
Output is correct |
29 |
Correct |
119 ms |
14956 KB |
Output is correct |
30 |
Correct |
3 ms |
2648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
211 ms |
31832 KB |
Output is correct |
3 |
Correct |
227 ms |
31572 KB |
Output is correct |
4 |
Correct |
226 ms |
31684 KB |
Output is correct |
5 |
Correct |
219 ms |
31636 KB |
Output is correct |
6 |
Correct |
222 ms |
31572 KB |
Output is correct |
7 |
Correct |
219 ms |
31892 KB |
Output is correct |
8 |
Correct |
241 ms |
31896 KB |
Output is correct |
9 |
Correct |
207 ms |
22612 KB |
Output is correct |
10 |
Correct |
243 ms |
22692 KB |
Output is correct |
11 |
Correct |
59 ms |
7908 KB |
Output is correct |
12 |
Correct |
60 ms |
8272 KB |
Output is correct |
13 |
Correct |
63 ms |
8016 KB |
Output is correct |
14 |
Correct |
62 ms |
8000 KB |
Output is correct |
15 |
Correct |
60 ms |
8016 KB |
Output is correct |
16 |
Correct |
61 ms |
7928 KB |
Output is correct |
17 |
Correct |
60 ms |
8048 KB |
Output is correct |
18 |
Correct |
53 ms |
8020 KB |
Output is correct |
19 |
Correct |
57 ms |
7904 KB |
Output is correct |
20 |
Correct |
2 ms |
2652 KB |
Output is correct |
21 |
Correct |
86 ms |
8124 KB |
Output is correct |
22 |
Correct |
71 ms |
8272 KB |
Output is correct |
23 |
Correct |
71 ms |
8320 KB |
Output is correct |
24 |
Correct |
74 ms |
8276 KB |
Output is correct |
25 |
Correct |
70 ms |
8272 KB |
Output is correct |
26 |
Correct |
86 ms |
8276 KB |
Output is correct |
27 |
Correct |
73 ms |
8288 KB |
Output is correct |
28 |
Correct |
55 ms |
8276 KB |
Output is correct |
29 |
Correct |
57 ms |
8276 KB |
Output is correct |
30 |
Correct |
2 ms |
2652 KB |
Output is correct |
31 |
Correct |
2 ms |
2652 KB |
Output is correct |
32 |
Correct |
2 ms |
2788 KB |
Output is correct |
33 |
Correct |
2 ms |
2648 KB |
Output is correct |
34 |
Correct |
2 ms |
2800 KB |
Output is correct |
35 |
Correct |
1 ms |
2652 KB |
Output is correct |
36 |
Correct |
2 ms |
2648 KB |
Output is correct |
37 |
Correct |
2 ms |
2652 KB |
Output is correct |
38 |
Correct |
1 ms |
2652 KB |
Output is correct |
39 |
Correct |
2 ms |
2652 KB |
Output is correct |
40 |
Correct |
1 ms |
2652 KB |
Output is correct |
41 |
Correct |
10 ms |
3676 KB |
Output is correct |
42 |
Correct |
9 ms |
3648 KB |
Output is correct |
43 |
Correct |
8 ms |
3676 KB |
Output is correct |
44 |
Correct |
10 ms |
3752 KB |
Output is correct |
45 |
Correct |
9 ms |
3540 KB |
Output is correct |
46 |
Correct |
9 ms |
3676 KB |
Output is correct |
47 |
Correct |
9 ms |
3672 KB |
Output is correct |
48 |
Correct |
8 ms |
3164 KB |
Output is correct |
49 |
Correct |
5 ms |
2908 KB |
Output is correct |
50 |
Correct |
1 ms |
2652 KB |
Output is correct |
51 |
Correct |
218 ms |
15024 KB |
Output is correct |
52 |
Correct |
215 ms |
15184 KB |
Output is correct |
53 |
Correct |
212 ms |
15120 KB |
Output is correct |
54 |
Correct |
206 ms |
14928 KB |
Output is correct |
55 |
Correct |
212 ms |
15036 KB |
Output is correct |
56 |
Correct |
218 ms |
14932 KB |
Output is correct |
57 |
Correct |
210 ms |
14928 KB |
Output is correct |
58 |
Correct |
124 ms |
14928 KB |
Output is correct |
59 |
Correct |
119 ms |
14956 KB |
Output is correct |
60 |
Correct |
3 ms |
2648 KB |
Output is correct |
61 |
Correct |
366 ms |
31788 KB |
Output is correct |
62 |
Correct |
421 ms |
31736 KB |
Output is correct |
63 |
Correct |
438 ms |
31748 KB |
Output is correct |
64 |
Correct |
385 ms |
31752 KB |
Output is correct |
65 |
Correct |
446 ms |
31700 KB |
Output is correct |
66 |
Correct |
434 ms |
31572 KB |
Output is correct |
67 |
Correct |
446 ms |
31704 KB |
Output is correct |
68 |
Correct |
328 ms |
22612 KB |
Output is correct |
69 |
Correct |
257 ms |
17420 KB |
Output is correct |
70 |
Correct |
2 ms |
2648 KB |
Output is correct |