Submission #147306

# Submission time Handle Problem Language Result Execution time Memory
147306 2019-08-28T19:07:59 Z joylintp Arranging Shoes (IOI19_shoes) C++14
50 / 100
219 ms 141816 KB
#include<bits/stdc++.h>
#include "shoes.h"

using namespace std;

bool visit[200001] = {};
long long n, ret = 0, bit[200001] = {}, s[200001], ans[200001];
queue<int> Left[100001], Right[100001];

void bld(void)
{
    for (int i = 2; i <= n + 10; i++)
        bit[i] = i - max(1, i - (i & -i));
}

long long sum(int x)
{
    long long ret = 0;
    for (int i = x; i >= 1; i -= (i & -i))
        ret += bit[i];
    return ret;
}

void edt(int x, int k)
{
    for (int i = x; i <= n; i += (i & -i))
        bit[i] -= k;
}

long long count_swaps(vector<int> in)
{
    n = in.size();
    s[0] = 0;
    for (int i = 1; i <= n; i++)
    {
        s[i] = in[i - 1];
        if (s[i] < 0)
            Left[-s[i]].push(i);
        else
            Right[s[i]].push(i);
    }
    bld();

    int cnt = 0, pos, tar;
    for (int i = 1; i <= n; i++)
    {
        if (visit[i])
            continue;

        tar = -abs(s[i]);
        pos = Left[-tar].front(), Left[-tar].pop();
        ans[cnt++] = tar;
        visit[pos] = true;
        ret += sum(pos);
        edt(pos, 1);

        tar = -ans[cnt - 1];
        pos = Right[tar].front(), Right[tar].pop();
        ans[cnt++] = tar;
        visit[pos] = true;
        ret += sum(pos);
        edt(pos, 1);
    }

	return ret;
}
# Verdict Execution time Memory Grader output
1 Correct 141 ms 135032 KB Output is correct
2 Correct 140 ms 134904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 141 ms 135032 KB Output is correct
2 Correct 140 ms 134904 KB Output is correct
3 Correct 141 ms 135024 KB Output is correct
4 Correct 138 ms 135008 KB Output is correct
5 Correct 167 ms 134904 KB Output is correct
6 Correct 139 ms 134948 KB Output is correct
7 Correct 139 ms 135032 KB Output is correct
8 Correct 139 ms 134904 KB Output is correct
9 Correct 139 ms 134904 KB Output is correct
10 Correct 151 ms 134904 KB Output is correct
11 Correct 136 ms 134908 KB Output is correct
12 Correct 139 ms 134912 KB Output is correct
13 Correct 140 ms 135032 KB Output is correct
14 Correct 138 ms 135060 KB Output is correct
15 Correct 138 ms 135032 KB Output is correct
16 Correct 166 ms 135032 KB Output is correct
17 Correct 138 ms 135032 KB Output is correct
18 Correct 138 ms 135004 KB Output is correct
19 Correct 137 ms 135032 KB Output is correct
20 Correct 139 ms 135032 KB Output is correct
21 Correct 151 ms 135032 KB Output is correct
22 Correct 139 ms 135032 KB Output is correct
23 Correct 140 ms 135160 KB Output is correct
24 Correct 138 ms 135032 KB Output is correct
25 Correct 138 ms 135032 KB Output is correct
26 Correct 139 ms 134940 KB Output is correct
27 Correct 139 ms 135032 KB Output is correct
28 Correct 161 ms 135000 KB Output is correct
29 Correct 138 ms 134940 KB Output is correct
30 Correct 164 ms 135060 KB Output is correct
31 Correct 168 ms 134972 KB Output is correct
32 Correct 166 ms 134904 KB Output is correct
33 Correct 169 ms 134904 KB Output is correct
34 Correct 162 ms 134908 KB Output is correct
35 Correct 139 ms 134904 KB Output is correct
36 Correct 155 ms 135140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 141 ms 135032 KB Output is correct
2 Correct 140 ms 134904 KB Output is correct
3 Correct 154 ms 134956 KB Output is correct
4 Correct 169 ms 134944 KB Output is correct
5 Correct 166 ms 135032 KB Output is correct
6 Correct 167 ms 134964 KB Output is correct
7 Correct 168 ms 135032 KB Output is correct
8 Correct 164 ms 135032 KB Output is correct
9 Correct 148 ms 134904 KB Output is correct
10 Correct 142 ms 135052 KB Output is correct
11 Correct 138 ms 134972 KB Output is correct
12 Correct 137 ms 134904 KB Output is correct
13 Correct 137 ms 135016 KB Output is correct
14 Correct 138 ms 134904 KB Output is correct
15 Correct 138 ms 134960 KB Output is correct
16 Correct 137 ms 135032 KB Output is correct
17 Correct 148 ms 135028 KB Output is correct
18 Correct 147 ms 135056 KB Output is correct
19 Correct 149 ms 135004 KB Output is correct
20 Correct 153 ms 135780 KB Output is correct
21 Correct 155 ms 135772 KB Output is correct
22 Incorrect 219 ms 141816 KB Output isn't correct
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 137 ms 135032 KB Output is correct
2 Correct 154 ms 134908 KB Output is correct
3 Correct 153 ms 134904 KB Output is correct
4 Correct 168 ms 135008 KB Output is correct
5 Incorrect 219 ms 141000 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 141 ms 135032 KB Output is correct
2 Correct 140 ms 134904 KB Output is correct
3 Correct 141 ms 135024 KB Output is correct
4 Correct 138 ms 135008 KB Output is correct
5 Correct 167 ms 134904 KB Output is correct
6 Correct 139 ms 134948 KB Output is correct
7 Correct 139 ms 135032 KB Output is correct
8 Correct 139 ms 134904 KB Output is correct
9 Correct 139 ms 134904 KB Output is correct
10 Correct 151 ms 134904 KB Output is correct
11 Correct 136 ms 134908 KB Output is correct
12 Correct 139 ms 134912 KB Output is correct
13 Correct 140 ms 135032 KB Output is correct
14 Correct 138 ms 135060 KB Output is correct
15 Correct 138 ms 135032 KB Output is correct
16 Correct 166 ms 135032 KB Output is correct
17 Correct 138 ms 135032 KB Output is correct
18 Correct 138 ms 135004 KB Output is correct
19 Correct 137 ms 135032 KB Output is correct
20 Correct 139 ms 135032 KB Output is correct
21 Correct 151 ms 135032 KB Output is correct
22 Correct 139 ms 135032 KB Output is correct
23 Correct 140 ms 135160 KB Output is correct
24 Correct 138 ms 135032 KB Output is correct
25 Correct 138 ms 135032 KB Output is correct
26 Correct 139 ms 134940 KB Output is correct
27 Correct 139 ms 135032 KB Output is correct
28 Correct 161 ms 135000 KB Output is correct
29 Correct 138 ms 134940 KB Output is correct
30 Correct 164 ms 135060 KB Output is correct
31 Correct 168 ms 134972 KB Output is correct
32 Correct 166 ms 134904 KB Output is correct
33 Correct 169 ms 134904 KB Output is correct
34 Correct 162 ms 134908 KB Output is correct
35 Correct 139 ms 134904 KB Output is correct
36 Correct 155 ms 135140 KB Output is correct
37 Correct 138 ms 134996 KB Output is correct
38 Correct 140 ms 134904 KB Output is correct
39 Correct 139 ms 135000 KB Output is correct
40 Correct 140 ms 135032 KB Output is correct
41 Correct 139 ms 135032 KB Output is correct
42 Correct 140 ms 135032 KB Output is correct
43 Correct 139 ms 135056 KB Output is correct
44 Correct 140 ms 135032 KB Output is correct
45 Correct 137 ms 135032 KB Output is correct
46 Correct 138 ms 135004 KB Output is correct
47 Correct 138 ms 135032 KB Output is correct
48 Correct 139 ms 135032 KB Output is correct
49 Correct 140 ms 135288 KB Output is correct
50 Correct 149 ms 135092 KB Output is correct
51 Correct 153 ms 135004 KB Output is correct
52 Correct 140 ms 135032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 141 ms 135032 KB Output is correct
2 Correct 140 ms 134904 KB Output is correct
3 Correct 141 ms 135024 KB Output is correct
4 Correct 138 ms 135008 KB Output is correct
5 Correct 167 ms 134904 KB Output is correct
6 Correct 139 ms 134948 KB Output is correct
7 Correct 139 ms 135032 KB Output is correct
8 Correct 139 ms 134904 KB Output is correct
9 Correct 139 ms 134904 KB Output is correct
10 Correct 151 ms 134904 KB Output is correct
11 Correct 136 ms 134908 KB Output is correct
12 Correct 139 ms 134912 KB Output is correct
13 Correct 140 ms 135032 KB Output is correct
14 Correct 138 ms 135060 KB Output is correct
15 Correct 138 ms 135032 KB Output is correct
16 Correct 166 ms 135032 KB Output is correct
17 Correct 138 ms 135032 KB Output is correct
18 Correct 138 ms 135004 KB Output is correct
19 Correct 137 ms 135032 KB Output is correct
20 Correct 139 ms 135032 KB Output is correct
21 Correct 151 ms 135032 KB Output is correct
22 Correct 139 ms 135032 KB Output is correct
23 Correct 140 ms 135160 KB Output is correct
24 Correct 138 ms 135032 KB Output is correct
25 Correct 138 ms 135032 KB Output is correct
26 Correct 139 ms 134940 KB Output is correct
27 Correct 139 ms 135032 KB Output is correct
28 Correct 161 ms 135000 KB Output is correct
29 Correct 138 ms 134940 KB Output is correct
30 Correct 164 ms 135060 KB Output is correct
31 Correct 168 ms 134972 KB Output is correct
32 Correct 166 ms 134904 KB Output is correct
33 Correct 169 ms 134904 KB Output is correct
34 Correct 162 ms 134908 KB Output is correct
35 Correct 139 ms 134904 KB Output is correct
36 Correct 155 ms 135140 KB Output is correct
37 Correct 154 ms 134956 KB Output is correct
38 Correct 169 ms 134944 KB Output is correct
39 Correct 166 ms 135032 KB Output is correct
40 Correct 167 ms 134964 KB Output is correct
41 Correct 168 ms 135032 KB Output is correct
42 Correct 164 ms 135032 KB Output is correct
43 Correct 148 ms 134904 KB Output is correct
44 Correct 142 ms 135052 KB Output is correct
45 Correct 138 ms 134972 KB Output is correct
46 Correct 137 ms 134904 KB Output is correct
47 Correct 137 ms 135016 KB Output is correct
48 Correct 138 ms 134904 KB Output is correct
49 Correct 138 ms 134960 KB Output is correct
50 Correct 137 ms 135032 KB Output is correct
51 Correct 148 ms 135028 KB Output is correct
52 Correct 147 ms 135056 KB Output is correct
53 Correct 149 ms 135004 KB Output is correct
54 Correct 153 ms 135780 KB Output is correct
55 Correct 155 ms 135772 KB Output is correct
56 Incorrect 219 ms 141816 KB Output isn't correct
57 Halted 0 ms 0 KB -