#include<bits/stdc++.h>
#define mid (L+R)/2
using namespace std;
int i,ans,k;
int f[200001],sg[200001];
queue<int>q1[200001];
queue<int>q2[200001];
vector<int>s;
void upd(int u,int L,int R,int pos,int y){
if(R < pos || L > pos)return;
if(R == L){sg[u]=y;return;}
else{
upd(u*2,L,mid,pos,y);
upd(u*2+1,mid+1,R,pos,y);
sg[u]=sg[u*2]+sg[u*2+1];
}
}
int get(int u,int L,int R,int a,int b){
if(b < L || a > R)return 0;
if(a <= L && b >= R)return sg[u];
return(get(u*2,L,mid,a,b)+get(u*2+1,mid+1,R,a,b));
}
int count_swaps(std:: vector<int>s){
int n=s.size();
for(i=0;i<s.size();i++){
f[i+1]=s[i];
}
for(i=1;i<=n;i++){
upd(1,1,n,i,1);
}
for(i=1;i<=n;i++){
if(f[i] < 0){
k=-(f[i]);
if(q2[k].size() == 0){
q1[k].push(i);
continue;
}
ans+=get(1,1,n,q2[k].front(),i)-1;
upd(1,1,n,q2[k].front(),2);
upd(1,1,n,i,0);
q2[k].pop();
}
if(f[i] > 0){
k=f[i];
if(q1[k].size() == 0){
q2[k].push(i);
continue;
}
ans+=get(1,1,n,q1[k].front(),i)-2;
upd(1,1,n,q1[k].front(),2);
upd(1,1,n,i,0);
q1[k].pop();
}
}
return ans;
}
Compilation message
shoes.cpp: In function 'int count_swaps(std::vector<int>)':
shoes.cpp:25:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0;i<s.size();i++){
~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
276 ms |
269716 KB |
Output is correct |
2 |
Correct |
301 ms |
269668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
276 ms |
269716 KB |
Output is correct |
2 |
Correct |
301 ms |
269668 KB |
Output is correct |
3 |
Correct |
280 ms |
269588 KB |
Output is correct |
4 |
Correct |
286 ms |
269688 KB |
Output is correct |
5 |
Correct |
278 ms |
269624 KB |
Output is correct |
6 |
Correct |
278 ms |
269536 KB |
Output is correct |
7 |
Correct |
281 ms |
269560 KB |
Output is correct |
8 |
Correct |
282 ms |
269600 KB |
Output is correct |
9 |
Correct |
282 ms |
269688 KB |
Output is correct |
10 |
Correct |
280 ms |
269680 KB |
Output is correct |
11 |
Correct |
280 ms |
269564 KB |
Output is correct |
12 |
Correct |
276 ms |
269620 KB |
Output is correct |
13 |
Correct |
274 ms |
269772 KB |
Output is correct |
14 |
Correct |
280 ms |
269664 KB |
Output is correct |
15 |
Correct |
279 ms |
269560 KB |
Output is correct |
16 |
Correct |
294 ms |
269644 KB |
Output is correct |
17 |
Correct |
318 ms |
269680 KB |
Output is correct |
18 |
Correct |
275 ms |
269548 KB |
Output is correct |
19 |
Correct |
283 ms |
269604 KB |
Output is correct |
20 |
Correct |
277 ms |
269688 KB |
Output is correct |
21 |
Correct |
277 ms |
269560 KB |
Output is correct |
22 |
Correct |
300 ms |
269668 KB |
Output is correct |
23 |
Correct |
279 ms |
269600 KB |
Output is correct |
24 |
Correct |
277 ms |
269688 KB |
Output is correct |
25 |
Correct |
279 ms |
269668 KB |
Output is correct |
26 |
Correct |
412 ms |
269612 KB |
Output is correct |
27 |
Correct |
285 ms |
269888 KB |
Output is correct |
28 |
Correct |
293 ms |
269560 KB |
Output is correct |
29 |
Correct |
282 ms |
269560 KB |
Output is correct |
30 |
Correct |
302 ms |
269692 KB |
Output is correct |
31 |
Correct |
332 ms |
269672 KB |
Output is correct |
32 |
Correct |
324 ms |
269640 KB |
Output is correct |
33 |
Correct |
278 ms |
269560 KB |
Output is correct |
34 |
Correct |
278 ms |
269560 KB |
Output is correct |
35 |
Correct |
280 ms |
269576 KB |
Output is correct |
36 |
Correct |
277 ms |
269560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
276 ms |
269716 KB |
Output is correct |
2 |
Correct |
301 ms |
269668 KB |
Output is correct |
3 |
Correct |
313 ms |
269616 KB |
Output is correct |
4 |
Correct |
305 ms |
269548 KB |
Output is correct |
5 |
Correct |
280 ms |
269560 KB |
Output is correct |
6 |
Correct |
330 ms |
269560 KB |
Output is correct |
7 |
Correct |
279 ms |
269548 KB |
Output is correct |
8 |
Correct |
280 ms |
269628 KB |
Output is correct |
9 |
Correct |
293 ms |
269576 KB |
Output is correct |
10 |
Correct |
277 ms |
269532 KB |
Output is correct |
11 |
Correct |
280 ms |
269520 KB |
Output is correct |
12 |
Correct |
277 ms |
269560 KB |
Output is correct |
13 |
Correct |
278 ms |
269616 KB |
Output is correct |
14 |
Correct |
277 ms |
269688 KB |
Output is correct |
15 |
Correct |
276 ms |
269680 KB |
Output is correct |
16 |
Correct |
273 ms |
269560 KB |
Output is correct |
17 |
Correct |
276 ms |
269688 KB |
Output is correct |
18 |
Correct |
277 ms |
269688 KB |
Output is correct |
19 |
Correct |
275 ms |
269688 KB |
Output is correct |
20 |
Correct |
313 ms |
270072 KB |
Output is correct |
21 |
Correct |
304 ms |
270072 KB |
Output is correct |
22 |
Runtime error |
640 ms |
549852 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
280 ms |
269564 KB |
Output is correct |
2 |
Correct |
281 ms |
269628 KB |
Output is correct |
3 |
Correct |
280 ms |
269628 KB |
Output is correct |
4 |
Correct |
279 ms |
269688 KB |
Output is correct |
5 |
Runtime error |
656 ms |
552624 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
276 ms |
269716 KB |
Output is correct |
2 |
Correct |
301 ms |
269668 KB |
Output is correct |
3 |
Correct |
280 ms |
269588 KB |
Output is correct |
4 |
Correct |
286 ms |
269688 KB |
Output is correct |
5 |
Correct |
278 ms |
269624 KB |
Output is correct |
6 |
Correct |
278 ms |
269536 KB |
Output is correct |
7 |
Correct |
281 ms |
269560 KB |
Output is correct |
8 |
Correct |
282 ms |
269600 KB |
Output is correct |
9 |
Correct |
282 ms |
269688 KB |
Output is correct |
10 |
Correct |
280 ms |
269680 KB |
Output is correct |
11 |
Correct |
280 ms |
269564 KB |
Output is correct |
12 |
Correct |
276 ms |
269620 KB |
Output is correct |
13 |
Correct |
274 ms |
269772 KB |
Output is correct |
14 |
Correct |
280 ms |
269664 KB |
Output is correct |
15 |
Correct |
279 ms |
269560 KB |
Output is correct |
16 |
Correct |
294 ms |
269644 KB |
Output is correct |
17 |
Correct |
318 ms |
269680 KB |
Output is correct |
18 |
Correct |
275 ms |
269548 KB |
Output is correct |
19 |
Correct |
283 ms |
269604 KB |
Output is correct |
20 |
Correct |
277 ms |
269688 KB |
Output is correct |
21 |
Correct |
277 ms |
269560 KB |
Output is correct |
22 |
Correct |
300 ms |
269668 KB |
Output is correct |
23 |
Correct |
279 ms |
269600 KB |
Output is correct |
24 |
Correct |
277 ms |
269688 KB |
Output is correct |
25 |
Correct |
279 ms |
269668 KB |
Output is correct |
26 |
Correct |
412 ms |
269612 KB |
Output is correct |
27 |
Correct |
285 ms |
269888 KB |
Output is correct |
28 |
Correct |
293 ms |
269560 KB |
Output is correct |
29 |
Correct |
282 ms |
269560 KB |
Output is correct |
30 |
Correct |
302 ms |
269692 KB |
Output is correct |
31 |
Correct |
332 ms |
269672 KB |
Output is correct |
32 |
Correct |
324 ms |
269640 KB |
Output is correct |
33 |
Correct |
278 ms |
269560 KB |
Output is correct |
34 |
Correct |
278 ms |
269560 KB |
Output is correct |
35 |
Correct |
280 ms |
269576 KB |
Output is correct |
36 |
Correct |
277 ms |
269560 KB |
Output is correct |
37 |
Correct |
280 ms |
269656 KB |
Output is correct |
38 |
Correct |
278 ms |
269532 KB |
Output is correct |
39 |
Correct |
279 ms |
269560 KB |
Output is correct |
40 |
Correct |
284 ms |
269788 KB |
Output is correct |
41 |
Correct |
282 ms |
269688 KB |
Output is correct |
42 |
Correct |
281 ms |
269816 KB |
Output is correct |
43 |
Correct |
280 ms |
269688 KB |
Output is correct |
44 |
Correct |
279 ms |
269692 KB |
Output is correct |
45 |
Correct |
278 ms |
269688 KB |
Output is correct |
46 |
Correct |
282 ms |
269764 KB |
Output is correct |
47 |
Correct |
280 ms |
269716 KB |
Output is correct |
48 |
Correct |
281 ms |
269652 KB |
Output is correct |
49 |
Correct |
282 ms |
269776 KB |
Output is correct |
50 |
Correct |
277 ms |
269688 KB |
Output is correct |
51 |
Correct |
281 ms |
269944 KB |
Output is correct |
52 |
Correct |
278 ms |
269708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
276 ms |
269716 KB |
Output is correct |
2 |
Correct |
301 ms |
269668 KB |
Output is correct |
3 |
Correct |
280 ms |
269588 KB |
Output is correct |
4 |
Correct |
286 ms |
269688 KB |
Output is correct |
5 |
Correct |
278 ms |
269624 KB |
Output is correct |
6 |
Correct |
278 ms |
269536 KB |
Output is correct |
7 |
Correct |
281 ms |
269560 KB |
Output is correct |
8 |
Correct |
282 ms |
269600 KB |
Output is correct |
9 |
Correct |
282 ms |
269688 KB |
Output is correct |
10 |
Correct |
280 ms |
269680 KB |
Output is correct |
11 |
Correct |
280 ms |
269564 KB |
Output is correct |
12 |
Correct |
276 ms |
269620 KB |
Output is correct |
13 |
Correct |
274 ms |
269772 KB |
Output is correct |
14 |
Correct |
280 ms |
269664 KB |
Output is correct |
15 |
Correct |
279 ms |
269560 KB |
Output is correct |
16 |
Correct |
294 ms |
269644 KB |
Output is correct |
17 |
Correct |
318 ms |
269680 KB |
Output is correct |
18 |
Correct |
275 ms |
269548 KB |
Output is correct |
19 |
Correct |
283 ms |
269604 KB |
Output is correct |
20 |
Correct |
277 ms |
269688 KB |
Output is correct |
21 |
Correct |
277 ms |
269560 KB |
Output is correct |
22 |
Correct |
300 ms |
269668 KB |
Output is correct |
23 |
Correct |
279 ms |
269600 KB |
Output is correct |
24 |
Correct |
277 ms |
269688 KB |
Output is correct |
25 |
Correct |
279 ms |
269668 KB |
Output is correct |
26 |
Correct |
412 ms |
269612 KB |
Output is correct |
27 |
Correct |
285 ms |
269888 KB |
Output is correct |
28 |
Correct |
293 ms |
269560 KB |
Output is correct |
29 |
Correct |
282 ms |
269560 KB |
Output is correct |
30 |
Correct |
302 ms |
269692 KB |
Output is correct |
31 |
Correct |
332 ms |
269672 KB |
Output is correct |
32 |
Correct |
324 ms |
269640 KB |
Output is correct |
33 |
Correct |
278 ms |
269560 KB |
Output is correct |
34 |
Correct |
278 ms |
269560 KB |
Output is correct |
35 |
Correct |
280 ms |
269576 KB |
Output is correct |
36 |
Correct |
277 ms |
269560 KB |
Output is correct |
37 |
Correct |
313 ms |
269616 KB |
Output is correct |
38 |
Correct |
305 ms |
269548 KB |
Output is correct |
39 |
Correct |
280 ms |
269560 KB |
Output is correct |
40 |
Correct |
330 ms |
269560 KB |
Output is correct |
41 |
Correct |
279 ms |
269548 KB |
Output is correct |
42 |
Correct |
280 ms |
269628 KB |
Output is correct |
43 |
Correct |
293 ms |
269576 KB |
Output is correct |
44 |
Correct |
277 ms |
269532 KB |
Output is correct |
45 |
Correct |
280 ms |
269520 KB |
Output is correct |
46 |
Correct |
277 ms |
269560 KB |
Output is correct |
47 |
Correct |
278 ms |
269616 KB |
Output is correct |
48 |
Correct |
277 ms |
269688 KB |
Output is correct |
49 |
Correct |
276 ms |
269680 KB |
Output is correct |
50 |
Correct |
273 ms |
269560 KB |
Output is correct |
51 |
Correct |
276 ms |
269688 KB |
Output is correct |
52 |
Correct |
277 ms |
269688 KB |
Output is correct |
53 |
Correct |
275 ms |
269688 KB |
Output is correct |
54 |
Correct |
313 ms |
270072 KB |
Output is correct |
55 |
Correct |
304 ms |
270072 KB |
Output is correct |
56 |
Runtime error |
640 ms |
549852 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
57 |
Halted |
0 ms |
0 KB |
- |