#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 3;
int n;
long long a[N];
vector<long long> s;
map<long long,int> ma;
long long fa[N],fb[N];
long long ans;
void update(long long (&a)[N],int idx,long long val){ idx++; while(idx<N) a[idx]+=val,idx+=(idx & -idx); }
long long read(long long (&a)[N],int idx){ idx++; long long val = 0; while(idx>0) val+=a[idx],idx-=(idx & -idx); return val; }
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n;
for(int i = 1;i <= n;i++) cin >> a[i],s.push_back(a[i]);
sort(s.begin(),s.end());
int id = 0;
for(long long x : s) if(!ma[x]) ma[x] = ++id;
for(int i = 1;i <= n;i++) a[i] = ma[a[i]];
for(int i = 1;i <= n;i++)
{
ans+=read(fb,N-2)-read(fb,a[i]);
update(fb,a[i],read(fa,a[i]-1));
update(fa,a[i],1);
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
247 ms |
28640 KB |
Output is correct |
3 |
Correct |
244 ms |
28644 KB |
Output is correct |
4 |
Correct |
244 ms |
28692 KB |
Output is correct |
5 |
Correct |
258 ms |
28640 KB |
Output is correct |
6 |
Correct |
242 ms |
28636 KB |
Output is correct |
7 |
Correct |
247 ms |
28640 KB |
Output is correct |
8 |
Correct |
260 ms |
28780 KB |
Output is correct |
9 |
Correct |
199 ms |
17376 KB |
Output is correct |
10 |
Correct |
199 ms |
17376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
6768 KB |
Output is correct |
2 |
Correct |
65 ms |
6772 KB |
Output is correct |
3 |
Correct |
60 ms |
6772 KB |
Output is correct |
4 |
Correct |
61 ms |
6772 KB |
Output is correct |
5 |
Correct |
63 ms |
6772 KB |
Output is correct |
6 |
Correct |
62 ms |
6772 KB |
Output is correct |
7 |
Correct |
61 ms |
6764 KB |
Output is correct |
8 |
Correct |
56 ms |
6772 KB |
Output is correct |
9 |
Correct |
57 ms |
6772 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
6768 KB |
Output is correct |
2 |
Correct |
65 ms |
6772 KB |
Output is correct |
3 |
Correct |
60 ms |
6772 KB |
Output is correct |
4 |
Correct |
61 ms |
6772 KB |
Output is correct |
5 |
Correct |
63 ms |
6772 KB |
Output is correct |
6 |
Correct |
62 ms |
6772 KB |
Output is correct |
7 |
Correct |
61 ms |
6764 KB |
Output is correct |
8 |
Correct |
56 ms |
6772 KB |
Output is correct |
9 |
Correct |
57 ms |
6772 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
79 ms |
6760 KB |
Output is correct |
12 |
Correct |
80 ms |
6764 KB |
Output is correct |
13 |
Correct |
89 ms |
6772 KB |
Output is correct |
14 |
Correct |
80 ms |
6772 KB |
Output is correct |
15 |
Correct |
82 ms |
6768 KB |
Output is correct |
16 |
Correct |
87 ms |
6764 KB |
Output is correct |
17 |
Correct |
81 ms |
6772 KB |
Output is correct |
18 |
Correct |
63 ms |
6772 KB |
Output is correct |
19 |
Correct |
62 ms |
6772 KB |
Output is correct |
20 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
512 KB |
Output is correct |
9 |
Correct |
5 ms |
512 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
512 KB |
Output is correct |
9 |
Correct |
5 ms |
512 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
13 ms |
1536 KB |
Output is correct |
12 |
Correct |
13 ms |
1536 KB |
Output is correct |
13 |
Correct |
12 ms |
1536 KB |
Output is correct |
14 |
Correct |
12 ms |
1536 KB |
Output is correct |
15 |
Correct |
13 ms |
1536 KB |
Output is correct |
16 |
Correct |
13 ms |
1536 KB |
Output is correct |
17 |
Correct |
13 ms |
1536 KB |
Output is correct |
18 |
Correct |
12 ms |
1152 KB |
Output is correct |
19 |
Correct |
7 ms |
768 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
6768 KB |
Output is correct |
2 |
Correct |
65 ms |
6772 KB |
Output is correct |
3 |
Correct |
60 ms |
6772 KB |
Output is correct |
4 |
Correct |
61 ms |
6772 KB |
Output is correct |
5 |
Correct |
63 ms |
6772 KB |
Output is correct |
6 |
Correct |
62 ms |
6772 KB |
Output is correct |
7 |
Correct |
61 ms |
6764 KB |
Output is correct |
8 |
Correct |
56 ms |
6772 KB |
Output is correct |
9 |
Correct |
57 ms |
6772 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
79 ms |
6760 KB |
Output is correct |
12 |
Correct |
80 ms |
6764 KB |
Output is correct |
13 |
Correct |
89 ms |
6772 KB |
Output is correct |
14 |
Correct |
80 ms |
6772 KB |
Output is correct |
15 |
Correct |
82 ms |
6768 KB |
Output is correct |
16 |
Correct |
87 ms |
6764 KB |
Output is correct |
17 |
Correct |
81 ms |
6772 KB |
Output is correct |
18 |
Correct |
63 ms |
6772 KB |
Output is correct |
19 |
Correct |
62 ms |
6772 KB |
Output is correct |
20 |
Correct |
5 ms |
512 KB |
Output is correct |
21 |
Correct |
290 ms |
12624 KB |
Output is correct |
22 |
Correct |
278 ms |
12640 KB |
Output is correct |
23 |
Correct |
261 ms |
12640 KB |
Output is correct |
24 |
Correct |
258 ms |
12640 KB |
Output is correct |
25 |
Correct |
265 ms |
12724 KB |
Output is correct |
26 |
Correct |
266 ms |
12640 KB |
Output is correct |
27 |
Correct |
298 ms |
12648 KB |
Output is correct |
28 |
Correct |
141 ms |
12636 KB |
Output is correct |
29 |
Correct |
144 ms |
12640 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
247 ms |
28640 KB |
Output is correct |
3 |
Correct |
244 ms |
28644 KB |
Output is correct |
4 |
Correct |
244 ms |
28692 KB |
Output is correct |
5 |
Correct |
258 ms |
28640 KB |
Output is correct |
6 |
Correct |
242 ms |
28636 KB |
Output is correct |
7 |
Correct |
247 ms |
28640 KB |
Output is correct |
8 |
Correct |
260 ms |
28780 KB |
Output is correct |
9 |
Correct |
199 ms |
17376 KB |
Output is correct |
10 |
Correct |
199 ms |
17376 KB |
Output is correct |
11 |
Correct |
64 ms |
6768 KB |
Output is correct |
12 |
Correct |
65 ms |
6772 KB |
Output is correct |
13 |
Correct |
60 ms |
6772 KB |
Output is correct |
14 |
Correct |
61 ms |
6772 KB |
Output is correct |
15 |
Correct |
63 ms |
6772 KB |
Output is correct |
16 |
Correct |
62 ms |
6772 KB |
Output is correct |
17 |
Correct |
61 ms |
6764 KB |
Output is correct |
18 |
Correct |
56 ms |
6772 KB |
Output is correct |
19 |
Correct |
57 ms |
6772 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Correct |
79 ms |
6760 KB |
Output is correct |
22 |
Correct |
80 ms |
6764 KB |
Output is correct |
23 |
Correct |
89 ms |
6772 KB |
Output is correct |
24 |
Correct |
80 ms |
6772 KB |
Output is correct |
25 |
Correct |
82 ms |
6768 KB |
Output is correct |
26 |
Correct |
87 ms |
6764 KB |
Output is correct |
27 |
Correct |
81 ms |
6772 KB |
Output is correct |
28 |
Correct |
63 ms |
6772 KB |
Output is correct |
29 |
Correct |
62 ms |
6772 KB |
Output is correct |
30 |
Correct |
5 ms |
512 KB |
Output is correct |
31 |
Correct |
5 ms |
512 KB |
Output is correct |
32 |
Correct |
5 ms |
512 KB |
Output is correct |
33 |
Correct |
5 ms |
512 KB |
Output is correct |
34 |
Correct |
5 ms |
512 KB |
Output is correct |
35 |
Correct |
5 ms |
512 KB |
Output is correct |
36 |
Correct |
5 ms |
512 KB |
Output is correct |
37 |
Correct |
5 ms |
512 KB |
Output is correct |
38 |
Correct |
5 ms |
512 KB |
Output is correct |
39 |
Correct |
5 ms |
512 KB |
Output is correct |
40 |
Correct |
5 ms |
384 KB |
Output is correct |
41 |
Correct |
13 ms |
1536 KB |
Output is correct |
42 |
Correct |
13 ms |
1536 KB |
Output is correct |
43 |
Correct |
12 ms |
1536 KB |
Output is correct |
44 |
Correct |
12 ms |
1536 KB |
Output is correct |
45 |
Correct |
13 ms |
1536 KB |
Output is correct |
46 |
Correct |
13 ms |
1536 KB |
Output is correct |
47 |
Correct |
13 ms |
1536 KB |
Output is correct |
48 |
Correct |
12 ms |
1152 KB |
Output is correct |
49 |
Correct |
7 ms |
768 KB |
Output is correct |
50 |
Correct |
5 ms |
384 KB |
Output is correct |
51 |
Correct |
290 ms |
12624 KB |
Output is correct |
52 |
Correct |
278 ms |
12640 KB |
Output is correct |
53 |
Correct |
261 ms |
12640 KB |
Output is correct |
54 |
Correct |
258 ms |
12640 KB |
Output is correct |
55 |
Correct |
265 ms |
12724 KB |
Output is correct |
56 |
Correct |
266 ms |
12640 KB |
Output is correct |
57 |
Correct |
298 ms |
12648 KB |
Output is correct |
58 |
Correct |
141 ms |
12636 KB |
Output is correct |
59 |
Correct |
144 ms |
12640 KB |
Output is correct |
60 |
Correct |
5 ms |
384 KB |
Output is correct |
61 |
Correct |
536 ms |
33260 KB |
Output is correct |
62 |
Correct |
562 ms |
33120 KB |
Output is correct |
63 |
Correct |
557 ms |
33120 KB |
Output is correct |
64 |
Correct |
534 ms |
33120 KB |
Output is correct |
65 |
Correct |
540 ms |
33248 KB |
Output is correct |
66 |
Correct |
543 ms |
33108 KB |
Output is correct |
67 |
Correct |
534 ms |
33220 KB |
Output is correct |
68 |
Correct |
421 ms |
21856 KB |
Output is correct |
69 |
Correct |
345 ms |
17124 KB |
Output is correct |
70 |
Correct |
4 ms |
384 KB |
Output is correct |