#include <bits/stdc++.h>
using namespace std;
struct nr {
long long i,v,idx;
}v[300005];
long long st[300005],dr[300005],aib[300005],n,s;
bool cmp1(nr a, nr b) {
return a.i < b.i;
}
bool cmp2(nr a, nr b) {
return a.idx < b.idx;
}
void update(long long a, long long b) {
for(long long i = a;i <= n;i += (i&(-i)))
aib[i] += b;
}
long long query(long long a) {
s = 0;
for(long long i = a;i > 0;i -= (i&(-i)))
s += aib[i];
return s;
}
int main()
{
long long cnt = 1,ans = 0;
cin >> n;
for(int i = 1;i <= n;i++) {
cin >> v[i].i;
v[i].idx = i;
}
sort(v + 1, v + n + 1, cmp1);
v[1].v = 1;
for(int i = 2;i <= n;i++) {
if(i > 1 && v[i].i != v[i - 1].i)
cnt++;
v[i].v = cnt;
}
sort(v + 1, v + n + 1, cmp2);
for(int i = 1;i <= n;i++) {
update(v[i].v, 1);
st[i] = query(v[i].v - 1);
}
for(int i = 1;i <= n;i++)
update(v[i].v, -1);
for(int i = n;i >= 1;i--) {
update(v[i].v, 1);
dr[i] = query(v[i].v - 1);
ans += st[i] * dr[i];
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
307 ms |
20076 KB |
Output is correct |
3 |
Correct |
305 ms |
19948 KB |
Output is correct |
4 |
Correct |
305 ms |
19948 KB |
Output is correct |
5 |
Correct |
304 ms |
19948 KB |
Output is correct |
6 |
Correct |
309 ms |
20076 KB |
Output is correct |
7 |
Correct |
310 ms |
19948 KB |
Output is correct |
8 |
Correct |
309 ms |
19948 KB |
Output is correct |
9 |
Correct |
330 ms |
18924 KB |
Output is correct |
10 |
Correct |
320 ms |
18912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
193 ms |
12652 KB |
Output is correct |
2 |
Correct |
186 ms |
12652 KB |
Output is correct |
3 |
Correct |
192 ms |
12652 KB |
Output is correct |
4 |
Correct |
199 ms |
12652 KB |
Output is correct |
5 |
Correct |
204 ms |
12780 KB |
Output is correct |
6 |
Correct |
206 ms |
12652 KB |
Output is correct |
7 |
Correct |
200 ms |
12800 KB |
Output is correct |
8 |
Correct |
177 ms |
12652 KB |
Output is correct |
9 |
Correct |
186 ms |
12780 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
193 ms |
12652 KB |
Output is correct |
2 |
Correct |
186 ms |
12652 KB |
Output is correct |
3 |
Correct |
192 ms |
12652 KB |
Output is correct |
4 |
Correct |
199 ms |
12652 KB |
Output is correct |
5 |
Correct |
204 ms |
12780 KB |
Output is correct |
6 |
Correct |
206 ms |
12652 KB |
Output is correct |
7 |
Correct |
200 ms |
12800 KB |
Output is correct |
8 |
Correct |
177 ms |
12652 KB |
Output is correct |
9 |
Correct |
186 ms |
12780 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
209 ms |
13108 KB |
Output is correct |
12 |
Correct |
202 ms |
12908 KB |
Output is correct |
13 |
Correct |
203 ms |
13164 KB |
Output is correct |
14 |
Correct |
202 ms |
13036 KB |
Output is correct |
15 |
Correct |
203 ms |
12908 KB |
Output is correct |
16 |
Correct |
202 ms |
13036 KB |
Output is correct |
17 |
Correct |
207 ms |
13036 KB |
Output is correct |
18 |
Correct |
173 ms |
13072 KB |
Output is correct |
19 |
Correct |
171 ms |
12908 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
11 ms |
1004 KB |
Output is correct |
12 |
Correct |
11 ms |
1004 KB |
Output is correct |
13 |
Correct |
11 ms |
1004 KB |
Output is correct |
14 |
Correct |
11 ms |
1004 KB |
Output is correct |
15 |
Correct |
12 ms |
1004 KB |
Output is correct |
16 |
Correct |
11 ms |
1004 KB |
Output is correct |
17 |
Correct |
11 ms |
1004 KB |
Output is correct |
18 |
Correct |
11 ms |
1004 KB |
Output is correct |
19 |
Correct |
6 ms |
748 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
193 ms |
12652 KB |
Output is correct |
2 |
Correct |
186 ms |
12652 KB |
Output is correct |
3 |
Correct |
192 ms |
12652 KB |
Output is correct |
4 |
Correct |
199 ms |
12652 KB |
Output is correct |
5 |
Correct |
204 ms |
12780 KB |
Output is correct |
6 |
Correct |
206 ms |
12652 KB |
Output is correct |
7 |
Correct |
200 ms |
12800 KB |
Output is correct |
8 |
Correct |
177 ms |
12652 KB |
Output is correct |
9 |
Correct |
186 ms |
12780 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
209 ms |
13108 KB |
Output is correct |
12 |
Correct |
202 ms |
12908 KB |
Output is correct |
13 |
Correct |
203 ms |
13164 KB |
Output is correct |
14 |
Correct |
202 ms |
13036 KB |
Output is correct |
15 |
Correct |
203 ms |
12908 KB |
Output is correct |
16 |
Correct |
202 ms |
13036 KB |
Output is correct |
17 |
Correct |
207 ms |
13036 KB |
Output is correct |
18 |
Correct |
173 ms |
13072 KB |
Output is correct |
19 |
Correct |
171 ms |
12908 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
244 ms |
14540 KB |
Output is correct |
22 |
Correct |
244 ms |
14572 KB |
Output is correct |
23 |
Correct |
244 ms |
14572 KB |
Output is correct |
24 |
Correct |
242 ms |
14572 KB |
Output is correct |
25 |
Correct |
251 ms |
14572 KB |
Output is correct |
26 |
Correct |
250 ms |
14560 KB |
Output is correct |
27 |
Correct |
250 ms |
14572 KB |
Output is correct |
28 |
Correct |
188 ms |
14540 KB |
Output is correct |
29 |
Correct |
186 ms |
14572 KB |
Output is correct |
30 |
Correct |
1 ms |
380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
307 ms |
20076 KB |
Output is correct |
3 |
Correct |
305 ms |
19948 KB |
Output is correct |
4 |
Correct |
305 ms |
19948 KB |
Output is correct |
5 |
Correct |
304 ms |
19948 KB |
Output is correct |
6 |
Correct |
309 ms |
20076 KB |
Output is correct |
7 |
Correct |
310 ms |
19948 KB |
Output is correct |
8 |
Correct |
309 ms |
19948 KB |
Output is correct |
9 |
Correct |
330 ms |
18924 KB |
Output is correct |
10 |
Correct |
320 ms |
18912 KB |
Output is correct |
11 |
Correct |
193 ms |
12652 KB |
Output is correct |
12 |
Correct |
186 ms |
12652 KB |
Output is correct |
13 |
Correct |
192 ms |
12652 KB |
Output is correct |
14 |
Correct |
199 ms |
12652 KB |
Output is correct |
15 |
Correct |
204 ms |
12780 KB |
Output is correct |
16 |
Correct |
206 ms |
12652 KB |
Output is correct |
17 |
Correct |
200 ms |
12800 KB |
Output is correct |
18 |
Correct |
177 ms |
12652 KB |
Output is correct |
19 |
Correct |
186 ms |
12780 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
209 ms |
13108 KB |
Output is correct |
22 |
Correct |
202 ms |
12908 KB |
Output is correct |
23 |
Correct |
203 ms |
13164 KB |
Output is correct |
24 |
Correct |
202 ms |
13036 KB |
Output is correct |
25 |
Correct |
203 ms |
12908 KB |
Output is correct |
26 |
Correct |
202 ms |
13036 KB |
Output is correct |
27 |
Correct |
207 ms |
13036 KB |
Output is correct |
28 |
Correct |
173 ms |
13072 KB |
Output is correct |
29 |
Correct |
171 ms |
12908 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
2 ms |
364 KB |
Output is correct |
32 |
Correct |
2 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
37 |
Correct |
1 ms |
364 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
364 KB |
Output is correct |
40 |
Correct |
1 ms |
364 KB |
Output is correct |
41 |
Correct |
11 ms |
1004 KB |
Output is correct |
42 |
Correct |
11 ms |
1004 KB |
Output is correct |
43 |
Correct |
11 ms |
1004 KB |
Output is correct |
44 |
Correct |
11 ms |
1004 KB |
Output is correct |
45 |
Correct |
12 ms |
1004 KB |
Output is correct |
46 |
Correct |
11 ms |
1004 KB |
Output is correct |
47 |
Correct |
11 ms |
1004 KB |
Output is correct |
48 |
Correct |
11 ms |
1004 KB |
Output is correct |
49 |
Correct |
6 ms |
748 KB |
Output is correct |
50 |
Correct |
1 ms |
364 KB |
Output is correct |
51 |
Correct |
244 ms |
14540 KB |
Output is correct |
52 |
Correct |
244 ms |
14572 KB |
Output is correct |
53 |
Correct |
244 ms |
14572 KB |
Output is correct |
54 |
Correct |
242 ms |
14572 KB |
Output is correct |
55 |
Correct |
251 ms |
14572 KB |
Output is correct |
56 |
Correct |
250 ms |
14560 KB |
Output is correct |
57 |
Correct |
250 ms |
14572 KB |
Output is correct |
58 |
Correct |
188 ms |
14540 KB |
Output is correct |
59 |
Correct |
186 ms |
14572 KB |
Output is correct |
60 |
Correct |
1 ms |
380 KB |
Output is correct |
61 |
Correct |
378 ms |
20100 KB |
Output is correct |
62 |
Correct |
362 ms |
20076 KB |
Output is correct |
63 |
Correct |
361 ms |
20076 KB |
Output is correct |
64 |
Correct |
360 ms |
20076 KB |
Output is correct |
65 |
Correct |
360 ms |
19948 KB |
Output is correct |
66 |
Correct |
369 ms |
20204 KB |
Output is correct |
67 |
Correct |
364 ms |
19920 KB |
Output is correct |
68 |
Correct |
374 ms |
18924 KB |
Output is correct |
69 |
Correct |
244 ms |
14956 KB |
Output is correct |
70 |
Correct |
1 ms |
364 KB |
Output is correct |