#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define f first
#define s second
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
const int MAXN = 500100;
ll fen[MAXN];
void upd (int p, ll x) {
p++;
for (int i = p; i < MAXN; i += i&(-i))
fen[i] += x;
}
ll get (int p) {
p++;
ll ret = 0ll;
for (int i = p; i > 0; i -= i&(-i))
ret += fen[i];
return ret;
}
ll get (int le, int ri) {
return get(ri) - get(le-1);
}
map<int, queue<int>> q;
long long count_swaps(std::vector<int> s) {
int n = (int)s.size();
FOR(i, 0, n-1) upd(i, 1);
FOR(i, 0, n-1) q[s[i]].push(i);
ll ret = 0;
FOR(i, 0, n-1) {
if (get(i,i) == 0) continue;
q[s[i]].pop();
int id = q[-s[i]].front();
q[-s[i]].pop();
if (s[i] > 0) ret++;
upd (i, -1);
upd (id, -1);
ret += get(i, id);
}
return ret;
}
/*
2
2 1 -1 -2
ans:
4
3
-2 2 2 -2 -2 2
ans:
1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
416 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
6 ms |
896 KB |
Output is correct |
21 |
Correct |
6 ms |
896 KB |
Output is correct |
22 |
Correct |
53 ms |
5004 KB |
Output is correct |
23 |
Correct |
51 ms |
5752 KB |
Output is correct |
24 |
Correct |
54 ms |
5624 KB |
Output is correct |
25 |
Correct |
53 ms |
5624 KB |
Output is correct |
26 |
Correct |
52 ms |
5624 KB |
Output is correct |
27 |
Correct |
47 ms |
5368 KB |
Output is correct |
28 |
Correct |
52 ms |
5624 KB |
Output is correct |
29 |
Correct |
51 ms |
5624 KB |
Output is correct |
30 |
Correct |
53 ms |
5880 KB |
Output is correct |
31 |
Correct |
54 ms |
5624 KB |
Output is correct |
32 |
Correct |
51 ms |
5752 KB |
Output is correct |
33 |
Correct |
49 ms |
5368 KB |
Output is correct |
34 |
Correct |
50 ms |
5624 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
1 ms |
384 KB |
Output is correct |
37 |
Correct |
50 ms |
5624 KB |
Output is correct |
38 |
Correct |
50 ms |
5752 KB |
Output is correct |
39 |
Correct |
51 ms |
5624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
563 ms |
147960 KB |
Output is correct |
6 |
Correct |
179 ms |
17456 KB |
Output is correct |
7 |
Correct |
562 ms |
148860 KB |
Output is correct |
8 |
Correct |
54 ms |
5624 KB |
Output is correct |
9 |
Correct |
554 ms |
148980 KB |
Output is correct |
10 |
Correct |
409 ms |
76920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
416 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
1 ms |
384 KB |
Output is correct |
37 |
Correct |
1 ms |
512 KB |
Output is correct |
38 |
Correct |
1 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
512 KB |
Output is correct |
40 |
Correct |
1 ms |
640 KB |
Output is correct |
41 |
Correct |
3 ms |
1920 KB |
Output is correct |
42 |
Correct |
3 ms |
1792 KB |
Output is correct |
43 |
Correct |
3 ms |
1664 KB |
Output is correct |
44 |
Correct |
3 ms |
1408 KB |
Output is correct |
45 |
Correct |
3 ms |
1408 KB |
Output is correct |
46 |
Correct |
3 ms |
1152 KB |
Output is correct |
47 |
Correct |
2 ms |
1024 KB |
Output is correct |
48 |
Correct |
2 ms |
896 KB |
Output is correct |
49 |
Correct |
2 ms |
640 KB |
Output is correct |
50 |
Correct |
1 ms |
384 KB |
Output is correct |
51 |
Correct |
2 ms |
384 KB |
Output is correct |
52 |
Correct |
3 ms |
1792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
416 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
1 ms |
384 KB |
Output is correct |
37 |
Correct |
1 ms |
384 KB |
Output is correct |
38 |
Correct |
1 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
1 ms |
384 KB |
Output is correct |
41 |
Correct |
1 ms |
384 KB |
Output is correct |
42 |
Correct |
1 ms |
512 KB |
Output is correct |
43 |
Correct |
1 ms |
384 KB |
Output is correct |
44 |
Correct |
1 ms |
384 KB |
Output is correct |
45 |
Correct |
1 ms |
384 KB |
Output is correct |
46 |
Correct |
1 ms |
384 KB |
Output is correct |
47 |
Correct |
1 ms |
384 KB |
Output is correct |
48 |
Correct |
1 ms |
384 KB |
Output is correct |
49 |
Correct |
1 ms |
384 KB |
Output is correct |
50 |
Correct |
2 ms |
384 KB |
Output is correct |
51 |
Correct |
1 ms |
384 KB |
Output is correct |
52 |
Correct |
1 ms |
384 KB |
Output is correct |
53 |
Correct |
1 ms |
384 KB |
Output is correct |
54 |
Correct |
6 ms |
896 KB |
Output is correct |
55 |
Correct |
6 ms |
896 KB |
Output is correct |
56 |
Correct |
53 ms |
5004 KB |
Output is correct |
57 |
Correct |
51 ms |
5752 KB |
Output is correct |
58 |
Correct |
54 ms |
5624 KB |
Output is correct |
59 |
Correct |
53 ms |
5624 KB |
Output is correct |
60 |
Correct |
52 ms |
5624 KB |
Output is correct |
61 |
Correct |
47 ms |
5368 KB |
Output is correct |
62 |
Correct |
52 ms |
5624 KB |
Output is correct |
63 |
Correct |
51 ms |
5624 KB |
Output is correct |
64 |
Correct |
53 ms |
5880 KB |
Output is correct |
65 |
Correct |
54 ms |
5624 KB |
Output is correct |
66 |
Correct |
51 ms |
5752 KB |
Output is correct |
67 |
Correct |
49 ms |
5368 KB |
Output is correct |
68 |
Correct |
50 ms |
5624 KB |
Output is correct |
69 |
Correct |
1 ms |
384 KB |
Output is correct |
70 |
Correct |
1 ms |
384 KB |
Output is correct |
71 |
Correct |
50 ms |
5624 KB |
Output is correct |
72 |
Correct |
50 ms |
5752 KB |
Output is correct |
73 |
Correct |
51 ms |
5624 KB |
Output is correct |
74 |
Correct |
1 ms |
512 KB |
Output is correct |
75 |
Correct |
1 ms |
384 KB |
Output is correct |
76 |
Correct |
1 ms |
384 KB |
Output is correct |
77 |
Correct |
1 ms |
384 KB |
Output is correct |
78 |
Correct |
563 ms |
147960 KB |
Output is correct |
79 |
Correct |
179 ms |
17456 KB |
Output is correct |
80 |
Correct |
562 ms |
148860 KB |
Output is correct |
81 |
Correct |
54 ms |
5624 KB |
Output is correct |
82 |
Correct |
554 ms |
148980 KB |
Output is correct |
83 |
Correct |
409 ms |
76920 KB |
Output is correct |
84 |
Correct |
1 ms |
512 KB |
Output is correct |
85 |
Correct |
1 ms |
384 KB |
Output is correct |
86 |
Correct |
1 ms |
512 KB |
Output is correct |
87 |
Correct |
1 ms |
640 KB |
Output is correct |
88 |
Correct |
3 ms |
1920 KB |
Output is correct |
89 |
Correct |
3 ms |
1792 KB |
Output is correct |
90 |
Correct |
3 ms |
1664 KB |
Output is correct |
91 |
Correct |
3 ms |
1408 KB |
Output is correct |
92 |
Correct |
3 ms |
1408 KB |
Output is correct |
93 |
Correct |
3 ms |
1152 KB |
Output is correct |
94 |
Correct |
2 ms |
1024 KB |
Output is correct |
95 |
Correct |
2 ms |
896 KB |
Output is correct |
96 |
Correct |
2 ms |
640 KB |
Output is correct |
97 |
Correct |
1 ms |
384 KB |
Output is correct |
98 |
Correct |
2 ms |
384 KB |
Output is correct |
99 |
Correct |
3 ms |
1792 KB |
Output is correct |
100 |
Correct |
3 ms |
1792 KB |
Output is correct |
101 |
Correct |
37 ms |
13696 KB |
Output is correct |
102 |
Correct |
15 ms |
3616 KB |
Output is correct |
103 |
Correct |
661 ms |
148728 KB |
Output is correct |
104 |
Correct |
544 ms |
148696 KB |
Output is correct |
105 |
Correct |
503 ms |
86696 KB |
Output is correct |
106 |
Correct |
556 ms |
148860 KB |
Output is correct |
107 |
Correct |
227 ms |
20728 KB |
Output is correct |
108 |
Correct |
280 ms |
36728 KB |
Output is correct |
109 |
Correct |
53 ms |
5624 KB |
Output is correct |
110 |
Correct |
49 ms |
5752 KB |
Output is correct |
111 |
Correct |
522 ms |
132856 KB |
Output is correct |
112 |
Correct |
555 ms |
116888 KB |
Output is correct |
113 |
Correct |
222 ms |
22520 KB |
Output is correct |
114 |
Correct |
561 ms |
148884 KB |
Output is correct |
115 |
Correct |
575 ms |
148984 KB |
Output is correct |