#include <bits/stdc++.h>
using namespace std;
#include <bits/extc++.h>
using namespace __gnu_pbds;
typedef tree<pair<long long,long long> , null_type, less<pair<long long,long long> >, rb_tree_tag, tree_order_statistics_node_update> ost;
const long long MOD=1e9+7;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ost tree,tree2;
long long n;
cin>>n;
long long niza[n];
for(long long i=0; i<n; i++)
{
cin>>niza[i];
}
long long l[n],r[n];
map<long long,long long> mapa,mapa2;
for(long long i=0; i<n; i++)
{
mapa[niza[i]]++;
tree.insert({niza[i],mapa[niza[i]]});
long long tmp=tree.order_of_key({niza[i],1});
l[i]=tmp;
}
for(long long i=n-1; i>=0; i--)
{
mapa2[niza[i]]++;
tree2.insert({niza[i],mapa2[niza[i]]});
long long tmp=tree2.order_of_key({niza[i],1});
r[i]=tmp;
}
long long res=0;
for(long long i=0; i<n; i++)
{
res+=l[i]*r[i];
}
cout<<res<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
672 ms |
88148 KB |
Output is correct |
3 |
Correct |
682 ms |
88148 KB |
Output is correct |
4 |
Correct |
633 ms |
88148 KB |
Output is correct |
5 |
Correct |
668 ms |
88044 KB |
Output is correct |
6 |
Correct |
621 ms |
88056 KB |
Output is correct |
7 |
Correct |
602 ms |
88160 KB |
Output is correct |
8 |
Correct |
675 ms |
88176 KB |
Output is correct |
9 |
Correct |
272 ms |
69972 KB |
Output is correct |
10 |
Correct |
237 ms |
69968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
193 ms |
45396 KB |
Output is correct |
2 |
Correct |
183 ms |
45392 KB |
Output is correct |
3 |
Correct |
166 ms |
45604 KB |
Output is correct |
4 |
Correct |
169 ms |
45492 KB |
Output is correct |
5 |
Correct |
188 ms |
45396 KB |
Output is correct |
6 |
Correct |
171 ms |
45564 KB |
Output is correct |
7 |
Correct |
188 ms |
45392 KB |
Output is correct |
8 |
Correct |
349 ms |
45396 KB |
Output is correct |
9 |
Correct |
344 ms |
45396 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
193 ms |
45396 KB |
Output is correct |
2 |
Correct |
183 ms |
45392 KB |
Output is correct |
3 |
Correct |
166 ms |
45604 KB |
Output is correct |
4 |
Correct |
169 ms |
45492 KB |
Output is correct |
5 |
Correct |
188 ms |
45396 KB |
Output is correct |
6 |
Correct |
171 ms |
45564 KB |
Output is correct |
7 |
Correct |
188 ms |
45392 KB |
Output is correct |
8 |
Correct |
349 ms |
45396 KB |
Output is correct |
9 |
Correct |
344 ms |
45396 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
269 ms |
45908 KB |
Output is correct |
12 |
Correct |
296 ms |
45728 KB |
Output is correct |
13 |
Correct |
287 ms |
45820 KB |
Output is correct |
14 |
Correct |
295 ms |
45916 KB |
Output is correct |
15 |
Correct |
334 ms |
45668 KB |
Output is correct |
16 |
Correct |
279 ms |
45908 KB |
Output is correct |
17 |
Correct |
310 ms |
45756 KB |
Output is correct |
18 |
Correct |
215 ms |
45924 KB |
Output is correct |
19 |
Correct |
203 ms |
45848 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
456 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
456 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
13 ms |
3168 KB |
Output is correct |
12 |
Correct |
11 ms |
3248 KB |
Output is correct |
13 |
Correct |
12 ms |
3204 KB |
Output is correct |
14 |
Correct |
12 ms |
3164 KB |
Output is correct |
15 |
Correct |
12 ms |
3348 KB |
Output is correct |
16 |
Correct |
11 ms |
3360 KB |
Output is correct |
17 |
Correct |
11 ms |
3264 KB |
Output is correct |
18 |
Correct |
9 ms |
2652 KB |
Output is correct |
19 |
Correct |
8 ms |
1884 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
193 ms |
45396 KB |
Output is correct |
2 |
Correct |
183 ms |
45392 KB |
Output is correct |
3 |
Correct |
166 ms |
45604 KB |
Output is correct |
4 |
Correct |
169 ms |
45492 KB |
Output is correct |
5 |
Correct |
188 ms |
45396 KB |
Output is correct |
6 |
Correct |
171 ms |
45564 KB |
Output is correct |
7 |
Correct |
188 ms |
45392 KB |
Output is correct |
8 |
Correct |
349 ms |
45396 KB |
Output is correct |
9 |
Correct |
344 ms |
45396 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
269 ms |
45908 KB |
Output is correct |
12 |
Correct |
296 ms |
45728 KB |
Output is correct |
13 |
Correct |
287 ms |
45820 KB |
Output is correct |
14 |
Correct |
295 ms |
45916 KB |
Output is correct |
15 |
Correct |
334 ms |
45668 KB |
Output is correct |
16 |
Correct |
279 ms |
45908 KB |
Output is correct |
17 |
Correct |
310 ms |
45756 KB |
Output is correct |
18 |
Correct |
215 ms |
45924 KB |
Output is correct |
19 |
Correct |
203 ms |
45848 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
484 ms |
58664 KB |
Output is correct |
22 |
Correct |
520 ms |
58564 KB |
Output is correct |
23 |
Correct |
507 ms |
58452 KB |
Output is correct |
24 |
Correct |
459 ms |
58452 KB |
Output is correct |
25 |
Correct |
496 ms |
58452 KB |
Output is correct |
26 |
Correct |
485 ms |
58452 KB |
Output is correct |
27 |
Correct |
500 ms |
58656 KB |
Output is correct |
28 |
Correct |
219 ms |
58452 KB |
Output is correct |
29 |
Correct |
248 ms |
58460 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
672 ms |
88148 KB |
Output is correct |
3 |
Correct |
682 ms |
88148 KB |
Output is correct |
4 |
Correct |
633 ms |
88148 KB |
Output is correct |
5 |
Correct |
668 ms |
88044 KB |
Output is correct |
6 |
Correct |
621 ms |
88056 KB |
Output is correct |
7 |
Correct |
602 ms |
88160 KB |
Output is correct |
8 |
Correct |
675 ms |
88176 KB |
Output is correct |
9 |
Correct |
272 ms |
69972 KB |
Output is correct |
10 |
Correct |
237 ms |
69968 KB |
Output is correct |
11 |
Correct |
193 ms |
45396 KB |
Output is correct |
12 |
Correct |
183 ms |
45392 KB |
Output is correct |
13 |
Correct |
166 ms |
45604 KB |
Output is correct |
14 |
Correct |
169 ms |
45492 KB |
Output is correct |
15 |
Correct |
188 ms |
45396 KB |
Output is correct |
16 |
Correct |
171 ms |
45564 KB |
Output is correct |
17 |
Correct |
188 ms |
45392 KB |
Output is correct |
18 |
Correct |
349 ms |
45396 KB |
Output is correct |
19 |
Correct |
344 ms |
45396 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
269 ms |
45908 KB |
Output is correct |
22 |
Correct |
296 ms |
45728 KB |
Output is correct |
23 |
Correct |
287 ms |
45820 KB |
Output is correct |
24 |
Correct |
295 ms |
45916 KB |
Output is correct |
25 |
Correct |
334 ms |
45668 KB |
Output is correct |
26 |
Correct |
279 ms |
45908 KB |
Output is correct |
27 |
Correct |
310 ms |
45756 KB |
Output is correct |
28 |
Correct |
215 ms |
45924 KB |
Output is correct |
29 |
Correct |
203 ms |
45848 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
604 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
468 KB |
Output is correct |
39 |
Correct |
1 ms |
456 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
13 ms |
3168 KB |
Output is correct |
42 |
Correct |
11 ms |
3248 KB |
Output is correct |
43 |
Correct |
12 ms |
3204 KB |
Output is correct |
44 |
Correct |
12 ms |
3164 KB |
Output is correct |
45 |
Correct |
12 ms |
3348 KB |
Output is correct |
46 |
Correct |
11 ms |
3360 KB |
Output is correct |
47 |
Correct |
11 ms |
3264 KB |
Output is correct |
48 |
Correct |
9 ms |
2652 KB |
Output is correct |
49 |
Correct |
8 ms |
1884 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
484 ms |
58664 KB |
Output is correct |
52 |
Correct |
520 ms |
58564 KB |
Output is correct |
53 |
Correct |
507 ms |
58452 KB |
Output is correct |
54 |
Correct |
459 ms |
58452 KB |
Output is correct |
55 |
Correct |
496 ms |
58452 KB |
Output is correct |
56 |
Correct |
485 ms |
58452 KB |
Output is correct |
57 |
Correct |
500 ms |
58656 KB |
Output is correct |
58 |
Correct |
219 ms |
58452 KB |
Output is correct |
59 |
Correct |
248 ms |
58460 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
593 ms |
88100 KB |
Output is correct |
62 |
Correct |
562 ms |
88028 KB |
Output is correct |
63 |
Correct |
605 ms |
88148 KB |
Output is correct |
64 |
Correct |
600 ms |
88036 KB |
Output is correct |
65 |
Correct |
606 ms |
88148 KB |
Output is correct |
66 |
Correct |
586 ms |
88144 KB |
Output is correct |
67 |
Correct |
584 ms |
88148 KB |
Output is correct |
68 |
Correct |
505 ms |
69972 KB |
Output is correct |
69 |
Correct |
502 ms |
63124 KB |
Output is correct |
70 |
Correct |
0 ms |
348 KB |
Output is correct |