Submission #316950

# Submission time Handle Problem Language Result Execution time Memory
316950 2020-10-28T16:49:03 Z Jarif_Rahman Arranging Shoes (IOI19_shoes) C++17
100 / 100
213 ms 32428 KB
#include "shoes.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int n, k;
vector<int>v;
vector<ll> seg;
void upd(int in, ll x){
    in+=k/2;
    seg[in] = x, in/=2;
    while(in > 0){
        seg[in] = seg[2*in] + seg[2*in+1];
        in/=2;
    }
}
ll sum(int l, int r){
    l+=k/2, r+=k/2;
    ll s = 0;
    while(l <= r){
        if(l%2 == 1) s+=seg[l], l++;
        if(r%2 == 0) s+=seg[r], r--;
        l/=2, r/=2;
    }
    return s;
}
long long count_swaps(vector<int> S){
    v = S;
    n = v.size()/2;
    k = 1; while(k <= 2*n) k*=2; k*=2;
    seg.resize(k, 0);
    vector<int> a(2*n);
    vector<pair<int, int>> sth(n+1, {0,0});
    for(int i = 0; i < 2*n; i++){
        if(v[i] > 0) sth[v[i]].sc++;
        else sth[-v[i]].f++;
    }
    int z = 0;
    for(int i = 0; i < 2*n; i++){
        int x = abs(v[i]);
        if(v[i] > 0){
            if(sth[x].sc <=  sth[x].f){
                a[2*z] = -x;
                a[2*z+1] = x;
                z++;
            }
            sth[x].sc--;
        }
        else{
            if(sth[x].f <=  sth[x].sc){
                a[2*z] = -x;
                a[2*z+1] = x;
                z++;
            }
            sth[x].f--;
        }
    }
    vector<vector<int>> va(2*n+1), vb(2*n+1);
    vector<int> p(2*n);
    for(int i = 0; i < 2*n; i++) va[a[i]+n].pb(i);
    for(int i = 0; i < 2*n; i++) vb[v[i]+n].pb(i);
    for(int i = 0; i <= 2*n; i++){
        if(va[i].empty()) continue;
        for(int j = 0; j < va[i].size(); j++) p[vb[i][j]] = va[i][j];
    }
    ll ans = 0;
    for(int i = 0; i < 2*n; i++){
        if(p[i]!=2*n-1) ans+=sum(p[i]+1, 2*n-1);
        upd(p[i], 1);
    }
    return ans;
}

Compilation message

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:67:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |         for(int j = 0; j < va[i].size(); j++) p[vb[i][j]] = va[i][j];
      |                        ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
