#include "shoes.h"
#include<bits/stdc++.h>
using namespace std;
#define INIT ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
int fw[200010];
queue<int> l[100010], r[100010];
void update(int i, int x){
for(int j=(200000-i+1); j<=200000; j+=(j&(-j))){
fw[j]+=x;
}
}
int query(int i){
int res=0;
for(int j=(200000-i+1); j>0; j-=(j&(-j))){
res+=fw[j];
}
return res;
}
bool v[200010];
long long count_swaps(std::vector<int> s) {
int n=s.size()/2;
for(int i=0; i<2*n; i++){
if(s[i]<0){
l[-s[i] ].push(i+1);
}
else{
r[s[i] ].push(i+1);
}
}
ll res=0;
int p1=1;
for(int i=1; i<=n; i++){
while(v[p1]==true){p1++;}
v[p1]=true;
int p=p1;
int c=s[p-1];
p+=query(p);
if(c<0){
int j=r[-c].front();
v[j]=true;
update(j, 1);
j+=query(j);
l[-c].pop();
r[-c].pop();
res+=j-p-2;
}
else{
int j=l[c].front();
v[j]=true;
update(j, 1);
j+=query(j);
l[c].pop();
r[c].pop();
res+=j-p-1;
}
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
135040 KB |
Output is correct |
2 |
Correct |
97 ms |
135020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
135040 KB |
Output is correct |
2 |
Correct |
97 ms |
135020 KB |
Output is correct |
3 |
Correct |
97 ms |
135020 KB |
Output is correct |
4 |
Correct |
96 ms |
135020 KB |
Output is correct |
5 |
Correct |
95 ms |
135020 KB |
Output is correct |
6 |
Correct |
97 ms |
135020 KB |
Output is correct |
7 |
Correct |
95 ms |
134996 KB |
Output is correct |
8 |
Correct |
96 ms |
135020 KB |
Output is correct |
9 |
Correct |
97 ms |
135020 KB |
Output is correct |
10 |
Correct |
97 ms |
135020 KB |
Output is correct |
11 |
Correct |
95 ms |
135020 KB |
Output is correct |
12 |
Correct |
96 ms |
135020 KB |
Output is correct |
13 |
Correct |
98 ms |
135020 KB |
Output is correct |
14 |
Correct |
97 ms |
135020 KB |
Output is correct |
15 |
Correct |
95 ms |
135020 KB |
Output is correct |
16 |
Correct |
96 ms |
135020 KB |
Output is correct |
17 |
Correct |
95 ms |
135020 KB |
Output is correct |
18 |
Correct |
95 ms |
135020 KB |
Output is correct |
19 |
Correct |
96 ms |
135020 KB |
Output is correct |
20 |
Correct |
96 ms |
135020 KB |
Output is correct |
21 |
Correct |
94 ms |
135020 KB |
Output is correct |
22 |
Correct |
96 ms |
135020 KB |
Output is correct |
23 |
Correct |
96 ms |
135020 KB |
Output is correct |
24 |
Correct |
96 ms |
135020 KB |
Output is correct |
25 |
Correct |
96 ms |
135020 KB |
Output is correct |
26 |
Correct |
96 ms |
135020 KB |
Output is correct |
27 |
Correct |
96 ms |
135020 KB |
Output is correct |
28 |
Correct |
96 ms |
135020 KB |
Output is correct |
29 |
Correct |
99 ms |
135020 KB |
Output is correct |
30 |
Correct |
97 ms |
135020 KB |
Output is correct |
31 |
Correct |
97 ms |
135020 KB |
Output is correct |
32 |
Correct |
95 ms |
135020 KB |
Output is correct |
33 |
Correct |
95 ms |
135020 KB |
Output is correct |
34 |
Correct |
94 ms |
135020 KB |
Output is correct |
35 |
Correct |
95 ms |
135020 KB |
Output is correct |
36 |
Correct |
96 ms |
135020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
135040 KB |
Output is correct |
2 |
Correct |
97 ms |
135020 KB |
Output is correct |
3 |
Correct |
95 ms |
135020 KB |
Output is correct |
4 |
Correct |
96 ms |
135020 KB |
Output is correct |
5 |
Correct |
96 ms |
134912 KB |
Output is correct |
6 |
Correct |
96 ms |
135020 KB |
Output is correct |
7 |
Correct |
95 ms |
135020 KB |
Output is correct |
8 |
Correct |
93 ms |
135020 KB |
Output is correct |
9 |
Correct |
94 ms |
135020 KB |
Output is correct |
10 |
Correct |
93 ms |
135020 KB |
Output is correct |
11 |
Correct |
95 ms |
135020 KB |
Output is correct |
12 |
Correct |
94 ms |
135020 KB |
Output is correct |
13 |
Correct |
95 ms |
135040 KB |
Output is correct |
14 |
Correct |
93 ms |
135020 KB |
Output is correct |
15 |
Correct |
94 ms |
135020 KB |
Output is correct |
16 |
Correct |
97 ms |
135020 KB |
Output is correct |
17 |
Correct |
99 ms |
135020 KB |
Output is correct |
18 |
Correct |
101 ms |
135020 KB |
Output is correct |
19 |
Correct |
103 ms |
135020 KB |
Output is correct |
20 |
Correct |
110 ms |
135276 KB |
Output is correct |
21 |
Correct |
107 ms |
135276 KB |
Output is correct |
22 |
Correct |
139 ms |
138348 KB |
Output is correct |
23 |
Correct |
136 ms |
139756 KB |
Output is correct |
24 |
Correct |
141 ms |
139628 KB |
Output is correct |
25 |
Correct |
133 ms |
139116 KB |
Output is correct |
26 |
Correct |
138 ms |
139628 KB |
Output is correct |
27 |
Correct |
133 ms |
139372 KB |
Output is correct |
28 |
Correct |
154 ms |
139372 KB |
Output is correct |
29 |
Correct |
133 ms |
139372 KB |
Output is correct |
30 |
Correct |
130 ms |
139244 KB |
Output is correct |
31 |
Correct |
135 ms |
139768 KB |
Output is correct |
32 |
Correct |
134 ms |
139244 KB |
Output is correct |
33 |
Correct |
133 ms |
139116 KB |
Output is correct |
34 |
Correct |
137 ms |
139244 KB |
Output is correct |
35 |
Correct |
96 ms |
135020 KB |
Output is correct |
36 |
Correct |
95 ms |
135148 KB |
Output is correct |
37 |
Correct |
132 ms |
139244 KB |
Output is correct |
38 |
Correct |
133 ms |
139244 KB |
Output is correct |
39 |
Correct |
131 ms |
139372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
135020 KB |
Output is correct |
2 |
Correct |
96 ms |
135020 KB |
Output is correct |
3 |
Correct |
94 ms |
135020 KB |
Output is correct |
4 |
Correct |
95 ms |
135020 KB |
Output is correct |
5 |
Correct |
169 ms |
137196 KB |
Output is correct |
6 |
Correct |
142 ms |
138348 KB |
Output is correct |
7 |
Correct |
173 ms |
138348 KB |
Output is correct |
8 |
Correct |
134 ms |
139372 KB |
Output is correct |
9 |
Correct |
172 ms |
138348 KB |
Output is correct |
10 |
Correct |
165 ms |
138476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
135040 KB |
Output is correct |
2 |
Correct |
97 ms |
135020 KB |
Output is correct |
3 |
Correct |
97 ms |
135020 KB |
Output is correct |
4 |
Correct |
96 ms |
135020 KB |
Output is correct |
5 |
Correct |
95 ms |
135020 KB |
Output is correct |
6 |
Correct |
97 ms |
135020 KB |
Output is correct |
7 |
Correct |
95 ms |
134996 KB |
Output is correct |
8 |
Correct |
96 ms |
135020 KB |
Output is correct |
9 |
Correct |
97 ms |
135020 KB |
Output is correct |
10 |
Correct |
97 ms |
135020 KB |
Output is correct |
11 |
Correct |
95 ms |
135020 KB |
Output is correct |
12 |
Correct |
96 ms |
135020 KB |
Output is correct |
13 |
Correct |
98 ms |
135020 KB |
Output is correct |
14 |
Correct |
97 ms |
135020 KB |
Output is correct |
15 |
Correct |
95 ms |
135020 KB |
Output is correct |
16 |
Correct |
96 ms |
135020 KB |
Output is correct |
17 |
Correct |
95 ms |
135020 KB |
Output is correct |
18 |
Correct |
95 ms |
135020 KB |
Output is correct |
19 |
Correct |
96 ms |
135020 KB |
Output is correct |
20 |
Correct |
96 ms |
135020 KB |
Output is correct |
21 |
Correct |
94 ms |
135020 KB |
Output is correct |
22 |
Correct |
96 ms |
135020 KB |
Output is correct |
23 |
Correct |
96 ms |
135020 KB |
Output is correct |
24 |
Correct |
96 ms |
135020 KB |
Output is correct |
25 |
Correct |
96 ms |
135020 KB |
Output is correct |
26 |
Correct |
96 ms |
135020 KB |
Output is correct |
27 |
Correct |
96 ms |
135020 KB |
Output is correct |
28 |
Correct |
96 ms |
135020 KB |
Output is correct |
29 |
Correct |
99 ms |
135020 KB |
Output is correct |
30 |
Correct |
97 ms |
135020 KB |
Output is correct |
31 |
Correct |
97 ms |
135020 KB |
Output is correct |
32 |
Correct |
95 ms |
135020 KB |
Output is correct |
33 |
Correct |
95 ms |
135020 KB |
Output is correct |
34 |
Correct |
94 ms |
135020 KB |
Output is correct |
35 |
Correct |
95 ms |
135020 KB |
Output is correct |
36 |
Correct |
96 ms |
135020 KB |
Output is correct |
37 |
Correct |
94 ms |
135020 KB |
Output is correct |
38 |
Correct |
95 ms |
135020 KB |
Output is correct |
39 |
Correct |
94 ms |
135020 KB |
Output is correct |
40 |
Correct |
94 ms |
135020 KB |
Output is correct |
41 |
Correct |
95 ms |
135020 KB |
Output is correct |
42 |
Correct |
94 ms |
134988 KB |
Output is correct |
43 |
Correct |
95 ms |
135148 KB |
Output is correct |
44 |
Correct |
94 ms |
135020 KB |
Output is correct |
45 |
Correct |
94 ms |
135032 KB |
Output is correct |
46 |
Correct |
95 ms |
135020 KB |
Output is correct |
47 |
Correct |
97 ms |
135020 KB |
Output is correct |
48 |
Correct |
95 ms |
135020 KB |
Output is correct |
49 |
Correct |
94 ms |
135020 KB |
Output is correct |
50 |
Correct |
98 ms |
135020 KB |
Output is correct |
51 |
Correct |
102 ms |
135020 KB |
Output is correct |
52 |
Correct |
97 ms |
135020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
135040 KB |
Output is correct |
2 |
Correct |
97 ms |
135020 KB |
Output is correct |
3 |
Correct |
97 ms |
135020 KB |
Output is correct |
4 |
Correct |
96 ms |
135020 KB |
Output is correct |
5 |
Correct |
95 ms |
135020 KB |
Output is correct |
6 |
Correct |
97 ms |
135020 KB |
Output is correct |
7 |
Correct |
95 ms |
134996 KB |
Output is correct |
8 |
Correct |
96 ms |
135020 KB |
Output is correct |
9 |
Correct |
97 ms |
135020 KB |
Output is correct |
10 |
Correct |
97 ms |
135020 KB |
Output is correct |
11 |
Correct |
95 ms |
135020 KB |
Output is correct |
12 |
Correct |
96 ms |
135020 KB |
Output is correct |
13 |
Correct |
98 ms |
135020 KB |
Output is correct |
14 |
Correct |
97 ms |
135020 KB |
Output is correct |
15 |
Correct |
95 ms |
135020 KB |
Output is correct |
16 |
Correct |
96 ms |
135020 KB |
Output is correct |
17 |
Correct |
95 ms |
135020 KB |
Output is correct |
18 |
Correct |
95 ms |
135020 KB |
Output is correct |
19 |
Correct |
96 ms |
135020 KB |
Output is correct |
20 |
Correct |
96 ms |
135020 KB |
Output is correct |
21 |
Correct |
94 ms |
135020 KB |
Output is correct |
22 |
Correct |
96 ms |
135020 KB |
Output is correct |
23 |
Correct |
96 ms |
135020 KB |
Output is correct |
24 |
Correct |
96 ms |
135020 KB |
Output is correct |
25 |
Correct |
96 ms |
135020 KB |
Output is correct |
26 |
Correct |
96 ms |
135020 KB |
Output is correct |
27 |
Correct |
96 ms |
135020 KB |
Output is correct |
28 |
Correct |
96 ms |
135020 KB |
Output is correct |
29 |
Correct |
99 ms |
135020 KB |
Output is correct |
30 |
Correct |
97 ms |
135020 KB |
Output is correct |
31 |
Correct |
97 ms |
135020 KB |
Output is correct |
32 |
Correct |
95 ms |
135020 KB |
Output is correct |
33 |
Correct |
95 ms |
135020 KB |
Output is correct |
34 |
Correct |
94 ms |
135020 KB |
Output is correct |
35 |
Correct |
95 ms |
135020 KB |
Output is correct |
36 |
Correct |
96 ms |
135020 KB |
Output is correct |
37 |
Correct |
95 ms |
135020 KB |
Output is correct |
38 |
Correct |
96 ms |
135020 KB |
Output is correct |
39 |
Correct |
96 ms |
134912 KB |
Output is correct |
40 |
Correct |
96 ms |
135020 KB |
Output is correct |
41 |
Correct |
95 ms |
135020 KB |
Output is correct |
42 |
Correct |
93 ms |
135020 KB |
Output is correct |
43 |
Correct |
94 ms |
135020 KB |
Output is correct |
44 |
Correct |
93 ms |
135020 KB |
Output is correct |
45 |
Correct |
95 ms |
135020 KB |
Output is correct |
46 |
Correct |
94 ms |
135020 KB |
Output is correct |
47 |
Correct |
95 ms |
135040 KB |
Output is correct |
48 |
Correct |
93 ms |
135020 KB |
Output is correct |
49 |
Correct |
94 ms |
135020 KB |
Output is correct |
50 |
Correct |
97 ms |
135020 KB |
Output is correct |
51 |
Correct |
99 ms |
135020 KB |
Output is correct |
52 |
Correct |
101 ms |
135020 KB |
Output is correct |
53 |
Correct |
103 ms |
135020 KB |
Output is correct |
54 |
Correct |
110 ms |
135276 KB |
Output is correct |
55 |
Correct |
107 ms |
135276 KB |
Output is correct |
56 |
Correct |
139 ms |
138348 KB |
Output is correct |
57 |
Correct |
136 ms |
139756 KB |
Output is correct |
58 |
Correct |
141 ms |
139628 KB |
Output is correct |
59 |
Correct |
133 ms |
139116 KB |
Output is correct |
60 |
Correct |
138 ms |
139628 KB |
Output is correct |
61 |
Correct |
133 ms |
139372 KB |
Output is correct |
62 |
Correct |
154 ms |
139372 KB |
Output is correct |
63 |
Correct |
133 ms |
139372 KB |
Output is correct |
64 |
Correct |
130 ms |
139244 KB |
Output is correct |
65 |
Correct |
135 ms |
139768 KB |
Output is correct |
66 |
Correct |
134 ms |
139244 KB |
Output is correct |
67 |
Correct |
133 ms |
139116 KB |
Output is correct |
68 |
Correct |
137 ms |
139244 KB |
Output is correct |
69 |
Correct |
96 ms |
135020 KB |
Output is correct |
70 |
Correct |
95 ms |
135148 KB |
Output is correct |
71 |
Correct |
132 ms |
139244 KB |
Output is correct |
72 |
Correct |
133 ms |
139244 KB |
Output is correct |
73 |
Correct |
131 ms |
139372 KB |
Output is correct |
74 |
Correct |
95 ms |
135020 KB |
Output is correct |
75 |
Correct |
96 ms |
135020 KB |
Output is correct |
76 |
Correct |
94 ms |
135020 KB |
Output is correct |
77 |
Correct |
95 ms |
135020 KB |
Output is correct |
78 |
Correct |
169 ms |
137196 KB |
Output is correct |
79 |
Correct |
142 ms |
138348 KB |
Output is correct |
80 |
Correct |
173 ms |
138348 KB |
Output is correct |
81 |
Correct |
134 ms |
139372 KB |
Output is correct |
82 |
Correct |
172 ms |
138348 KB |
Output is correct |
83 |
Correct |
165 ms |
138476 KB |
Output is correct |
84 |
Correct |
94 ms |
135020 KB |
Output is correct |
85 |
Correct |
95 ms |
135020 KB |
Output is correct |
86 |
Correct |
94 ms |
135020 KB |
Output is correct |
87 |
Correct |
94 ms |
135020 KB |
Output is correct |
88 |
Correct |
95 ms |
135020 KB |
Output is correct |
89 |
Correct |
94 ms |
134988 KB |
Output is correct |
90 |
Correct |
95 ms |
135148 KB |
Output is correct |
91 |
Correct |
94 ms |
135020 KB |
Output is correct |
92 |
Correct |
94 ms |
135032 KB |
Output is correct |
93 |
Correct |
95 ms |
135020 KB |
Output is correct |
94 |
Correct |
97 ms |
135020 KB |
Output is correct |
95 |
Correct |
95 ms |
135020 KB |
Output is correct |
96 |
Correct |
94 ms |
135020 KB |
Output is correct |
97 |
Correct |
98 ms |
135020 KB |
Output is correct |
98 |
Correct |
102 ms |
135020 KB |
Output is correct |
99 |
Correct |
97 ms |
135020 KB |
Output is correct |
100 |
Correct |
95 ms |
135020 KB |
Output is correct |
101 |
Correct |
100 ms |
135276 KB |
Output is correct |
102 |
Correct |
99 ms |
135276 KB |
Output is correct |
103 |
Correct |
178 ms |
138860 KB |
Output is correct |
104 |
Correct |
175 ms |
138860 KB |
Output is correct |
105 |
Correct |
178 ms |
138732 KB |
Output is correct |
106 |
Correct |
171 ms |
138476 KB |
Output is correct |
107 |
Correct |
156 ms |
138732 KB |
Output is correct |
108 |
Correct |
161 ms |
138732 KB |
Output is correct |
109 |
Correct |
133 ms |
139244 KB |
Output is correct |
110 |
Correct |
133 ms |
139372 KB |
Output is correct |
111 |
Correct |
167 ms |
138348 KB |
Output is correct |
112 |
Correct |
179 ms |
138732 KB |
Output is correct |
113 |
Correct |
148 ms |
138368 KB |
Output is correct |
114 |
Correct |
170 ms |
138348 KB |
Output is correct |
115 |
Correct |
171 ms |
138348 KB |
Output is correct |