답안 #482144

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
482144 2021-10-23T11:38:41 Z MasterTaster Arranging Shoes (IOI19_shoes) C++14
100 / 100
95 ms 20312 KB
#include "shoes.h"
#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define MAXN 200010

using namespace std;

int bit[MAXN+10], gde[MAXN];
vector<int> leva[MAXN], desna[MAXN];

void upd(int x)
{
    while (x<MAXN)
    {
        bit[x]++;
        x+=x&(-x);
    }
}

int sum(int x)
{
    ll ret=0;
    while (x)
    {
        ret+=bit[x];
        x-=x&(-x);
    }
    return ret;
}


ll ress;
long long count_swaps(std::vector<int> s) {
    ress=0;
    int n=s.size()/2;

    for (int i=0; i<2*n; i++)
    {
        if (s[i]>0) desna[s[i]].pb(i);
        else leva[-s[i]].pb(i);
    }

    for (int i=0; i<2*n; i++) gde[i]=-1;


    for (int i=1; i<=n; i++)
    {
        for (int j=0; j<desna[i].size(); j++)
        {
            //cout<<leva[i][j]<<" "<<desna[i][j]<<endl;
            if (leva[i][j]<desna[i][j]) gde[leva[i][j]]=desna[i][j];
            else gde[desna[i][j]]=leva[i][j];
        }
    }

    for (int i=0; i<2*n; i++)
    {
        if (gde[i]!=-1)
        {
            //cout<<sum(gde[i]-1)<<" "<<sum(i-1)<<endl;
            if (i!=0)
            {
                if (s[i]<0) ress+=(gde[i]-(sum(gde[i]-1)-sum(i-1))-i-1);
                else ress+=(gde[i]-(sum(gde[i]-1)-sum(i-1))-i);
                upd(gde[i]);
            }
            else
            {
                if (s[i]<0) ress+=(gde[i]-(sum(gde[i]-1))-i-1);
                else ress+=(gde[i]-(sum(gde[i]-1))-i);
                upd(gde[i]);
            }
        }
    }
    return ress;
}

Compilation message

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:50:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         for (int j=0; j<desna[i].size(); j++)
      |                       ~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 9676 KB Output is correct
