#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> P[100001];
int tree[200001];
void update(int n, int v)
{
for(++n;n<=200000;n+=n&-n) tree[n]+=v;
}
int get_cnt(int n)
{
int ret=0;
for(++n;n;n-=n&-n) ret+=tree[n];
return ret;
}
long long count_swaps(vector<int> S)
{
int N=S.size();
long long ret=0;
for(int i=N-1;i>=0;i--) {
if(S[i]>0) P[S[i]].push_back(i);
update(i,1);
}
for(int i=0;i<N;i++) if(S[i]<0) {
update(i,-1);
ret+=get_cnt(i);
update(P[-S[i]].back(),-1);
ret+=get_cnt(P[-S[i]].back());
P[-S[i]].pop_back();
}
return ret;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2680 KB |
Output is correct |
3 |
Correct |
4 ms |
2680 KB |
Output is correct |
4 |
Correct |
4 ms |
2680 KB |
Output is correct |
5 |
Correct |
4 ms |
2680 KB |
Output is correct |
6 |
Correct |
4 ms |
2680 KB |
Output is correct |
7 |
Correct |
4 ms |
2680 KB |
Output is correct |
8 |
Correct |
4 ms |
2680 KB |
Output is correct |
9 |
Correct |
4 ms |
2680 KB |
Output is correct |
10 |
Correct |
4 ms |
2680 KB |
Output is correct |
11 |
Correct |
4 ms |
2684 KB |
Output is correct |
12 |
Correct |
4 ms |
2680 KB |
Output is correct |
13 |
Correct |
4 ms |
2680 KB |
Output is correct |
14 |
Incorrect |
4 ms |
2680 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2680 KB |
Output is correct |
3 |
Correct |
4 ms |
2680 KB |
Output is correct |
4 |
Correct |
4 ms |
2652 KB |
Output is correct |
5 |
Correct |
4 ms |
2680 KB |
Output is correct |
6 |
Correct |
4 ms |
2680 KB |
Output is correct |
7 |
Correct |
4 ms |
2680 KB |
Output is correct |
8 |
Correct |
4 ms |
2680 KB |
Output is correct |
9 |
Correct |
4 ms |
2748 KB |
Output is correct |
10 |
Correct |
4 ms |
2680 KB |
Output is correct |
11 |
Correct |
4 ms |
2680 KB |
Output is correct |
12 |
Correct |
4 ms |
2680 KB |
Output is correct |
13 |
Correct |
4 ms |
2680 KB |
Output is correct |
14 |
Correct |
4 ms |
2680 KB |
Output is correct |
15 |
Correct |
4 ms |
2680 KB |
Output is correct |
16 |
Correct |
4 ms |
2680 KB |
Output is correct |
17 |
Correct |
4 ms |
2680 KB |
Output is correct |
18 |
Correct |
4 ms |
2680 KB |
Output is correct |
19 |
Correct |
4 ms |
2680 KB |
Output is correct |
20 |
Correct |
8 ms |
3192 KB |
Output is correct |
21 |
Correct |
8 ms |
3192 KB |
Output is correct |
22 |
Correct |
46 ms |
6896 KB |
Output is correct |
23 |
Correct |
39 ms |
6896 KB |
Output is correct |
24 |
Correct |
45 ms |
6768 KB |
Output is correct |
25 |
Correct |
41 ms |
6760 KB |
Output is correct |
26 |
Correct |
46 ms |
6744 KB |
Output is correct |
27 |
Correct |
38 ms |
6644 KB |
Output is correct |
28 |
Correct |
44 ms |
6772 KB |
Output is correct |
29 |
Correct |
42 ms |
6772 KB |
Output is correct |
30 |
Correct |
43 ms |
6896 KB |
Output is correct |
31 |
Correct |
46 ms |
6768 KB |
Output is correct |
32 |
Correct |
42 ms |
6896 KB |
Output is correct |
33 |
Correct |
41 ms |
6644 KB |
Output is correct |
34 |
Correct |
42 ms |
7028 KB |
Output is correct |
35 |
Correct |
6 ms |
2680 KB |
Output is correct |
36 |
Correct |
5 ms |
2680 KB |
Output is correct |
37 |
Correct |
42 ms |
6768 KB |
Output is correct |
38 |
Correct |
42 ms |
6896 KB |
Output is correct |
39 |
Correct |
42 ms |
6768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2808 KB |
Output is correct |
2 |
Correct |
5 ms |
2680 KB |
Output is correct |
3 |
Correct |
4 ms |
2680 KB |
Output is correct |
4 |
Correct |
4 ms |
2680 KB |
Output is correct |
5 |
Correct |
59 ms |
9336 KB |
Output is correct |
6 |
Correct |
57 ms |
7092 KB |
Output is correct |
7 |
Correct |
60 ms |
9376 KB |
Output is correct |
8 |
Correct |
46 ms |
6840 KB |
Output is correct |
9 |
Correct |
61 ms |
9468 KB |
Output is correct |
10 |
Correct |
64 ms |
7928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2680 KB |
Output is correct |
3 |
Correct |
4 ms |
2680 KB |
Output is correct |
4 |
Correct |
4 ms |
2680 KB |
Output is correct |
5 |
Correct |
4 ms |
2680 KB |
Output is correct |
6 |
Correct |
4 ms |
2680 KB |
Output is correct |
7 |
Correct |
4 ms |
2680 KB |
Output is correct |
8 |
Correct |
4 ms |
2680 KB |
Output is correct |
9 |
Correct |
4 ms |
2680 KB |
Output is correct |
10 |
Correct |
4 ms |
2680 KB |
Output is correct |
11 |
Correct |
4 ms |
2684 KB |
Output is correct |
12 |
Correct |
4 ms |
2680 KB |
Output is correct |
13 |
Correct |
4 ms |
2680 KB |
Output is correct |
14 |
Incorrect |
4 ms |
2680 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2680 KB |
Output is correct |
3 |
Correct |
4 ms |
2680 KB |
Output is correct |
4 |
Correct |
4 ms |
2680 KB |
Output is correct |
5 |
Correct |
4 ms |
2680 KB |
Output is correct |
6 |
Correct |
4 ms |
2680 KB |
Output is correct |
7 |
Correct |
4 ms |
2680 KB |
Output is correct |
8 |
Correct |
4 ms |
2680 KB |
Output is correct |
9 |
Correct |
4 ms |
2680 KB |
Output is correct |
10 |
Correct |
4 ms |
2680 KB |
Output is correct |
11 |
Correct |
4 ms |
2684 KB |
Output is correct |
12 |
Correct |
4 ms |
2680 KB |
Output is correct |
13 |
Correct |
4 ms |
2680 KB |
Output is correct |
14 |
Incorrect |
4 ms |
2680 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |