#include <iostream>
#include <cstdio>
#include <queue>
#include <vector>
using namespace std;
long long noneg,k,b[1000005],curindex,cursum,n,a[1000005];
queue<long long>q[500005];
vector<long long>s;
void update(int ind,int value) {
for(int i=ind; i<=n; i+=i&(-i))
b[i]+=value;
}
int curs(int ind1) {
cursum=0;
for(int i=ind1; i>=1; i-=i&(-i))
cursum+=b[i];
return cursum;
}
long long count_swaps(std:: vector<int>s) { // *** !
int k;
long long ans=0; //***
noneg=100005; n=s.size();
for(k=0; k<s.size(); k++) a[k+1]=s[k];
for(k=1;k<=n;k++) update(k,1);
for(k=1; k<=n; k++)
if(q[a[k]+noneg].size()>0) {
curindex=q[a[k]+noneg].front();
q[a[k]+noneg].pop();
ans+=curs(k)-curs(curindex)-1;
if(a[k]<0) ans++;
update(k,-1);
update(curindex,1);
} else q[a[k]*(-1)+noneg].push(k);
return ans;
}
Compilation message
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:30:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(k=0; k<s.size(); k++) a[k+1]=s[k];
~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
346 ms |
336860 KB |
Output is correct |
2 |
Correct |
340 ms |
337068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
346 ms |
336860 KB |
Output is correct |
2 |
Correct |
340 ms |
337068 KB |
Output is correct |
3 |
Correct |
344 ms |
336936 KB |
Output is correct |
4 |
Correct |
343 ms |
336880 KB |
Output is correct |
5 |
Correct |
340 ms |
336952 KB |
Output is correct |
6 |
Correct |
342 ms |
336932 KB |
Output is correct |
7 |
Correct |
345 ms |
336992 KB |
Output is correct |
8 |
Correct |
349 ms |
336904 KB |
Output is correct |
9 |
Correct |
344 ms |
336888 KB |
Output is correct |
10 |
Correct |
401 ms |
336996 KB |
Output is correct |
11 |
Correct |
344 ms |
336940 KB |
Output is correct |
12 |
Correct |
342 ms |
337144 KB |
Output is correct |
13 |
Correct |
342 ms |
336860 KB |
Output is correct |
14 |
Correct |
346 ms |
336984 KB |
Output is correct |
15 |
Correct |
345 ms |
336932 KB |
Output is correct |
16 |
Correct |
346 ms |
336888 KB |
Output is correct |
17 |
Correct |
345 ms |
336904 KB |
Output is correct |
18 |
Correct |
343 ms |
336952 KB |
Output is correct |
19 |
Correct |
348 ms |
336980 KB |
Output is correct |
20 |
Correct |
343 ms |
337016 KB |
Output is correct |
21 |
Correct |
347 ms |
336984 KB |
Output is correct |
22 |
Correct |
343 ms |
336860 KB |
Output is correct |
23 |
Correct |
344 ms |
337016 KB |
Output is correct |
24 |
Correct |
344 ms |
336960 KB |
Output is correct |
25 |
Correct |
344 ms |
337088 KB |
Output is correct |
26 |
Correct |
344 ms |
336964 KB |
Output is correct |
27 |
Correct |
362 ms |
336888 KB |
Output is correct |
28 |
Correct |
345 ms |
336944 KB |
Output is correct |
29 |
Correct |
344 ms |
336912 KB |
Output is correct |
30 |
Correct |
350 ms |
336940 KB |
Output is correct |
31 |
Correct |
342 ms |
337016 KB |
Output is correct |
32 |
Correct |
342 ms |
337020 KB |
Output is correct |
33 |
Correct |
343 ms |
337144 KB |
Output is correct |
34 |
Correct |
343 ms |
336952 KB |
Output is correct |
35 |
Correct |
344 ms |
336968 KB |
Output is correct |
36 |
Correct |
341 ms |
336852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
346 ms |
336860 KB |
Output is correct |
2 |
Correct |
340 ms |
337068 KB |
Output is correct |
3 |
Correct |
345 ms |
336944 KB |
Output is correct |
4 |
Correct |
345 ms |
337004 KB |
Output is correct |
5 |
Correct |
349 ms |
336852 KB |
Output is correct |
6 |
Correct |
343 ms |
337112 KB |
Output is correct |
7 |
Correct |
346 ms |
336920 KB |
Output is correct |
8 |
Correct |
342 ms |
336912 KB |
Output is correct |
9 |
Correct |
342 ms |
336888 KB |
Output is correct |
10 |
Correct |
343 ms |
336888 KB |
Output is correct |
11 |
Correct |
342 ms |
337016 KB |
Output is correct |
12 |
Correct |
361 ms |
336864 KB |
Output is correct |
13 |
Correct |
343 ms |
336996 KB |
Output is correct |
14 |
Correct |
350 ms |
336940 KB |
Output is correct |
15 |
Correct |
344 ms |
337040 KB |
Output is correct |
16 |
Correct |
351 ms |
336952 KB |
Output is correct |
17 |
Correct |
346 ms |
336912 KB |
Output is correct |
18 |
Correct |
344 ms |
336944 KB |
Output is correct |
19 |
Correct |
343 ms |
336944 KB |
Output is correct |
20 |
Correct |
375 ms |
337648 KB |
Output is correct |
21 |
Correct |
375 ms |
337528 KB |
Output is correct |
22 |
Correct |
383 ms |
342928 KB |
Output is correct |
23 |
Correct |
381 ms |
342900 KB |
Output is correct |
24 |
Correct |
383 ms |
342856 KB |
Output is correct |
25 |
Correct |
409 ms |
343524 KB |
Output is correct |
26 |
Correct |
384 ms |
342884 KB |
Output is correct |
27 |
Correct |
383 ms |
342816 KB |
Output is correct |
28 |
Correct |
414 ms |
343676 KB |
Output is correct |
29 |
Correct |
421 ms |
343764 KB |
Output is correct |
30 |
Correct |
434 ms |
343828 KB |
Output is correct |
31 |
Correct |
388 ms |
343036 KB |
Output is correct |
32 |
Correct |
411 ms |
343736 KB |
Output is correct |
33 |
Correct |
411 ms |
343644 KB |
Output is correct |
34 |
Correct |
413 ms |
343828 KB |
Output is correct |
35 |
Correct |
345 ms |
336948 KB |
Output is correct |
36 |
Correct |
346 ms |
337056 KB |
Output is correct |
37 |
Correct |
421 ms |
343840 KB |
Output is correct |
38 |
Correct |
464 ms |
343776 KB |
Output is correct |
39 |
Correct |
434 ms |
343768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
371 ms |
336972 KB |
Output is correct |
2 |
Correct |
349 ms |
336908 KB |
Output is correct |
3 |
Correct |
345 ms |
336956 KB |
Output is correct |
4 |
Correct |
352 ms |
336872 KB |
Output is correct |
5 |
Correct |
428 ms |
342904 KB |
Output is correct |
6 |
Correct |
405 ms |
343004 KB |
Output is correct |
7 |
Correct |
432 ms |
342920 KB |
Output is correct |
8 |
Correct |
410 ms |
343948 KB |
Output is correct |
9 |
Correct |
431 ms |
342956 KB |
Output is correct |
10 |
Correct |
420 ms |
343040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
346 ms |
336860 KB |
Output is correct |
2 |
Correct |
340 ms |
337068 KB |
Output is correct |
3 |
Correct |
344 ms |
336936 KB |
Output is correct |
4 |
Correct |
343 ms |
336880 KB |
Output is correct |
5 |
Correct |
340 ms |
336952 KB |
Output is correct |
6 |
Correct |
342 ms |
336932 KB |
Output is correct |
7 |
Correct |
345 ms |
336992 KB |
Output is correct |
8 |
Correct |
349 ms |
336904 KB |
Output is correct |
9 |
Correct |
344 ms |
336888 KB |
Output is correct |
10 |
Correct |
401 ms |
336996 KB |
Output is correct |
11 |
Correct |
344 ms |
336940 KB |
Output is correct |
12 |
Correct |
342 ms |
337144 KB |
Output is correct |
13 |
Correct |
342 ms |
336860 KB |
Output is correct |
14 |
Correct |
346 ms |
336984 KB |
Output is correct |
15 |
Correct |
345 ms |
336932 KB |
Output is correct |
16 |
Correct |
346 ms |
336888 KB |
Output is correct |
17 |
Correct |
345 ms |
336904 KB |
Output is correct |
18 |
Correct |
343 ms |
336952 KB |
Output is correct |
19 |
Correct |
348 ms |
336980 KB |
Output is correct |
20 |
Correct |
343 ms |
337016 KB |
Output is correct |
21 |
Correct |
347 ms |
336984 KB |
Output is correct |
22 |
Correct |
343 ms |
336860 KB |
Output is correct |
23 |
Correct |
344 ms |
337016 KB |
Output is correct |
24 |
Correct |
344 ms |
336960 KB |
Output is correct |
25 |
Correct |
344 ms |
337088 KB |
Output is correct |
26 |
Correct |
344 ms |
336964 KB |
Output is correct |
27 |
Correct |
362 ms |
336888 KB |
Output is correct |
28 |
Correct |
345 ms |
336944 KB |
Output is correct |
29 |
Correct |
344 ms |
336912 KB |
Output is correct |
30 |
Correct |
350 ms |
336940 KB |
Output is correct |
31 |
Correct |
342 ms |
337016 KB |
Output is correct |
32 |
Correct |
342 ms |
337020 KB |
Output is correct |
33 |
Correct |
343 ms |
337144 KB |
Output is correct |
34 |
Correct |
343 ms |
336952 KB |
Output is correct |
35 |
Correct |
344 ms |
336968 KB |
Output is correct |
36 |
Correct |
341 ms |
336852 KB |
Output is correct |
37 |
Correct |
345 ms |
336928 KB |
Output is correct |
38 |
Correct |
343 ms |
336908 KB |
Output is correct |
39 |
Correct |
343 ms |
337016 KB |
Output is correct |
40 |
Correct |
365 ms |
336888 KB |
Output is correct |
41 |
Correct |
344 ms |
337016 KB |
Output is correct |
42 |
Correct |
342 ms |
337008 KB |
Output is correct |
43 |
Correct |
347 ms |
336968 KB |
Output is correct |
44 |
Correct |
346 ms |
336928 KB |
Output is correct |
45 |
Correct |
350 ms |
337128 KB |
Output is correct |
46 |
Correct |
348 ms |
337008 KB |
Output is correct |
47 |
Correct |
380 ms |
336968 KB |
Output is correct |
48 |
Correct |
347 ms |
337016 KB |
Output is correct |
49 |
Correct |
346 ms |
337016 KB |
Output is correct |
50 |
Correct |
348 ms |
337032 KB |
Output is correct |
51 |
Correct |
347 ms |
336940 KB |
Output is correct |
52 |
Correct |
406 ms |
337084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
346 ms |
336860 KB |
Output is correct |
2 |
Correct |
340 ms |
337068 KB |
Output is correct |
3 |
Correct |
344 ms |
336936 KB |
Output is correct |
4 |
Correct |
343 ms |
336880 KB |
Output is correct |
5 |
Correct |
340 ms |
336952 KB |
Output is correct |
6 |
Correct |
342 ms |
336932 KB |
Output is correct |
7 |
Correct |
345 ms |
336992 KB |
Output is correct |
8 |
Correct |
349 ms |
336904 KB |
Output is correct |
9 |
Correct |
344 ms |
336888 KB |
Output is correct |
10 |
Correct |
401 ms |
336996 KB |
Output is correct |
11 |
Correct |
344 ms |
336940 KB |
Output is correct |
12 |
Correct |
342 ms |
337144 KB |
Output is correct |
13 |
Correct |
342 ms |
336860 KB |
Output is correct |
14 |
Correct |
346 ms |
336984 KB |
Output is correct |
15 |
Correct |
345 ms |
336932 KB |
Output is correct |
16 |
Correct |
346 ms |
336888 KB |
Output is correct |
17 |
Correct |
345 ms |
336904 KB |
Output is correct |
18 |
Correct |
343 ms |
336952 KB |
Output is correct |
19 |
Correct |
348 ms |
336980 KB |
Output is correct |
20 |
Correct |
343 ms |
337016 KB |
Output is correct |
21 |
Correct |
347 ms |
336984 KB |
Output is correct |
22 |
Correct |
343 ms |
336860 KB |
Output is correct |
23 |
Correct |
344 ms |
337016 KB |
Output is correct |
24 |
Correct |
344 ms |
336960 KB |
Output is correct |
25 |
Correct |
344 ms |
337088 KB |
Output is correct |
26 |
Correct |
344 ms |
336964 KB |
Output is correct |
27 |
Correct |
362 ms |
336888 KB |
Output is correct |
28 |
Correct |
345 ms |
336944 KB |
Output is correct |
29 |
Correct |
344 ms |
336912 KB |
Output is correct |
30 |
Correct |
350 ms |
336940 KB |
Output is correct |
31 |
Correct |
342 ms |
337016 KB |
Output is correct |
32 |
Correct |
342 ms |
337020 KB |
Output is correct |
33 |
Correct |
343 ms |
337144 KB |
Output is correct |
34 |
Correct |
343 ms |
336952 KB |
Output is correct |
35 |
Correct |
344 ms |
336968 KB |
Output is correct |
36 |
Correct |
341 ms |
336852 KB |
Output is correct |
37 |
Correct |
345 ms |
336944 KB |
Output is correct |
38 |
Correct |
345 ms |
337004 KB |
Output is correct |
39 |
Correct |
349 ms |
336852 KB |
Output is correct |
40 |
Correct |
343 ms |
337112 KB |
Output is correct |
41 |
Correct |
346 ms |
336920 KB |
Output is correct |
42 |
Correct |
342 ms |
336912 KB |
Output is correct |
43 |
Correct |
342 ms |
336888 KB |
Output is correct |
44 |
Correct |
343 ms |
336888 KB |
Output is correct |
45 |
Correct |
342 ms |
337016 KB |
Output is correct |
46 |
Correct |
361 ms |
336864 KB |
Output is correct |
47 |
Correct |
343 ms |
336996 KB |
Output is correct |
48 |
Correct |
350 ms |
336940 KB |
Output is correct |
49 |
Correct |
344 ms |
337040 KB |
Output is correct |
50 |
Correct |
351 ms |
336952 KB |
Output is correct |
51 |
Correct |
346 ms |
336912 KB |
Output is correct |
52 |
Correct |
344 ms |
336944 KB |
Output is correct |
53 |
Correct |
343 ms |
336944 KB |
Output is correct |
54 |
Correct |
375 ms |
337648 KB |
Output is correct |
55 |
Correct |
375 ms |
337528 KB |
Output is correct |
56 |
Correct |
383 ms |
342928 KB |
Output is correct |
57 |
Correct |
381 ms |
342900 KB |
Output is correct |
58 |
Correct |
383 ms |
342856 KB |
Output is correct |
59 |
Correct |
409 ms |
343524 KB |
Output is correct |
60 |
Correct |
384 ms |
342884 KB |
Output is correct |
61 |
Correct |
383 ms |
342816 KB |
Output is correct |
62 |
Correct |
414 ms |
343676 KB |
Output is correct |
63 |
Correct |
421 ms |
343764 KB |
Output is correct |
64 |
Correct |
434 ms |
343828 KB |
Output is correct |
65 |
Correct |
388 ms |
343036 KB |
Output is correct |
66 |
Correct |
411 ms |
343736 KB |
Output is correct |
67 |
Correct |
411 ms |
343644 KB |
Output is correct |
68 |
Correct |
413 ms |
343828 KB |
Output is correct |
69 |
Correct |
345 ms |
336948 KB |
Output is correct |
70 |
Correct |
346 ms |
337056 KB |
Output is correct |
71 |
Correct |
421 ms |
343840 KB |
Output is correct |
72 |
Correct |
464 ms |
343776 KB |
Output is correct |
73 |
Correct |
434 ms |
343768 KB |
Output is correct |
74 |
Correct |
371 ms |
336972 KB |
Output is correct |
75 |
Correct |
349 ms |
336908 KB |
Output is correct |
76 |
Correct |
345 ms |
336956 KB |
Output is correct |
77 |
Correct |
352 ms |
336872 KB |
Output is correct |
78 |
Correct |
428 ms |
342904 KB |
Output is correct |
79 |
Correct |
405 ms |
343004 KB |
Output is correct |
80 |
Correct |
432 ms |
342920 KB |
Output is correct |
81 |
Correct |
410 ms |
343948 KB |
Output is correct |
82 |
Correct |
431 ms |
342956 KB |
Output is correct |
83 |
Correct |
420 ms |
343040 KB |
Output is correct |
84 |
Correct |
345 ms |
336928 KB |
Output is correct |
85 |
Correct |
343 ms |
336908 KB |
Output is correct |
86 |
Correct |
343 ms |
337016 KB |
Output is correct |
87 |
Correct |
365 ms |
336888 KB |
Output is correct |
88 |
Correct |
344 ms |
337016 KB |
Output is correct |
89 |
Correct |
342 ms |
337008 KB |
Output is correct |
90 |
Correct |
347 ms |
336968 KB |
Output is correct |
91 |
Correct |
346 ms |
336928 KB |
Output is correct |
92 |
Correct |
350 ms |
337128 KB |
Output is correct |
93 |
Correct |
348 ms |
337008 KB |
Output is correct |
94 |
Correct |
380 ms |
336968 KB |
Output is correct |
95 |
Correct |
347 ms |
337016 KB |
Output is correct |
96 |
Correct |
346 ms |
337016 KB |
Output is correct |
97 |
Correct |
348 ms |
337032 KB |
Output is correct |
98 |
Correct |
347 ms |
336940 KB |
Output is correct |
99 |
Correct |
406 ms |
337084 KB |
Output is correct |
100 |
Correct |
347 ms |
336992 KB |
Output is correct |
101 |
Correct |
349 ms |
337556 KB |
Output is correct |
102 |
Correct |
356 ms |
337528 KB |
Output is correct |
103 |
Correct |
451 ms |
342832 KB |
Output is correct |
104 |
Correct |
405 ms |
342988 KB |
Output is correct |
105 |
Correct |
413 ms |
342888 KB |
Output is correct |
106 |
Correct |
425 ms |
342868 KB |
Output is correct |
107 |
Correct |
412 ms |
343024 KB |
Output is correct |
108 |
Correct |
398 ms |
342896 KB |
Output is correct |
109 |
Correct |
414 ms |
343700 KB |
Output is correct |
110 |
Correct |
415 ms |
343796 KB |
Output is correct |
111 |
Correct |
428 ms |
342820 KB |
Output is correct |
112 |
Correct |
430 ms |
343032 KB |
Output is correct |
113 |
Correct |
406 ms |
343084 KB |
Output is correct |
114 |
Correct |
421 ms |
342964 KB |
Output is correct |
115 |
Correct |
425 ms |
343024 KB |
Output is correct |