// Dmitry _kun_ Sayutin (2019)
#include <bits/stdc++.h>
#include "shoes.h"
using std::cin;
using std::cout;
using std::cerr;
using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;
using std::pair;
using std::make_pair;
using std::tuple;
using std::make_tuple;
using std::get;
using std::min;
using std::abs;
using std::max;
using std::swap;
using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;
#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif
#define SZ(vec) int((vec).size())
#define ALL(data) data.begin(),data.end()
#define RALL(data) data.rbegin(),data.rend()
#define TYPEMAX(type) std::numeric_limits<type>::max()
#define TYPEMIN(type) std::numeric_limits<type>::min()
vector<int> change(vector<int> v) {
int n = (int)v.size() / 2;
vector<int> cnt(n, 0);
for(int i = 0; i < 2*n; i++)
if(v[i] > 0)
cnt[v[i] - 1]++;
for(int i = 1; i < n; i++)
cnt[i] += cnt[i-1];
vector<int> cntl = cnt, cntr = cnt;
for(int i = 0; i < 2*n; i++)
if(v[i] > 0)
v[i] = (--cntr[v[i] - 1]) + 1;
else
v[i] = -((--cntl[-v[i] - 1]) + 1);
return v;
}
long long count_swaps(vector<int> s) {
s = change(s);
vector<pair<int, bool>> in(SZ(s));
vector<int> where(SZ(s) / 2, -1);
for (int i = 0; i != SZ(s); ++i) {
in[i].first = abs(s[i]) - 1;
in[i].second = (s[i] < 0 ? 0 : 1);
if (where[in[i].first] == -1)
where[in[i].first] = i;
}
vector<int> fenw(SZ(in));
for (int i = 0; i != SZ(in); ++i)
fenw[i] = 1 + i - (i & (i+1));
long long ans = 0;
vector<char> dead(SZ(in), false);
for (int pos = SZ(in) - 1; pos >= 0; --pos)
if (not dead[pos]) {
dead[pos] = 1;
int i = where[in[pos].first];
dead[i] = 1;
int dist = 0;
for (int p = pos; p >= 0; p = (p & (p + 1)) - 1)
dist += fenw[p];
for (int p = i; p >= 0; p = (p & (p + 1)) - 1)
dist -= fenw[p];
if (in[pos].second == 1)
--dist;
ans += dist;
for (int p = i; p < SZ(fenw); p = p | (p + 1))
fenw[p] -= 1;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
380 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
380 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
256 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
256 KB |
Output is correct |
29 |
Correct |
2 ms |
256 KB |
Output is correct |
30 |
Correct |
2 ms |
256 KB |
Output is correct |
31 |
Correct |
2 ms |
256 KB |
Output is correct |
32 |
Correct |
2 ms |
256 KB |
Output is correct |
33 |
Correct |
2 ms |
256 KB |
Output is correct |
34 |
Correct |
2 ms |
376 KB |
Output is correct |
35 |
Correct |
2 ms |
376 KB |
Output is correct |
36 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
256 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
760 KB |
Output is correct |
21 |
Correct |
6 ms |
888 KB |
Output is correct |
22 |
Correct |
43 ms |
4812 KB |
Output is correct |
23 |
Correct |
36 ms |
4812 KB |
Output is correct |
24 |
Correct |
43 ms |
4812 KB |
Output is correct |
25 |
Correct |
35 ms |
4816 KB |
Output is correct |
26 |
Correct |
44 ms |
4944 KB |
Output is correct |
27 |
Correct |
37 ms |
4812 KB |
Output is correct |
28 |
Correct |
38 ms |
4816 KB |
Output is correct |
29 |
Correct |
38 ms |
4940 KB |
Output is correct |
30 |
Correct |
39 ms |
4812 KB |
Output is correct |
31 |
Correct |
47 ms |
4812 KB |
Output is correct |
32 |
Correct |
37 ms |
4788 KB |
Output is correct |
33 |
Correct |
35 ms |
4812 KB |
Output is correct |
34 |
Correct |
37 ms |
4940 KB |
Output is correct |
35 |
Correct |
2 ms |
376 KB |
Output is correct |
36 |
Correct |
2 ms |
376 KB |
Output is correct |
37 |
Correct |
39 ms |
4820 KB |
Output is correct |
38 |
Correct |
37 ms |
4812 KB |
Output is correct |
39 |
Correct |
37 ms |
4816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
44 ms |
4852 KB |
Output is correct |
6 |
Correct |
58 ms |
4856 KB |
Output is correct |
7 |
Correct |
44 ms |
4812 KB |
Output is correct |
8 |
Correct |
40 ms |
4812 KB |
Output is correct |
9 |
Correct |
42 ms |
4812 KB |
Output is correct |
10 |
Correct |
42 ms |
4816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
380 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
380 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
256 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
256 KB |
Output is correct |
29 |
Correct |
2 ms |
256 KB |
Output is correct |
30 |
Correct |
2 ms |
256 KB |
Output is correct |
31 |
Correct |
2 ms |
256 KB |
Output is correct |
32 |
Correct |
2 ms |
256 KB |
Output is correct |
33 |
Correct |
2 ms |
256 KB |
Output is correct |
34 |
Correct |
2 ms |
376 KB |
Output is correct |
35 |
Correct |
2 ms |
376 KB |
Output is correct |
36 |
Correct |
2 ms |
256 KB |
Output is correct |
37 |
Correct |
2 ms |
256 KB |
Output is correct |
38 |
Correct |
2 ms |
376 KB |
Output is correct |
39 |
Correct |
2 ms |
376 KB |
Output is correct |
40 |
Correct |
2 ms |
376 KB |
Output is correct |
41 |
Correct |
2 ms |
376 KB |
Output is correct |
42 |
Correct |
2 ms |
376 KB |
Output is correct |
43 |
Correct |
2 ms |
376 KB |
Output is correct |
44 |
Correct |
2 ms |
376 KB |
Output is correct |
45 |
Correct |
2 ms |
376 KB |
Output is correct |
46 |
Correct |
2 ms |
376 KB |
Output is correct |
47 |
Correct |
3 ms |
376 KB |
Output is correct |
48 |
Correct |
2 ms |
376 KB |
Output is correct |
49 |
Correct |
2 ms |
376 KB |
Output is correct |
50 |
Correct |
2 ms |
376 KB |
Output is correct |
51 |
Correct |
2 ms |
376 KB |
Output is correct |
52 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
380 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
380 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
256 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
256 KB |
Output is correct |
29 |
Correct |
2 ms |
256 KB |
Output is correct |
30 |
Correct |
2 ms |
256 KB |
Output is correct |
31 |
Correct |
2 ms |
256 KB |
Output is correct |
32 |
Correct |
2 ms |
256 KB |
Output is correct |
33 |
Correct |
2 ms |
256 KB |
Output is correct |
34 |
Correct |
2 ms |
376 KB |
Output is correct |
35 |
Correct |
2 ms |
376 KB |
Output is correct |
36 |
Correct |
2 ms |
256 KB |
Output is correct |
37 |
Correct |
2 ms |
376 KB |
Output is correct |
38 |
Correct |
2 ms |
376 KB |
Output is correct |
39 |
Correct |
2 ms |
376 KB |
Output is correct |
40 |
Correct |
2 ms |
376 KB |
Output is correct |
41 |
Correct |
2 ms |
256 KB |
Output is correct |
42 |
Correct |
2 ms |
376 KB |
Output is correct |
43 |
Correct |
2 ms |
256 KB |
Output is correct |
44 |
Correct |
2 ms |
256 KB |
Output is correct |
45 |
Correct |
2 ms |
256 KB |
Output is correct |
46 |
Correct |
2 ms |
256 KB |
Output is correct |
47 |
Correct |
2 ms |
376 KB |
Output is correct |
48 |
Correct |
2 ms |
256 KB |
Output is correct |
49 |
Correct |
2 ms |
376 KB |
Output is correct |
50 |
Correct |
2 ms |
376 KB |
Output is correct |
51 |
Correct |
2 ms |
256 KB |
Output is correct |
52 |
Correct |
2 ms |
376 KB |
Output is correct |
53 |
Correct |
2 ms |
376 KB |
Output is correct |
54 |
Correct |
6 ms |
760 KB |
Output is correct |
55 |
Correct |
6 ms |
888 KB |
Output is correct |
56 |
Correct |
43 ms |
4812 KB |
Output is correct |
57 |
Correct |
36 ms |
4812 KB |
Output is correct |
58 |
Correct |
43 ms |
4812 KB |
Output is correct |
59 |
Correct |
35 ms |
4816 KB |
Output is correct |
60 |
Correct |
44 ms |
4944 KB |
Output is correct |
61 |
Correct |
37 ms |
4812 KB |
Output is correct |
62 |
Correct |
38 ms |
4816 KB |
Output is correct |
63 |
Correct |
38 ms |
4940 KB |
Output is correct |
64 |
Correct |
39 ms |
4812 KB |
Output is correct |
65 |
Correct |
47 ms |
4812 KB |
Output is correct |
66 |
Correct |
37 ms |
4788 KB |
Output is correct |
67 |
Correct |
35 ms |
4812 KB |
Output is correct |
68 |
Correct |
37 ms |
4940 KB |
Output is correct |
69 |
Correct |
2 ms |
376 KB |
Output is correct |
70 |
Correct |
2 ms |
376 KB |
Output is correct |
71 |
Correct |
39 ms |
4820 KB |
Output is correct |
72 |
Correct |
37 ms |
4812 KB |
Output is correct |
73 |
Correct |
37 ms |
4816 KB |
Output is correct |
74 |
Correct |
2 ms |
376 KB |
Output is correct |
75 |
Correct |
2 ms |
376 KB |
Output is correct |
76 |
Correct |
2 ms |
376 KB |
Output is correct |
77 |
Correct |
2 ms |
376 KB |
Output is correct |
78 |
Correct |
44 ms |
4852 KB |
Output is correct |
79 |
Correct |
58 ms |
4856 KB |
Output is correct |
80 |
Correct |
44 ms |
4812 KB |
Output is correct |
81 |
Correct |
40 ms |
4812 KB |
Output is correct |
82 |
Correct |
42 ms |
4812 KB |
Output is correct |
83 |
Correct |
42 ms |
4816 KB |
Output is correct |
84 |
Correct |
2 ms |
256 KB |
Output is correct |
85 |
Correct |
2 ms |
376 KB |
Output is correct |
86 |
Correct |
2 ms |
376 KB |
Output is correct |
87 |
Correct |
2 ms |
376 KB |
Output is correct |
88 |
Correct |
2 ms |
376 KB |
Output is correct |
89 |
Correct |
2 ms |
376 KB |
Output is correct |
90 |
Correct |
2 ms |
376 KB |
Output is correct |
91 |
Correct |
2 ms |
376 KB |
Output is correct |
92 |
Correct |
2 ms |
376 KB |
Output is correct |
93 |
Correct |
2 ms |
376 KB |
Output is correct |
94 |
Correct |
3 ms |
376 KB |
Output is correct |
95 |
Correct |
2 ms |
376 KB |
Output is correct |
96 |
Correct |
2 ms |
376 KB |
Output is correct |
97 |
Correct |
2 ms |
376 KB |
Output is correct |
98 |
Correct |
2 ms |
376 KB |
Output is correct |
99 |
Correct |
2 ms |
376 KB |
Output is correct |
100 |
Correct |
2 ms |
376 KB |
Output is correct |
101 |
Correct |
6 ms |
760 KB |
Output is correct |
102 |
Correct |
6 ms |
760 KB |
Output is correct |
103 |
Correct |
49 ms |
4816 KB |
Output is correct |
104 |
Correct |
41 ms |
4812 KB |
Output is correct |
105 |
Correct |
48 ms |
4812 KB |
Output is correct |
106 |
Correct |
42 ms |
4816 KB |
Output is correct |
107 |
Correct |
48 ms |
4816 KB |
Output is correct |
108 |
Correct |
41 ms |
4812 KB |
Output is correct |
109 |
Correct |
38 ms |
4752 KB |
Output is correct |
110 |
Correct |
37 ms |
4944 KB |
Output is correct |
111 |
Correct |
42 ms |
4816 KB |
Output is correct |
112 |
Correct |
49 ms |
4944 KB |
Output is correct |
113 |
Correct |
44 ms |
4864 KB |
Output is correct |
114 |
Correct |
43 ms |
4816 KB |
Output is correct |
115 |
Correct |
43 ms |
4896 KB |
Output is correct |