//#include "grader.cpp"
#include "shoes.h"
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N=200010;
int t[N];
void upd(int n,int pos,int x){
for (;pos<=n;pos|=pos+1) t[pos]+=x;
}
int get(int pos){
int sum=0;
for (;pos>=0;pos&=pos+1,pos--) sum+=t[pos];
return sum;
}
set<int>open[N],close[N];
int r[N];
ll count_swaps(vector<int> s) {
for (int i=0;i<s.size();i++) s[i]=-s[i];
for (int i=0;i<s.size();i++){
if (s[i]>0) open[s[i]].insert(i);
else if (s[i]<0) close[-s[i]].insert(i);
}
ll res=0ll;
for (int i=0;i<s.size();i++){
if (r[i]==-1) continue;
if (s[i]>0){
r[i]=(*close[s[i]].begin());
r[r[i]]=-1;
close[s[i]].erase(close[s[i]].begin());
open[s[i]].erase(i);
} else {
r[i]=(*open[-s[i]].begin());
r[r[i]]=-1;
open[-s[i]].erase(open[-s[i]].begin());
res++;
close[-s[i]].erase(i);
}
// cout<<i<<" "<<r[i]<<endl;
}
for (int i=0;i<s.size();i++){
upd(s.size(),i,1);
}
for (int i=0;i<s.size();i++){
if (r[i]==-1) continue;
// cout<<i<<" "<<r[i]<<endl;
res+=get(r[i]-1)-get(i);
upd(s.size(),r[i],-1);
}
return res;
}
Compilation message
shoes.cpp: In function 'll count_swaps(std::vector<int>)':
shoes.cpp:19:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for (int i=0;i<s.size();i++) s[i]=-s[i];
| ~^~~~~~~~~
shoes.cpp:20:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for (int i=0;i<s.size();i++){
| ~^~~~~~~~~
shoes.cpp:25:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for (int i=0;i<s.size();i++){
| ~^~~~~~~~~
shoes.cpp:42:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int i=0;i<s.size();i++){
| ~^~~~~~~~~
shoes.cpp:45:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for (int i=0;i<s.size();i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
19020 KB |
Output is correct |
2 |
Correct |
12 ms |
19052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
19020 KB |
Output is correct |
2 |
Correct |
12 ms |
19052 KB |
Output is correct |
3 |
Correct |
12 ms |
19020 KB |
Output is correct |
4 |
Correct |
12 ms |
19048 KB |
Output is correct |
5 |
Correct |
12 ms |
19020 KB |
Output is correct |
6 |
Correct |
12 ms |
19020 KB |
Output is correct |
7 |
Correct |
12 ms |
19020 KB |
Output is correct |
8 |
Correct |
12 ms |
19088 KB |
Output is correct |
9 |
Correct |
12 ms |
19020 KB |
Output is correct |
10 |
Correct |
12 ms |
19020 KB |
Output is correct |
11 |
Correct |
12 ms |
19084 KB |
Output is correct |
12 |
Correct |
12 ms |
19020 KB |
Output is correct |
13 |
Correct |
12 ms |
19020 KB |
Output is correct |
14 |
Correct |
14 ms |
19076 KB |
Output is correct |
15 |
Correct |
13 ms |
19020 KB |
Output is correct |
16 |
Correct |
12 ms |
19020 KB |
Output is correct |
17 |
Correct |
12 ms |
18992 KB |
Output is correct |
18 |
Correct |
12 ms |
19056 KB |
Output is correct |
19 |
Correct |
11 ms |
19020 KB |
Output is correct |
20 |
Correct |
12 ms |
19020 KB |
Output is correct |
21 |
Correct |
12 ms |
19020 KB |
Output is correct |
22 |
Correct |
12 ms |
19008 KB |
Output is correct |
23 |
Correct |
12 ms |
19008 KB |
Output is correct |
24 |
Correct |
12 ms |
19020 KB |
Output is correct |
25 |
Correct |
12 ms |
19020 KB |
Output is correct |
26 |
Correct |
12 ms |
19084 KB |
Output is correct |
27 |
Correct |
12 ms |
18996 KB |
Output is correct |
28 |
Correct |
12 ms |
19020 KB |
Output is correct |
29 |
Correct |
12 ms |
19020 KB |
Output is correct |
30 |
Correct |
12 ms |
18976 KB |
Output is correct |
31 |
Correct |
12 ms |
19076 KB |
Output is correct |
32 |
Correct |
12 ms |
19020 KB |
Output is correct |
33 |
Correct |
12 ms |
19020 KB |
Output is correct |
34 |
Correct |
12 ms |
19100 KB |
Output is correct |
35 |
Correct |
13 ms |
19096 KB |
Output is correct |
36 |
Correct |
12 ms |
19020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
19020 KB |
Output is correct |
2 |
Correct |
12 ms |
19052 KB |
Output is correct |
3 |
Correct |
13 ms |
19004 KB |
Output is correct |
4 |
Correct |
12 ms |
19020 KB |
Output is correct |
5 |
Correct |
12 ms |
19020 KB |
Output is correct |
6 |
Correct |
12 ms |
19096 KB |
Output is correct |
7 |
Correct |
14 ms |
19148 KB |
Output is correct |
8 |
Correct |
12 ms |
19020 KB |
Output is correct |
9 |
Correct |
12 ms |
18988 KB |
Output is correct |
10 |
Correct |
12 ms |
19100 KB |
Output is correct |
11 |
Correct |
12 ms |
18988 KB |
Output is correct |
12 |
Correct |
12 ms |
19052 KB |
Output is correct |
13 |
Correct |
12 ms |
19020 KB |
Output is correct |
14 |
Correct |
12 ms |
18996 KB |
Output is correct |
15 |
Correct |
12 ms |
19020 KB |
Output is correct |
16 |
Correct |
12 ms |
19020 KB |
Output is correct |
17 |
Correct |
12 ms |
19148 KB |
Output is correct |
18 |
Correct |
12 ms |
19148 KB |
Output is correct |
19 |
Correct |
13 ms |
19148 KB |
Output is correct |
20 |
Correct |
24 ms |
20320 KB |
Output is correct |
21 |
Correct |
20 ms |
20300 KB |
Output is correct |
22 |
Correct |
118 ms |
31588 KB |
Output is correct |
23 |
Correct |
110 ms |
31556 KB |
Output is correct |
24 |
Correct |
98 ms |
31528 KB |
Output is correct |
25 |
Correct |
102 ms |
31512 KB |
Output is correct |
26 |
Correct |
96 ms |
32748 KB |
Output is correct |
27 |
Correct |
108 ms |
32656 KB |
Output is correct |
28 |
Correct |
103 ms |
32780 KB |
Output is correct |
29 |
Correct |
102 ms |
32836 KB |
Output is correct |
30 |
Correct |
101 ms |
32816 KB |
Output is correct |
31 |
Correct |
99 ms |
32780 KB |
Output is correct |
32 |
Correct |
103 ms |
32780 KB |
Output is correct |
33 |
Correct |
101 ms |
32684 KB |
Output is correct |
34 |
Correct |
103 ms |
32852 KB |
Output is correct |
35 |
Correct |
12 ms |
19020 KB |
Output is correct |
36 |
Correct |
14 ms |
19020 KB |
Output is correct |
37 |
Correct |
105 ms |
32828 KB |
Output is correct |
38 |
Correct |
105 ms |
32792 KB |
Output is correct |
39 |
Correct |
104 ms |
32792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
19044 KB |
Output is correct |
2 |
Correct |
13 ms |
18972 KB |
Output is correct |
3 |
Correct |
11 ms |
19020 KB |
Output is correct |
4 |
Correct |
12 ms |
19020 KB |
Output is correct |
5 |
Correct |
107 ms |
31600 KB |
Output is correct |
6 |
Correct |
130 ms |
32788 KB |
Output is correct |
7 |
Correct |
104 ms |
32804 KB |
Output is correct |
8 |
Correct |
92 ms |
32788 KB |
Output is correct |
9 |
Correct |
93 ms |
32792 KB |
Output is correct |
10 |
Correct |
139 ms |
32924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
19020 KB |
Output is correct |
2 |
Correct |
12 ms |
19052 KB |
Output is correct |
3 |
Correct |
12 ms |
19020 KB |
Output is correct |
4 |
Correct |
12 ms |
19048 KB |
Output is correct |
5 |
Correct |
12 ms |
19020 KB |
Output is correct |
6 |
Correct |
12 ms |
19020 KB |
Output is correct |
7 |
Correct |
12 ms |
19020 KB |
Output is correct |
8 |
Correct |
12 ms |
19088 KB |
Output is correct |
9 |
Correct |
12 ms |
19020 KB |
Output is correct |
10 |
Correct |
12 ms |
19020 KB |
Output is correct |
11 |
Correct |
12 ms |
19084 KB |
Output is correct |
12 |
Correct |
12 ms |
19020 KB |
Output is correct |
13 |
Correct |
12 ms |
19020 KB |
Output is correct |
14 |
Correct |
14 ms |
19076 KB |
Output is correct |
15 |
Correct |
13 ms |
19020 KB |
Output is correct |
16 |
Correct |
12 ms |
19020 KB |
Output is correct |
17 |
Correct |
12 ms |
18992 KB |
Output is correct |
18 |
Correct |
12 ms |
19056 KB |
Output is correct |
19 |
Correct |
11 ms |
19020 KB |
Output is correct |
20 |
Correct |
12 ms |
19020 KB |
Output is correct |
21 |
Correct |
12 ms |
19020 KB |
Output is correct |
22 |
Correct |
12 ms |
19008 KB |
Output is correct |
23 |
Correct |
12 ms |
19008 KB |
Output is correct |
24 |
Correct |
12 ms |
19020 KB |
Output is correct |
25 |
Correct |
12 ms |
19020 KB |
Output is correct |
26 |
Correct |
12 ms |
19084 KB |
Output is correct |
27 |
Correct |
12 ms |
18996 KB |
Output is correct |
28 |
Correct |
12 ms |
19020 KB |
Output is correct |
29 |
Correct |
12 ms |
19020 KB |
Output is correct |
30 |
Correct |
12 ms |
18976 KB |
Output is correct |
31 |
Correct |
12 ms |
19076 KB |
Output is correct |
32 |
Correct |
12 ms |
19020 KB |
Output is correct |
33 |
Correct |
12 ms |
19020 KB |
Output is correct |
34 |
Correct |
12 ms |
19100 KB |
Output is correct |
35 |
Correct |
13 ms |
19096 KB |
Output is correct |
36 |
Correct |
12 ms |
19020 KB |
Output is correct |
37 |
Correct |
12 ms |
19020 KB |
Output is correct |
38 |
Correct |
12 ms |
18996 KB |
Output is correct |
39 |
Correct |
11 ms |
19020 KB |
Output is correct |
40 |
Correct |
12 ms |
19020 KB |
Output is correct |
41 |
Correct |
12 ms |
19148 KB |
Output is correct |
42 |
Correct |
12 ms |
19148 KB |
Output is correct |
43 |
Correct |
13 ms |
19196 KB |
Output is correct |
44 |
Correct |
12 ms |
19148 KB |
Output is correct |
45 |
Correct |
13 ms |
19104 KB |
Output is correct |
46 |
Correct |
13 ms |
19216 KB |
Output is correct |
47 |
Correct |
13 ms |
19220 KB |
Output is correct |
48 |
Correct |
13 ms |
19148 KB |
Output is correct |
49 |
Correct |
12 ms |
19184 KB |
Output is correct |
50 |
Correct |
12 ms |
19152 KB |
Output is correct |
51 |
Correct |
12 ms |
19148 KB |
Output is correct |
52 |
Correct |
12 ms |
19144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
19020 KB |
Output is correct |
2 |
Correct |
12 ms |
19052 KB |
Output is correct |
3 |
Correct |
12 ms |
19020 KB |
Output is correct |
4 |
Correct |
12 ms |
19048 KB |
Output is correct |
5 |
Correct |
12 ms |
19020 KB |
Output is correct |
6 |
Correct |
12 ms |
19020 KB |
Output is correct |
7 |
Correct |
12 ms |
19020 KB |
Output is correct |
8 |
Correct |
12 ms |
19088 KB |
Output is correct |
9 |
Correct |
12 ms |
19020 KB |
Output is correct |
10 |
Correct |
12 ms |
19020 KB |
Output is correct |
11 |
Correct |
12 ms |
19084 KB |
Output is correct |
12 |
Correct |
12 ms |
19020 KB |
Output is correct |
13 |
Correct |
12 ms |
19020 KB |
Output is correct |
14 |
Correct |
14 ms |
19076 KB |
Output is correct |
15 |
Correct |
13 ms |
19020 KB |
Output is correct |
16 |
Correct |
12 ms |
19020 KB |
Output is correct |
17 |
Correct |
12 ms |
18992 KB |
Output is correct |
18 |
Correct |
12 ms |
19056 KB |
Output is correct |
19 |
Correct |
11 ms |
19020 KB |
Output is correct |
20 |
Correct |
12 ms |
19020 KB |
Output is correct |
21 |
Correct |
12 ms |
19020 KB |
Output is correct |
22 |
Correct |
12 ms |
19008 KB |
Output is correct |
23 |
Correct |
12 ms |
19008 KB |
Output is correct |
24 |
Correct |
12 ms |
19020 KB |
Output is correct |
25 |
Correct |
12 ms |
19020 KB |
Output is correct |
26 |
Correct |
12 ms |
19084 KB |
Output is correct |
27 |
Correct |
12 ms |
18996 KB |
Output is correct |
28 |
Correct |
12 ms |
19020 KB |
Output is correct |
29 |
Correct |
12 ms |
19020 KB |
Output is correct |
30 |
Correct |
12 ms |
18976 KB |
Output is correct |
31 |
Correct |
12 ms |
19076 KB |
Output is correct |
32 |
Correct |
12 ms |
19020 KB |
Output is correct |
33 |
Correct |
12 ms |
19020 KB |
Output is correct |
34 |
Correct |
12 ms |
19100 KB |
Output is correct |
35 |
Correct |
13 ms |
19096 KB |
Output is correct |
36 |
Correct |
12 ms |
19020 KB |
Output is correct |
37 |
Correct |
13 ms |
19004 KB |
Output is correct |
38 |
Correct |
12 ms |
19020 KB |
Output is correct |
39 |
Correct |
12 ms |
19020 KB |
Output is correct |
40 |
Correct |
12 ms |
19096 KB |
Output is correct |
41 |
Correct |
14 ms |
19148 KB |
Output is correct |
42 |
Correct |
12 ms |
19020 KB |
Output is correct |
43 |
Correct |
12 ms |
18988 KB |
Output is correct |
44 |
Correct |
12 ms |
19100 KB |
Output is correct |
45 |
Correct |
12 ms |
18988 KB |
Output is correct |
46 |
Correct |
12 ms |
19052 KB |
Output is correct |
47 |
Correct |
12 ms |
19020 KB |
Output is correct |
48 |
Correct |
12 ms |
18996 KB |
Output is correct |
49 |
Correct |
12 ms |
19020 KB |
Output is correct |
50 |
Correct |
12 ms |
19020 KB |
Output is correct |
51 |
Correct |
12 ms |
19148 KB |
Output is correct |
52 |
Correct |
12 ms |
19148 KB |
Output is correct |
53 |
Correct |
13 ms |
19148 KB |
Output is correct |
54 |
Correct |
24 ms |
20320 KB |
Output is correct |
55 |
Correct |
20 ms |
20300 KB |
Output is correct |
56 |
Correct |
118 ms |
31588 KB |
Output is correct |
57 |
Correct |
110 ms |
31556 KB |
Output is correct |
58 |
Correct |
98 ms |
31528 KB |
Output is correct |
59 |
Correct |
102 ms |
31512 KB |
Output is correct |
60 |
Correct |
96 ms |
32748 KB |
Output is correct |
61 |
Correct |
108 ms |
32656 KB |
Output is correct |
62 |
Correct |
103 ms |
32780 KB |
Output is correct |
63 |
Correct |
102 ms |
32836 KB |
Output is correct |
64 |
Correct |
101 ms |
32816 KB |
Output is correct |
65 |
Correct |
99 ms |
32780 KB |
Output is correct |
66 |
Correct |
103 ms |
32780 KB |
Output is correct |
67 |
Correct |
101 ms |
32684 KB |
Output is correct |
68 |
Correct |
103 ms |
32852 KB |
Output is correct |
69 |
Correct |
12 ms |
19020 KB |
Output is correct |
70 |
Correct |
14 ms |
19020 KB |
Output is correct |
71 |
Correct |
105 ms |
32828 KB |
Output is correct |
72 |
Correct |
105 ms |
32792 KB |
Output is correct |
73 |
Correct |
104 ms |
32792 KB |
Output is correct |
74 |
Correct |
11 ms |
19044 KB |
Output is correct |
75 |
Correct |
13 ms |
18972 KB |
Output is correct |
76 |
Correct |
11 ms |
19020 KB |
Output is correct |
77 |
Correct |
12 ms |
19020 KB |
Output is correct |
78 |
Correct |
107 ms |
31600 KB |
Output is correct |
79 |
Correct |
130 ms |
32788 KB |
Output is correct |
80 |
Correct |
104 ms |
32804 KB |
Output is correct |
81 |
Correct |
92 ms |
32788 KB |
Output is correct |
82 |
Correct |
93 ms |
32792 KB |
Output is correct |
83 |
Correct |
139 ms |
32924 KB |
Output is correct |
84 |
Correct |
12 ms |
19020 KB |
Output is correct |
85 |
Correct |
12 ms |
18996 KB |
Output is correct |
86 |
Correct |
11 ms |
19020 KB |
Output is correct |
87 |
Correct |
12 ms |
19020 KB |
Output is correct |
88 |
Correct |
12 ms |
19148 KB |
Output is correct |
89 |
Correct |
12 ms |
19148 KB |
Output is correct |
90 |
Correct |
13 ms |
19196 KB |
Output is correct |
91 |
Correct |
12 ms |
19148 KB |
Output is correct |
92 |
Correct |
13 ms |
19104 KB |
Output is correct |
93 |
Correct |
13 ms |
19216 KB |
Output is correct |
94 |
Correct |
13 ms |
19220 KB |
Output is correct |
95 |
Correct |
13 ms |
19148 KB |
Output is correct |
96 |
Correct |
12 ms |
19184 KB |
Output is correct |
97 |
Correct |
12 ms |
19152 KB |
Output is correct |
98 |
Correct |
12 ms |
19148 KB |
Output is correct |
99 |
Correct |
12 ms |
19144 KB |
Output is correct |
100 |
Correct |
14 ms |
19104 KB |
Output is correct |
101 |
Correct |
19 ms |
20428 KB |
Output is correct |
102 |
Correct |
21 ms |
20372 KB |
Output is correct |
103 |
Correct |
148 ms |
32816 KB |
Output is correct |
104 |
Correct |
106 ms |
32740 KB |
Output is correct |
105 |
Correct |
150 ms |
32788 KB |
Output is correct |
106 |
Correct |
120 ms |
32764 KB |
Output is correct |
107 |
Correct |
143 ms |
32788 KB |
Output is correct |
108 |
Correct |
125 ms |
32736 KB |
Output is correct |
109 |
Correct |
91 ms |
32868 KB |
Output is correct |
110 |
Correct |
103 ms |
32848 KB |
Output is correct |
111 |
Correct |
102 ms |
32836 KB |
Output is correct |
112 |
Correct |
125 ms |
32796 KB |
Output is correct |
113 |
Correct |
142 ms |
32840 KB |
Output is correct |
114 |
Correct |
113 ms |
32836 KB |
Output is correct |
115 |
Correct |
99 ms |
32780 KB |
Output is correct |