2 Correct 9 ms 9676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 9676 KB Output is correct
2 Correct 9 ms 9676 KB Output is correct
3 Correct 9 ms 9700 KB Output is correct
4 Correct 10 ms 9676 KB Output is correct
5 Correct 10 ms 9700 KB Output is correct
6 Correct 11 ms 9700 KB Output is correct
7 Correct 10 ms 9688 KB Output is correct
8 Correct 10 ms 9676 KB Output is correct
9 Correct 9 ms 9676 KB Output is correct
10 Correct 9 ms 9676 KB Output is correct
11 Correct 9 ms 9648 KB Output is correct
12 Correct 8 ms 9676 KB Output is correct
13 Correct 9 ms 9736 KB Output is correct
14 Correct 8 ms 9676 KB Output is correct
15 Correct 9 ms 9700 KB Output is correct
16 Correct 9 ms 9676 KB Output is correct
17 Correct 8 ms 9676 KB Output is correct
18 Correct 11 ms 9644 KB Output is correct
19 Correct 9 ms 9620 KB Output is correct
20 Correct 8 ms 9676 KB Output is correct
21 Correct 9 ms 9696 KB Output is correct
22 Correct 8 ms 9676 KB Output is correct
23 Correct 8 ms 9704 KB Output is correct
24 Correct 8 ms 9676 KB Output is correct
25 Correct 8 ms 9676 KB Output is correct
26 Correct 7 ms 9696 KB Output is correct
27 Correct 8 ms 9676 KB Output is correct
28 Correct 8 ms 9676 KB Output is correct
29 Correct 9 ms 9676 KB Output is correct
30 Correct 8 ms 9676 KB Output is correct
31 Correct 9 ms 9700 KB Output is correct
32 Correct 9 ms 9700 KB Output is correct
33 Correct 8 ms 9676 KB Output is correct
34 Correct 8 ms 9676 KB Output is correct
35 Correct 8 ms 9676 KB Output is correct
36 Correct 8 ms 9676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 9676 KB Output is correct
2 Correct 9 ms 9676 KB Output is correct
3 Correct 8 ms 9704 KB Output is correct
4 Correct 9 ms 9680 KB Output is correct
5 Correct 8 ms 9700 KB Output is correct
6 Correct 9 ms 9664 KB Output is correct
7 Correct 8 ms 9676 KB Output is correct
8 Correct 8 ms 9700 KB Output is correct
9 Correct 8 ms 9676 KB Output is correct
10 Correct 10 ms 9700 KB Output is correct
11 Correct 8 ms 9676 KB Output is correct
12 Correct 8 ms 9636 KB Output is correct
13 Correct 8 ms 9812 KB Output is correct
14 Correct 9 ms 9676 KB Output is correct
15 Correct 8 ms 9676 KB Output is correct
16 Correct 8 ms 9676 KB Output is correct
17 Correct 9 ms 9692 KB Output is correct
18 Correct 8 ms 9704 KB Output is correct
19 Correct 7 ms 9676 KB Output is correct
20 Correct 11 ms 10316 KB Output is correct
21 Correct 11 ms 10268 KB Output is correct
22 Correct 37 ms 14948 KB Output is correct
23 Correct 36 ms 15032 KB Output is correct
24 Correct 51 ms 15172 KB Output is correct
25 Correct 40 ms 14360 KB Output is correct
26 Correct 41 ms 15072 KB Output is correct
27 Correct 34 ms 14776 KB Output is correct
28 Correct 33 ms 14564 KB Output is correct
29 Correct 34 ms 14548 KB Output is correct
30 Correct 36 ms 14552 KB Output is correct
31 Correct 54 ms 14952 KB Output is correct
32 Correct 39 ms 14524 KB Output is correct
33 Correct 33 ms 14440 KB Output is correct
34 Correct 33 ms 14556 KB Output is correct
35 Correct 8 ms 9676 KB Output is correct
36 Correct 8 ms 9700 KB Output is correct
37 Correct 35 ms 14568 KB Output is correct
38 Correct 36 ms 14556 KB Output is correct
39 Correct 32 ms 14572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 9692 KB Output is correct
2 Correct 8 ms 9688 KB Output is correct
3 Correct 8 ms 9676 KB Output is correct
4 Correct 9 ms 9804 KB Output is correct
5 Correct 55 ms 19932 KB Output is correct
6 Correct 59 ms 15128 KB Output is correct
7 Correct 64 ms 19812 KB Output is correct
8 Correct 34 ms 14572 KB Output is correct
9 Correct 65 ms 19916 KB Output is correct
10 Correct 50 ms 16748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 9676 KB Output is correct
2 Correct 9 ms 9676 KB Output is correct
3 Correct 9 ms 9700 KB Output is correct
4 Correct 10 ms 9676 KB Output is correct
5 Correct 10 ms 9700 KB Output is correct
6 Correct 11 ms 9700 KB Output is correct
7 Correct 10 ms 9688 KB Output is correct
8 Correct 10 ms 9676 KB Output is correct
9 Correct 9 ms 9676 KB Output is correct
10 Correct 9 ms 9676 KB Output is correct
11 Correct 9 ms 9648 KB Output is correct
12 Correct 8 ms 9676 KB Output is correct
13 Correct 9 ms 9736 KB Output is correct
14 Correct 8 ms 9676 KB Output is correct
15 Correct 9 ms 9700 KB Output is correct
16 Correct 9 ms 9676 KB Output is correct
17 Correct 8 ms 9676 KB Output is correct
18 Correct 11 ms 9644 KB Output is correct
19 Correct 9 ms 9620 KB Output is correct
20 Correct 8 ms 9676 KB Output is correct
21 Correct 9 ms 9696 KB Output is correct
22 Correct 8 ms 9676 KB Output is correct
23 Correct 8 ms 9704 KB Output is correct
24 Correct 8 ms 9676 KB Output is correct
25 Correct 8 ms 9676 KB Output is correct
26 Correct 7 ms 9696 KB Output is correct
27 Correct 8 ms 9676 KB Output is correct
28 Correct 8 ms 9676 KB Output is correct
29 Correct 9 ms 9676 KB Output is correct
30 Correct 8 ms 9676 KB Output is correct
31 Correct 9 ms 9700 KB Output is correct
32 Correct 9 ms 9700 KB Output is correct
33 Correct 8 ms 9676 KB Output is correct
34 Correct 8 ms 9676 KB Output is correct
35 Correct 8 ms 9676 KB Output is correct
36 Correct 8 ms 9676 KB Output is correct
37 Correct 8 ms 9676 KB Output is correct
38 Correct 10 ms 9732 KB Output is correct
39 Correct 9 ms 9676 KB Output is correct
40 Correct 9 ms 9700 KB Output is correct
41 Correct 8 ms 9804 KB Output is correct
42 Correct 9 ms 9828 KB Output is correct
43 Correct 8 ms 9804 KB Output is correct
44 Correct 9 ms 9804 KB Output is correct
45 Correct 9 ms 9804 KB Output is correct
46 Correct 9 ms 9728 KB Output is correct
47 Correct 9 ms 9676 KB Output is correct
48 Correct 8 ms 9676 KB Output is correct
49 Correct 8 ms 9676 KB Output is correct
50 Correct 10 ms 9704 KB Output is correct
51 Correct 9 ms 9676 KB Output is correct
52 Correct 9 ms 9804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 9676 KB Output is correct
2 Correct 9 ms 9676 KB Output is correct
3 Correct 9 ms 9700 KB Output is correct
4 Correct 10 ms 9676 KB Output is correct
5 Correct 10 ms 9700 KB Output is correct
6 Correct 11 ms 9700 KB Output is correct
7 Correct 10 ms 9688 KB Output is correct
8 Correct 10 ms 9676 KB Output is correct
9 Correct 9 ms 9676 KB Output is correct
10 Correct 9 ms 9676 KB Output is correct
11 Correct 9 ms 9648 KB Output is correct
12 Correct 8 ms 9676 KB Output is correct
13 Correct 9 ms 9736 KB Output is correct
14 Correct 8 ms 9676 KB Output is correct
15 Correct 9 ms 9700 KB Output is correct
16 Correct 9 ms 9676 KB Output is correct
17 Correct 8 ms 9676 KB Output is correct
18 Correct 11 ms 9644 KB Output is correct
19 Correct 9 ms 9620 KB Output is correct
20 Correct 8 ms 9676 KB Output is correct
21 Correct 9 ms 9696 KB Output is correct
22 Correct 8 ms 9676 KB Output is correct
23 Correct 8 ms 9704 KB Output is correct
24 Correct 8 ms 9676 KB Output is correct
25 Correct 8 ms 9676 KB Output is correct
26 Correct 7 ms 9696 KB Output is correct
27 Correct 8 ms 9676 KB Output is correct
28 Correct 8 ms 9676 KB Output is correct
29 Correct 9 ms 9676 KB Output is correct
30 Correct 8 ms 9676 KB Output is correct
31 Correct 9 ms 9700 KB Output is correct
32 Correct 9 ms 9700 KB Output is correct
33 Correct 8 ms 9676 KB Output is correct
34 Correct 8 ms 9676 KB Output is correct
35 Correct 8 ms 9676 KB Output is correct
36 Correct 8 ms 9676 KB Output is correct
37 Correct 8 ms 9704 KB Output is correct
38 Correct 9 ms 9680 KB Output is correct
39 Correct 8 ms 9700 KB Output is correct
40 Correct 9 ms 9664 KB Output is correct
41 Correct 8 ms 9676 KB Output is correct
42 Correct 8 ms 9700 KB Output is correct
43 Correct 8 ms 9676 KB Output is correct
44 Correct 10 ms 9700 KB Output is correct
45 Correct 8 ms 9676 KB Output is correct
46 Correct 8 ms 9636 KB Output is correct
47 Correct 8 ms 9812 KB Output is correct
48 Correct 9 ms 9676 KB Output is correct
49 Correct 8 ms 9676 KB Output is correct
50 Correct 8 ms 9676 KB Output is correct
51 Correct 9 ms 9692 KB Output is correct
52 Correct 8 ms 9704 KB Output is correct
53 Correct 7 ms 9676 KB Output is correct
54 Correct 11 ms 10316 KB Output is correct
55 Correct 11 ms 10268 KB Output is correct
56 Correct 37 ms 14948 KB Output is correct
57 Correct 36 ms 15032 KB Output is correct
58 Correct 51 ms 15172 KB Output is correct
59 Correct 40 ms 14360 KB Output is correct
60 Correct 41 ms 15072 KB Output is correct
61 Correct 34 ms 14776 KB Output is correct
62 Correct 33 ms 14564 KB Output is correct
63 Correct 34 ms 14548 KB Output is correct
64 Correct 36 ms 14552 KB Output is correct
65 Correct 54 ms 14952 KB Output is correct
66 Correct 39 ms 14524 KB Output is correct
67 Correct 33 ms 14440 KB Output is correct
68 Correct 33 ms 14556 KB Output is correct
69 Correct 8 ms 9676 KB Output is correct
70 Correct 8 ms 9700 KB Output is correct
71 Correct 35 ms 14568 KB Output is correct
72 Correct 36 ms 14556 KB Output is correct
73 Correct 32 ms 14572 KB Output is correct
74 Correct 9 ms 9692 KB Output is correct
75 Correct 8 ms 9688 KB Output is correct
76 Correct 8 ms 9676 KB Output is correct
77 Correct 9 ms 9804 KB Output is correct
78 Correct 55 ms 19932 KB Output is correct
79 Correct 59 ms 15128 KB Output is correct
80 Correct 64 ms 19812 KB Output is correct
81 Correct 34 ms 14572 KB Output is correct
82 Correct 65 ms 19916 KB Output is correct
83 Correct 50 ms 16748 KB Output is correct
84 Correct 8 ms 9676 KB Output is correct
85 Correct 10 ms 9732 KB Output is correct
86 Correct 9 ms 9676 KB Output is correct
87 Correct 9 ms 9700 KB Output is correct
88 Correct 8 ms 9804 KB Output is correct
89 Correct 9 ms 9828 KB Output is correct
90 Correct 8 ms 9804 KB Output is correct
91 Correct 9 ms 9804 KB Output is correct
92 Correct 9 ms 9804 KB Output is correct
93 Correct 9 ms 9728 KB Output is correct
94 Correct 9 ms 9676 KB Output is correct
95 Correct 8 ms 9676 KB Output is correct
96 Correct 8 ms 9676 KB Output is correct
97 Correct 10 ms 9704 KB Output is correct
98 Correct 9 ms 9676 KB Output is correct
99 Correct 9 ms 9804 KB Output is correct
100 Correct 8 ms 9804 KB Output is correct
101 Correct 12 ms 10652 KB Output is correct
102 Correct 11 ms 10316 KB Output is correct
103 Correct 83 ms 20196 KB Output is correct
104 Correct 61 ms 20312 KB Output is correct
105 Correct 95 ms 17604 KB Output is correct
106 Correct 82 ms 19816 KB Output is correct
107 Correct 57 ms 15632 KB Output is correct
108 Correct 68 ms 15944 KB Output is correct
109 Correct 33 ms 14908 KB Output is correct
110 Correct 32 ms 14524 KB Output is correct
111 Correct 54 ms 19236 KB Output is correct
112 Correct 87 ms 18876 KB Output is correct
113 Correct 50 ms 15212 KB Output is correct
114 Correct 63 ms 19924 KB Output is correct
115 Correct 56 ms 19948 KB Output is correct