22 Correct 0 ms 256 KB Output is correct
23 Correct 0 ms 256 KB Output is correct
24 Correct 1 ms 256 KB Output is correct
25 Correct 1 ms 256 KB Output is correct
26 Correct 1 ms 256 KB Output is correct
27 Correct 1 ms 256 KB Output is correct
28 Correct 0 ms 256 KB Output is correct
29 Correct 0 ms 256 KB Output is correct
30 Correct 1 ms 256 KB Output is correct
31 Correct 0 ms 256 KB Output is correct
32 Correct 0 ms 256 KB Output is correct
33 Correct 0 ms 256 KB Output is correct
34 Correct 1 ms 320 KB Output is correct
35 Correct 1 ms 256 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 7 ms 2560 KB Output is correct
21 Correct 7 ms 2560 KB Output is correct
22 Correct 74 ms 20716 KB Output is correct
23 Correct 71 ms 20588 KB Output is correct
24 Correct 74 ms 20416 KB Output is correct
25 Correct 71 ms 20464 KB Output is correct
26 Correct 74 ms 20588 KB Output is correct
27 Correct 70 ms 20588 KB Output is correct
28 Correct 73 ms 20460 KB Output is correct
29 Correct 72 ms 20460 KB Output is correct
30 Correct 74 ms 20460 KB Output is correct
31 Correct 75 ms 20736 KB Output is correct
32 Correct 72 ms 20472 KB Output is correct
33 Correct 70 ms 20460 KB Output is correct
34 Correct 72 ms 20460 KB Output is correct
35 Correct 0 ms 256 KB Output is correct
36 Correct 0 ms 256 KB Output is correct
37 Correct 73 ms 20460 KB Output is correct
38 Correct 72 ms 20460 KB Output is correct
39 Correct 72 ms 20460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 173 ms 31096 KB Output is correct
6 Correct 102 ms 21496 KB Output is correct
7 Correct 179 ms 31096 KB Output is correct
8 Correct 72 ms 20464 KB Output is correct
9 Correct 170 ms 31108 KB Output is correct
10 Correct 139 ms 24952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
22 Correct 0 ms 256 KB Output is correct
23 Correct 0 ms 256 KB Output is correct
24 Correct 1 ms 256 KB Output is correct
25 Correct 1 ms 256 KB Output is correct
26 Correct 1 ms 256 KB Output is correct
27 Correct 1 ms 256 KB Output is correct
28 Correct 0 ms 256 KB Output is correct
29 Correct 0 ms 256 KB Output is correct
30 Correct 1 ms 256 KB Output is correct
31 Correct 0 ms 256 KB Output is correct
32 Correct 0 ms 256 KB Output is correct
33 Correct 0 ms 256 KB Output is correct
34 Correct 1 ms 320 KB Output is correct
35 Correct 1 ms 256 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 256 KB Output is correct
38 Correct 1 ms 256 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 2 ms 640 KB Output is correct
42 Correct 2 ms 640 KB Output is correct
43 Correct 1 ms 640 KB Output is correct
44 Correct 1 ms 640 KB Output is correct
45 Correct 1 ms 512 KB Output is correct
46 Correct 2 ms 512 KB Output is correct
47 Correct 1 ms 512 KB Output is correct
48 Correct 2 ms 512 KB Output is correct
49 Correct 1 ms 512 KB Output is correct
50 Correct 1 ms 512 KB Output is correct
51 Correct 1 ms 512 KB Output is correct
52 Correct 1 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
22 Correct 0 ms 256 KB Output is correct
23 Correct 0 ms 256 KB Output is correct
24 Correct 1 ms 256 KB Output is correct
25 Correct 1 ms 256 KB Output is correct
26 Correct 1 ms 256 KB Output is correct
27 Correct 1 ms 256 KB Output is correct
28 Correct 0 ms 256 KB Output is correct
29 Correct 0 ms 256 KB Output is correct
30 Correct 1 ms 256 KB Output is correct
31 Correct 0 ms 256 KB Output is correct
32 Correct 0 ms 256 KB Output is correct
33 Correct 0 ms 256 KB Output is correct
34 Correct 1 ms 320 KB Output is correct
35 Correct 1 ms 256 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 0 ms 256 KB Output is correct
38 Correct 0 ms 256 KB Output is correct
39 Correct 0 ms 256 KB Output is correct
40 Correct 1 ms 256 KB Output is correct
41 Correct 0 ms 256 KB Output is correct
42 Correct 0 ms 256 KB Output is correct
43 Correct 0 ms 256 KB Output is correct
44 Correct 0 ms 256 KB Output is correct
45 Correct 0 ms 256 KB Output is correct
46 Correct 0 ms 256 KB Output is correct
47 Correct 0 ms 256 KB Output is correct
48 Correct 1 ms 256 KB Output is correct
49 Correct 1 ms 256 KB Output is correct
50 Correct 0 ms 384 KB Output is correct
51 Correct 1 ms 384 KB Output is correct
52 Correct 1 ms 512 KB Output is correct
53 Correct 1 ms 512 KB Output is correct
54 Correct 7 ms 2560 KB Output is correct
55 Correct 7 ms 2560 KB Output is correct
56 Correct 74 ms 20716 KB Output is correct
57 Correct 71 ms 20588 KB Output is correct
58 Correct 74 ms 20416 KB Output is correct
59 Correct 71 ms 20464 KB Output is correct
60 Correct 74 ms 20588 KB Output is correct
61 Correct 70 ms 20588 KB Output is correct
62 Correct 73 ms 20460 KB Output is correct
63 Correct 72 ms 20460 KB Output is correct
64 Correct 74 ms 20460 KB Output is correct
65 Correct 75 ms 20736 KB Output is correct
66 Correct 72 ms 20472 KB Output is correct
67 Correct 70 ms 20460 KB Output is correct
68 Correct 72 ms 20460 KB Output is correct
69 Correct 0 ms 256 KB Output is correct
70 Correct 0 ms 256 KB Output is correct
71 Correct 73 ms 20460 KB Output is correct
72 Correct 72 ms 20460 KB Output is correct
73 Correct 72 ms 20460 KB Output is correct
74 Correct 1 ms 256 KB Output is correct
75 Correct 0 ms 256 KB Output is correct
76 Correct 0 ms 256 KB Output is correct
77 Correct 1 ms 256 KB Output is correct
78 Correct 173 ms 31096 KB Output is correct
79 Correct 102 ms 21496 KB Output is correct
80 Correct 179 ms 31096 KB Output is correct
81 Correct 72 ms 20464 KB Output is correct
82 Correct 170 ms 31108 KB Output is correct
83 Correct 139 ms 24952 KB Output is correct
84 Correct 1 ms 256 KB Output is correct
85 Correct 1 ms 256 KB Output is correct
86 Correct 1 ms 384 KB Output is correct
87 Correct 1 ms 384 KB Output is correct
88 Correct 2 ms 640 KB Output is correct
89 Correct 2 ms 640 KB Output is correct
90 Correct 1 ms 640 KB Output is correct
91 Correct 1 ms 640 KB Output is correct
92 Correct 1 ms 512 KB Output is correct
93 Correct 2 ms 512 KB Output is correct
94 Correct 1 ms 512 KB Output is correct
95 Correct 2 ms 512 KB Output is correct
96 Correct 1 ms 512 KB Output is correct
97 Correct 1 ms 512 KB Output is correct
98 Correct 1 ms 512 KB Output is correct
99 Correct 1 ms 640 KB Output is correct
100 Correct 1 ms 640 KB Output is correct
101 Correct 12 ms 3456 KB Output is correct
102 Correct 10 ms 2688 KB Output is correct
103 Correct 213 ms 32248 KB Output is correct
104 Correct 193 ms 32248 KB Output is correct
105 Correct 168 ms 26880 KB Output is correct
106 Correct 178 ms 32428 KB Output is correct
107 Correct 110 ms 22904 KB Output is correct
108 Correct 126 ms 23576 KB Output is correct
109 Correct 74 ms 22060 KB Output is correct
110 Correct 72 ms 21744 KB Output is correct
111 Correct 165 ms 30968 KB Output is correct
112 Correct 177 ms 29548 KB Output is correct
113 Correct 114 ms 22904 KB Output is correct
114 Correct 170 ms 32248 KB Output is correct
115 Correct 171 ms 32248 KB Output is correct