#include <iostream>
#include <map>
#define int long long
using namespace std;
const int nmax = 3e5 + 7;
int dr[nmax], st[nmax], f[nmax], v[nmax];
map<int, int> mp;
void update(int i) {
int val = 1;
while(i < nmax) {
f[i] += val;
i += (i & (-i));
}
}
int query(int i) {
int sum = 0;
while(i > 0) {
sum += f[i];
i -= (i & (-i));
}
return sum;
}
int32_t main() {
int n;
cin >> n;
for(int i = 1; i <= n; i ++) {
cin >> v[i];
mp[v[i]];
}
int cnt = 2;
for(auto &it : mp) {
it.second = cnt;
cnt ++;
}
for(int i = 1; i <= n; i ++) {
v[i] = mp[v[i]];
}
for(int i = 1; i <= n; i ++) {
dr[i] = query(v[i] - 1);
update(v[i]);
}
for(int i = 0; i < nmax; i ++) {
f[i] = 0;
}
for(int i = n; i >= 1; i --) {
st[i] = query(v[i] - 1);
update(v[i]);
}
long long ans = 0;
for(int i = 1; i <= n; i ++) {
ans += dr[i] * st[i];
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
268 ms |
34064 KB |
Output is correct |
3 |
Correct |
248 ms |
33996 KB |
Output is correct |
4 |
Correct |
248 ms |
33900 KB |
Output is correct |
5 |
Correct |
242 ms |
34008 KB |
Output is correct |
6 |
Correct |
262 ms |
33932 KB |
Output is correct |
7 |
Correct |
304 ms |
33984 KB |
Output is correct |
8 |
Correct |
253 ms |
33972 KB |
Output is correct |
9 |
Correct |
224 ms |
25004 KB |
Output is correct |
10 |
Correct |
250 ms |
24944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
72 ms |
10196 KB |
Output is correct |
2 |
Correct |
70 ms |
10164 KB |
Output is correct |
3 |
Correct |
73 ms |
10240 KB |
Output is correct |
4 |
Correct |
75 ms |
10176 KB |
Output is correct |
5 |
Correct |
72 ms |
10224 KB |
Output is correct |
6 |
Correct |
70 ms |
10244 KB |
Output is correct |
7 |
Correct |
71 ms |
10204 KB |
Output is correct |
8 |
Correct |
71 ms |
10168 KB |
Output is correct |
9 |
Correct |
68 ms |
10188 KB |
Output is correct |
10 |
Correct |
1 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
72 ms |
10196 KB |
Output is correct |
2 |
Correct |
70 ms |
10164 KB |
Output is correct |
3 |
Correct |
73 ms |
10240 KB |
Output is correct |
4 |
Correct |
75 ms |
10176 KB |
Output is correct |
5 |
Correct |
72 ms |
10224 KB |
Output is correct |
6 |
Correct |
70 ms |
10244 KB |
Output is correct |
7 |
Correct |
71 ms |
10204 KB |
Output is correct |
8 |
Correct |
71 ms |
10168 KB |
Output is correct |
9 |
Correct |
68 ms |
10188 KB |
Output is correct |
10 |
Correct |
1 ms |
2644 KB |
Output is correct |
11 |
Correct |
83 ms |
10528 KB |
Output is correct |
12 |
Correct |
83 ms |
10432 KB |
Output is correct |
13 |
Correct |
97 ms |
10532 KB |
Output is correct |
14 |
Correct |
89 ms |
10532 KB |
Output is correct |
15 |
Correct |
83 ms |
10484 KB |
Output is correct |
16 |
Correct |
86 ms |
10444 KB |
Output is correct |
17 |
Correct |
85 ms |
10512 KB |
Output is correct |
18 |
Correct |
74 ms |
10540 KB |
Output is correct |
19 |
Correct |
68 ms |
10520 KB |
Output is correct |
20 |
Correct |
1 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2620 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2620 KB |
Output is correct |
9 |
Correct |
1 ms |
2612 KB |
Output is correct |
10 |
Correct |
1 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2620 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2620 KB |
Output is correct |
9 |
Correct |
1 ms |
2612 KB |
Output is correct |
10 |
Correct |
1 ms |
2644 KB |
Output is correct |
11 |
Correct |
10 ms |
3644 KB |
Output is correct |
12 |
Correct |
12 ms |
3668 KB |
Output is correct |
13 |
Correct |
10 ms |
3644 KB |
Output is correct |
14 |
Correct |
10 ms |
3652 KB |
Output is correct |
15 |
Correct |
10 ms |
3624 KB |
Output is correct |
16 |
Correct |
10 ms |
3684 KB |
Output is correct |
17 |
Correct |
10 ms |
3648 KB |
Output is correct |
18 |
Correct |
9 ms |
3268 KB |
Output is correct |
19 |
Correct |
4 ms |
2900 KB |
Output is correct |
20 |
Correct |
1 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
72 ms |
10196 KB |
Output is correct |
2 |
Correct |
70 ms |
10164 KB |
Output is correct |
3 |
Correct |
73 ms |
10240 KB |
Output is correct |
4 |
Correct |
75 ms |
10176 KB |
Output is correct |
5 |
Correct |
72 ms |
10224 KB |
Output is correct |
6 |
Correct |
70 ms |
10244 KB |
Output is correct |
7 |
Correct |
71 ms |
10204 KB |
Output is correct |
8 |
Correct |
71 ms |
10168 KB |
Output is correct |
9 |
Correct |
68 ms |
10188 KB |
Output is correct |
10 |
Correct |
1 ms |
2644 KB |
Output is correct |
11 |
Correct |
83 ms |
10528 KB |
Output is correct |
12 |
Correct |
83 ms |
10432 KB |
Output is correct |
13 |
Correct |
97 ms |
10532 KB |
Output is correct |
14 |
Correct |
89 ms |
10532 KB |
Output is correct |
15 |
Correct |
83 ms |
10484 KB |
Output is correct |
16 |
Correct |
86 ms |
10444 KB |
Output is correct |
17 |
Correct |
85 ms |
10512 KB |
Output is correct |
18 |
Correct |
74 ms |
10540 KB |
Output is correct |
19 |
Correct |
68 ms |
10520 KB |
Output is correct |
20 |
Correct |
1 ms |
2644 KB |
Output is correct |
21 |
Correct |
226 ms |
17356 KB |
Output is correct |
22 |
Correct |
225 ms |
17316 KB |
Output is correct |
23 |
Correct |
231 ms |
17352 KB |
Output is correct |
24 |
Correct |
238 ms |
17328 KB |
Output is correct |
25 |
Correct |
226 ms |
17336 KB |
Output is correct |
26 |
Correct |
231 ms |
17292 KB |
Output is correct |
27 |
Correct |
226 ms |
17276 KB |
Output is correct |
28 |
Correct |
133 ms |
17244 KB |
Output is correct |
29 |
Correct |
130 ms |
17320 KB |
Output is correct |
30 |
Correct |
1 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
268 ms |
34064 KB |
Output is correct |
3 |
Correct |
248 ms |
33996 KB |
Output is correct |
4 |
Correct |
248 ms |
33900 KB |
Output is correct |
5 |
Correct |
242 ms |
34008 KB |
Output is correct |
6 |
Correct |
262 ms |
33932 KB |
Output is correct |
7 |
Correct |
304 ms |
33984 KB |
Output is correct |
8 |
Correct |
253 ms |
33972 KB |
Output is correct |
9 |
Correct |
224 ms |
25004 KB |
Output is correct |
10 |
Correct |
250 ms |
24944 KB |
Output is correct |
11 |
Correct |
72 ms |
10196 KB |
Output is correct |
12 |
Correct |
70 ms |
10164 KB |
Output is correct |
13 |
Correct |
73 ms |
10240 KB |
Output is correct |
14 |
Correct |
75 ms |
10176 KB |
Output is correct |
15 |
Correct |
72 ms |
10224 KB |
Output is correct |
16 |
Correct |
70 ms |
10244 KB |
Output is correct |
17 |
Correct |
71 ms |
10204 KB |
Output is correct |
18 |
Correct |
71 ms |
10168 KB |
Output is correct |
19 |
Correct |
68 ms |
10188 KB |
Output is correct |
20 |
Correct |
1 ms |
2644 KB |
Output is correct |
21 |
Correct |
83 ms |
10528 KB |
Output is correct |
22 |
Correct |
83 ms |
10432 KB |
Output is correct |
23 |
Correct |
97 ms |
10532 KB |
Output is correct |
24 |
Correct |
89 ms |
10532 KB |
Output is correct |
25 |
Correct |
83 ms |
10484 KB |
Output is correct |
26 |
Correct |
86 ms |
10444 KB |
Output is correct |
27 |
Correct |
85 ms |
10512 KB |
Output is correct |
28 |
Correct |
74 ms |
10540 KB |
Output is correct |
29 |
Correct |
68 ms |
10520 KB |
Output is correct |
30 |
Correct |
1 ms |
2644 KB |
Output is correct |
31 |
Correct |
2 ms |
2644 KB |
Output is correct |
32 |
Correct |
2 ms |
2644 KB |
Output is correct |
33 |
Correct |
2 ms |
2644 KB |
Output is correct |
34 |
Correct |
2 ms |
2644 KB |
Output is correct |
35 |
Correct |
2 ms |
2620 KB |
Output is correct |
36 |
Correct |
2 ms |
2644 KB |
Output is correct |
37 |
Correct |
2 ms |
2644 KB |
Output is correct |
38 |
Correct |
2 ms |
2620 KB |
Output is correct |
39 |
Correct |
1 ms |
2612 KB |
Output is correct |
40 |
Correct |
1 ms |
2644 KB |
Output is correct |
41 |
Correct |
10 ms |
3644 KB |
Output is correct |
42 |
Correct |
12 ms |
3668 KB |
Output is correct |
43 |
Correct |
10 ms |
3644 KB |
Output is correct |
44 |
Correct |
10 ms |
3652 KB |
Output is correct |
45 |
Correct |
10 ms |
3624 KB |
Output is correct |
46 |
Correct |
10 ms |
3684 KB |
Output is correct |
47 |
Correct |
10 ms |
3648 KB |
Output is correct |
48 |
Correct |
9 ms |
3268 KB |
Output is correct |
49 |
Correct |
4 ms |
2900 KB |
Output is correct |
50 |
Correct |
1 ms |
2644 KB |
Output is correct |
51 |
Correct |
226 ms |
17356 KB |
Output is correct |
52 |
Correct |
225 ms |
17316 KB |
Output is correct |
53 |
Correct |
231 ms |
17352 KB |
Output is correct |
54 |
Correct |
238 ms |
17328 KB |
Output is correct |
55 |
Correct |
226 ms |
17336 KB |
Output is correct |
56 |
Correct |
231 ms |
17292 KB |
Output is correct |
57 |
Correct |
226 ms |
17276 KB |
Output is correct |
58 |
Correct |
133 ms |
17244 KB |
Output is correct |
59 |
Correct |
130 ms |
17320 KB |
Output is correct |
60 |
Correct |
1 ms |
2644 KB |
Output is correct |
61 |
Correct |
521 ms |
34004 KB |
Output is correct |
62 |
Correct |
518 ms |
33996 KB |
Output is correct |
63 |
Correct |
553 ms |
34008 KB |
Output is correct |
64 |
Correct |
572 ms |
34008 KB |
Output is correct |
65 |
Correct |
572 ms |
33896 KB |
Output is correct |
66 |
Correct |
495 ms |
33900 KB |
Output is correct |
67 |
Correct |
538 ms |
34004 KB |
Output is correct |
68 |
Correct |
398 ms |
24884 KB |
Output is correct |
69 |
Correct |
252 ms |
19652 KB |
Output is correct |
70 |
Correct |
2 ms |
2608 KB |
Output is correct |