#include<bits/stdc++.h>
#include "shoes.h"
using namespace std;
bool visit[200000] = {};
long long n, ret = 0, bit[200001] = {}, s[200001], ans[200001];
queue<int> Left[100001], Right[100001];
void bld(void)
{
for (int i = 1; i <= n + 10; i++)
for (int j = i; j > i - (i & -i); j--)
if (j != 1)
bit[i]++;
}
long long sum(int x)
{
long long ret = 0;
for (int i = x; i >= 1; i -= (i & -i))
ret += bit[i];
return ret;
}
void edt(int x, int k)
{
for (int i = x; i <= n; i += (i & -i))
bit[i] -= k;
}
long long count_swaps(vector<int> in)
{
n = in.size();
s[0] = 0;
for (int i = 1; i <= n; i++)
{
s[i] = in[i - 1];
if (s[i] < 0)
Left[-s[i]].push(i);
else
Right[s[i]].push(i);
}
bld();
int cnt = 0, pos, tar;
for (int i = 1; i <= n; i++)
{
if (visit[i])
continue;
tar = -abs(s[i]);
pos = Left[-tar].front(), Left[-tar].pop();
ans[cnt++] = tar;
visit[pos] = true;
ret += sum(pos);
edt(pos, 1);
tar = -ans[cnt - 1];
pos = Right[tar].front(), Right[tar].pop();
ans[cnt++] = tar;
visit[pos] = true;
ret += sum(pos);
edt(pos, 1);
}
return ret;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
134 ms |
135032 KB |
Output is correct |
2 |
Correct |
135 ms |
134956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
134 ms |
135032 KB |
Output is correct |
2 |
Correct |
135 ms |
134956 KB |
Output is correct |
3 |
Correct |
134 ms |
134904 KB |
Output is correct |
4 |
Correct |
134 ms |
135032 KB |
Output is correct |
5 |
Correct |
141 ms |
135108 KB |
Output is correct |
6 |
Correct |
145 ms |
134956 KB |
Output is correct |
7 |
Correct |
135 ms |
134904 KB |
Output is correct |
8 |
Correct |
137 ms |
134904 KB |
Output is correct |
9 |
Correct |
135 ms |
134948 KB |
Output is correct |
10 |
Correct |
134 ms |
134988 KB |
Output is correct |
11 |
Correct |
135 ms |
135032 KB |
Output is correct |
12 |
Correct |
135 ms |
134904 KB |
Output is correct |
13 |
Correct |
136 ms |
134944 KB |
Output is correct |
14 |
Correct |
135 ms |
134904 KB |
Output is correct |
15 |
Correct |
134 ms |
135008 KB |
Output is correct |
16 |
Correct |
134 ms |
134904 KB |
Output is correct |
17 |
Correct |
134 ms |
135004 KB |
Output is correct |
18 |
Correct |
134 ms |
135004 KB |
Output is correct |
19 |
Correct |
151 ms |
135032 KB |
Output is correct |
20 |
Correct |
152 ms |
135008 KB |
Output is correct |
21 |
Correct |
137 ms |
134908 KB |
Output is correct |
22 |
Correct |
137 ms |
134904 KB |
Output is correct |
23 |
Correct |
134 ms |
135016 KB |
Output is correct |
24 |
Correct |
136 ms |
134948 KB |
Output is correct |
25 |
Correct |
134 ms |
134904 KB |
Output is correct |
26 |
Correct |
140 ms |
135024 KB |
Output is correct |
27 |
Correct |
142 ms |
134912 KB |
Output is correct |
28 |
Correct |
164 ms |
135144 KB |
Output is correct |
29 |
Correct |
151 ms |
134960 KB |
Output is correct |
30 |
Correct |
160 ms |
135004 KB |
Output is correct |
31 |
Correct |
162 ms |
135008 KB |
Output is correct |
32 |
Correct |
163 ms |
135036 KB |
Output is correct |
33 |
Correct |
154 ms |
134936 KB |
Output is correct |
34 |
Correct |
135 ms |
135004 KB |
Output is correct |
35 |
Correct |
135 ms |
134904 KB |
Output is correct |
36 |
Correct |
149 ms |
135016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
134 ms |
135032 KB |
Output is correct |
2 |
Correct |
135 ms |
134956 KB |
Output is correct |
3 |
Correct |
145 ms |
135048 KB |
Output is correct |
4 |
Correct |
136 ms |
134904 KB |
Output is correct |
5 |
Correct |
136 ms |
135000 KB |
Output is correct |
6 |
Correct |
138 ms |
134908 KB |
Output is correct |
7 |
Correct |
137 ms |
134904 KB |
Output is correct |
8 |
Correct |
160 ms |
135028 KB |
Output is correct |
9 |
Correct |
137 ms |
135036 KB |
Output is correct |
10 |
Correct |
138 ms |
135020 KB |
Output is correct |
11 |
Correct |
137 ms |
134904 KB |
Output is correct |
12 |
Correct |
137 ms |
135144 KB |
Output is correct |
13 |
Correct |
137 ms |
135004 KB |
Output is correct |
14 |
Correct |
152 ms |
135028 KB |
Output is correct |
15 |
Correct |
136 ms |
134904 KB |
Output is correct |
16 |
Correct |
138 ms |
134944 KB |
Output is correct |
17 |
Correct |
154 ms |
135120 KB |
Output is correct |
18 |
Correct |
149 ms |
135032 KB |
Output is correct |
19 |
Correct |
178 ms |
135160 KB |
Output is correct |
20 |
Correct |
157 ms |
135800 KB |
Output is correct |
21 |
Correct |
152 ms |
135928 KB |
Output is correct |
22 |
Execution timed out |
1095 ms |
143480 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
136 ms |
134904 KB |
Output is correct |
2 |
Correct |
137 ms |
135052 KB |
Output is correct |
3 |
Correct |
139 ms |
134956 KB |
Output is correct |
4 |
Correct |
140 ms |
135020 KB |
Output is correct |
5 |
Execution timed out |
1091 ms |
142712 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
134 ms |
135032 KB |
Output is correct |
2 |
Correct |
135 ms |
134956 KB |
Output is correct |
3 |
Correct |
134 ms |
134904 KB |
Output is correct |
4 |
Correct |
134 ms |
135032 KB |
Output is correct |
5 |
Correct |
141 ms |
135108 KB |
Output is correct |
6 |
Correct |
145 ms |
134956 KB |
Output is correct |
7 |
Correct |
135 ms |
134904 KB |
Output is correct |
8 |
Correct |
137 ms |
134904 KB |
Output is correct |
9 |
Correct |
135 ms |
134948 KB |
Output is correct |
10 |
Correct |
134 ms |
134988 KB |
Output is correct |
11 |
Correct |
135 ms |
135032 KB |
Output is correct |
12 |
Correct |
135 ms |
134904 KB |
Output is correct |
13 |
Correct |
136 ms |
134944 KB |
Output is correct |
14 |
Correct |
135 ms |
134904 KB |
Output is correct |
15 |
Correct |
134 ms |
135008 KB |
Output is correct |
16 |
Correct |
134 ms |
134904 KB |
Output is correct |
17 |
Correct |
134 ms |
135004 KB |
Output is correct |
18 |
Correct |
134 ms |
135004 KB |
Output is correct |
19 |
Correct |
151 ms |
135032 KB |
Output is correct |
20 |
Correct |
152 ms |
135008 KB |
Output is correct |
21 |
Correct |
137 ms |
134908 KB |
Output is correct |
22 |
Correct |
137 ms |
134904 KB |
Output is correct |
23 |
Correct |
134 ms |
135016 KB |
Output is correct |
24 |
Correct |
136 ms |
134948 KB |
Output is correct |
25 |
Correct |
134 ms |
134904 KB |
Output is correct |
26 |
Correct |
140 ms |
135024 KB |
Output is correct |
27 |
Correct |
142 ms |
134912 KB |
Output is correct |
28 |
Correct |
164 ms |
135144 KB |
Output is correct |
29 |
Correct |
151 ms |
134960 KB |
Output is correct |
30 |
Correct |
160 ms |
135004 KB |
Output is correct |
31 |
Correct |
162 ms |
135008 KB |
Output is correct |
32 |
Correct |
163 ms |
135036 KB |
Output is correct |
33 |
Correct |
154 ms |
134936 KB |
Output is correct |
34 |
Correct |
135 ms |
135004 KB |
Output is correct |
35 |
Correct |
135 ms |
134904 KB |
Output is correct |
36 |
Correct |
149 ms |
135016 KB |
Output is correct |
37 |
Correct |
136 ms |
134904 KB |
Output is correct |
38 |
Correct |
137 ms |
134988 KB |
Output is correct |
39 |
Correct |
137 ms |
134992 KB |
Output is correct |
40 |
Correct |
137 ms |
135032 KB |
Output is correct |
41 |
Correct |
140 ms |
135108 KB |
Output is correct |
42 |
Correct |
137 ms |
135032 KB |
Output is correct |
43 |
Correct |
137 ms |
135036 KB |
Output is correct |
44 |
Correct |
139 ms |
135112 KB |
Output is correct |
45 |
Correct |
137 ms |
135052 KB |
Output is correct |
46 |
Correct |
139 ms |
135032 KB |
Output is correct |
47 |
Correct |
142 ms |
135036 KB |
Output is correct |
48 |
Correct |
139 ms |
135032 KB |
Output is correct |
49 |
Correct |
137 ms |
135128 KB |
Output is correct |
50 |
Correct |
150 ms |
135032 KB |
Output is correct |
51 |
Correct |
152 ms |
135032 KB |
Output is correct |
52 |
Correct |
166 ms |
134996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
134 ms |
135032 KB |
Output is correct |
2 |
Correct |
135 ms |
134956 KB |
Output is correct |
3 |
Correct |
134 ms |
134904 KB |
Output is correct |
4 |
Correct |
134 ms |
135032 KB |
Output is correct |
5 |
Correct |
141 ms |
135108 KB |
Output is correct |
6 |
Correct |
145 ms |
134956 KB |
Output is correct |
7 |
Correct |
135 ms |
134904 KB |
Output is correct |
8 |
Correct |
137 ms |
134904 KB |
Output is correct |
9 |
Correct |
135 ms |
134948 KB |
Output is correct |
10 |
Correct |
134 ms |
134988 KB |
Output is correct |
11 |
Correct |
135 ms |
135032 KB |
Output is correct |
12 |
Correct |
135 ms |
134904 KB |
Output is correct |
13 |
Correct |
136 ms |
134944 KB |
Output is correct |
14 |
Correct |
135 ms |
134904 KB |
Output is correct |
15 |
Correct |
134 ms |
135008 KB |
Output is correct |
16 |
Correct |
134 ms |
134904 KB |
Output is correct |
17 |
Correct |
134 ms |
135004 KB |
Output is correct |
18 |
Correct |
134 ms |
135004 KB |
Output is correct |
19 |
Correct |
151 ms |
135032 KB |
Output is correct |
20 |
Correct |
152 ms |
135008 KB |
Output is correct |
21 |
Correct |
137 ms |
134908 KB |
Output is correct |
22 |
Correct |
137 ms |
134904 KB |
Output is correct |
23 |
Correct |
134 ms |
135016 KB |
Output is correct |
24 |
Correct |
136 ms |
134948 KB |
Output is correct |
25 |
Correct |
134 ms |
134904 KB |
Output is correct |
26 |
Correct |
140 ms |
135024 KB |
Output is correct |
27 |
Correct |
142 ms |
134912 KB |
Output is correct |
28 |
Correct |
164 ms |
135144 KB |
Output is correct |
29 |
Correct |
151 ms |
134960 KB |
Output is correct |
30 |
Correct |
160 ms |
135004 KB |
Output is correct |
31 |
Correct |
162 ms |
135008 KB |
Output is correct |
32 |
Correct |
163 ms |
135036 KB |
Output is correct |
33 |
Correct |
154 ms |
134936 KB |
Output is correct |
34 |
Correct |
135 ms |
135004 KB |
Output is correct |
35 |
Correct |
135 ms |
134904 KB |
Output is correct |
36 |
Correct |
149 ms |
135016 KB |
Output is correct |
37 |
Correct |
145 ms |
135048 KB |
Output is correct |
38 |
Correct |
136 ms |
134904 KB |
Output is correct |
39 |
Correct |
136 ms |
135000 KB |
Output is correct |
40 |
Correct |
138 ms |
134908 KB |
Output is correct |
41 |
Correct |
137 ms |
134904 KB |
Output is correct |
42 |
Correct |
160 ms |
135028 KB |
Output is correct |
43 |
Correct |
137 ms |
135036 KB |
Output is correct |
44 |
Correct |
138 ms |
135020 KB |
Output is correct |
45 |
Correct |
137 ms |
134904 KB |
Output is correct |
46 |
Correct |
137 ms |
135144 KB |
Output is correct |
47 |
Correct |
137 ms |
135004 KB |
Output is correct |
48 |
Correct |
152 ms |
135028 KB |
Output is correct |
49 |
Correct |
136 ms |
134904 KB |
Output is correct |
50 |
Correct |
138 ms |
134944 KB |
Output is correct |
51 |
Correct |
154 ms |
135120 KB |
Output is correct |
52 |
Correct |
149 ms |
135032 KB |
Output is correct |
53 |
Correct |
178 ms |
135160 KB |
Output is correct |
54 |
Correct |
157 ms |
135800 KB |
Output is correct |
55 |
Correct |
152 ms |
135928 KB |
Output is correct |
56 |
Execution timed out |
1095 ms |
143480 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |