답안 #211175

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
211175 2020-03-19T11:00:02 Z arctan Arranging Shoes (IOI19_shoes) C++14
100 / 100
198 ms 141176 KB
#include<bits/stdc++.h>
#include "shoes.h"
using namespace std;


typedef long long ll;
const ll mod=1e9+7;
const ll maxn=200005;
const ll inf=1e9+7;
queue<ll> m[2][100005];
ll BIT[maxn];
inline int lsb(int x)
{
    return x&(-x);
}
void add(int x,int v)
{
  	for(int i=x;i<maxn;i+=lsb(i))
    {
        BIT[i]+=v;
    }

}
ll query(ll x)
{
    //assert(x>=0);
    ll res=0;
  	int cnt=0;
    for(int i=x;i>0;i-=lsb(i))
    {
        res+=BIT[i];
    }
    return res;
}
ll count_swaps(std::vector<int> s)
{
    for(int i=0;i<s.size();i++)
    {
        bool x=0;
        if(s[i]<0)
        {
            x=1;
            m[x][-s[i]].push(i);
        }
        else m[x][s[i]].push(i);
        add(i+1,1);
    }
    ll sum=0;
    for(int i=0;i<s.size();i++)
    {
        bool x=(s[i]<0);
        s[i]=abs(s[i]);
        
        if(m[!x][s[i]].empty()) continue;
        if(m[x][s[i]].front()!=i) continue;
        assert(m[!x][s[i]].size()==m[x][s[i]].size());
        ll p=m[!x][s[i]].front();
        m[x][s[i]].pop();
        m[!x][s[i]].pop();
        sum+=query(p)-query(i+1);
        if(!x) sum++;
        //cout<<i<<" "<<sum<<"\n";
        add(p+1,-1);
        //add(i+1,-1);
        //if(i>50000) assert(0);
    }



    return sum;
}

Compilation message

shoes.cpp: In function 'll query(ll)':
shoes.cpp:28:8: warning: unused variable 'cnt' [-Wunused-variable]
    int cnt=0;
        ^~~
shoes.cpp: In function 'll count_swaps(std::vector<int>)':
shoes.cpp:37:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<s.size();i++)
                 ~^~~~~~~~~
shoes.cpp:49:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<s.size();i++)
                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 135032 KB Output is correct
2 Correct 97 ms 135160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 135032 KB Output is correct
2 Correct 97 ms 135160 KB Output is correct
3 Correct 96 ms 135032 KB Output is correct
4 Correct 95 ms 135032 KB Output is correct
5 Correct 94 ms 135032 KB Output is correct
6 Correct 104 ms 135032 KB Output is correct
7 Correct 98 ms 135032 KB Output is correct
8 Correct 95 ms 135032 KB Output is correct
9 Correct 96 ms 135032 KB Output is correct
10 Correct 92 ms 135032 KB Output is correct
11 Correct 94 ms 134956 KB Output is correct
12 Correct 94 ms 135032 KB Output is correct
13 Correct 95 ms 135032 KB Output is correct
14 Correct 100 ms 135160 KB Output is correct
15 Correct 93 ms 135032 KB Output is correct
16 Correct 96 ms 135032 KB Output is correct
17 Correct 94 ms 135032 KB Output is correct
18 Correct 93 ms 135032 KB Output is correct
19 Correct 95 ms 135032 KB Output is correct
20 Correct 98 ms 135032 KB Output is correct
21 Correct 97 ms 135032 KB Output is correct
22 Correct 93 ms 135032 KB Output is correct
23 Correct 93 ms 135032 KB Output is correct
24 Correct 97 ms 135032 KB Output is correct
25 Correct 95 ms 135032 KB Output is correct
26 Correct 94 ms 135032 KB Output is correct
27 Correct 97 ms 135036 KB Output is correct
28 Correct 97 ms 135032 KB Output is correct
29 Correct 92 ms 134904 KB Output is correct
30 Correct 93 ms 135032 KB Output is correct
31 Correct 94 ms 134964 KB Output is correct
32 Correct 95 ms 135028 KB Output is correct
33 Correct 94 ms 135160 KB Output is correct
34 Correct 94 ms 135032 KB Output is correct
35 Correct 95 ms 135032 KB Output is correct
36 Correct 95 ms 135032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 135032 KB Output is correct
2 Correct 97 ms 135160 KB Output is correct
3 Correct 99 ms 135032 KB Output is correct
4 Correct 93 ms 135032 KB Output is correct
5 Correct 95 ms 135032 KB Output is correct
6 Correct 99 ms 135032 KB Output is correct
7 Correct 93 ms 135032 KB Output is correct
8 Correct 93 ms 135032 KB Output is correct
9 Correct 95 ms 135032 KB Output is correct
10 Correct 93 ms 135032 KB Output is correct
11 Correct 97 ms 135160 KB Output is correct
12 Correct 95 ms 135036 KB Output is correct
13 Correct 98 ms 135032 KB Output is correct
14 Correct 97 ms 135032 KB Output is correct
15 Correct 93 ms 135032 KB Output is correct
16 Correct 101 ms 134980 KB Output is correct
17 Correct 100 ms 135032 KB Output is correct
18 Correct 103 ms 135032 KB Output is correct
19 Correct 104 ms 135032 KB Output is correct
20 Correct 105 ms 135544 KB Output is correct
21 Correct 106 ms 135540 KB Output is correct
22 Correct 144 ms 139768 KB Output is correct
23 Correct 144 ms 141048 KB Output is correct
24 Correct 144 ms 141176 KB Output is correct
25 Correct 143 ms 140796 KB Output is correct
26 Correct 141 ms 141048 KB Output is correct
27 Correct 145 ms 140792 KB Output is correct
28 Correct 139 ms 141084 KB Output is correct
29 Correct 137 ms 141048 KB Output is correct
30 Correct 134 ms 141048 KB Output is correct
31 Correct 143 ms 141048 KB Output is correct
32 Correct 139 ms 141052 KB Output is correct
33 Correct 140 ms 140792 KB Output is correct
34 Correct 137 ms 141052 KB Output is correct
35 Correct 94 ms 135032 KB Output is correct
36 Correct 96 ms 135032 KB Output is correct
37 Correct 137 ms 141048 KB Output is correct
38 Correct 140 ms 141048 KB Output is correct
39 Correct 139 ms 141048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 135032 KB Output is correct
2 Correct 97 ms 134980 KB Output is correct
3 Correct 93 ms 135032 KB Output is correct
4 Correct 94 ms 135040 KB Output is correct
5 Correct 181 ms 138080 KB Output is correct
6 Correct 165 ms 138232 KB Output is correct
7 Correct 184 ms 138104 KB Output is correct
8 Correct 141 ms 139768 KB Output is correct
9 Correct 183 ms 139408 KB Output is correct
10 Correct 174 ms 139384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 135032 KB Output is correct
2 Correct 97 ms 135160 KB Output is correct
3 Correct 96 ms 135032 KB Output is correct
4 Correct 95 ms 135032 KB Output is correct
5 Correct 94 ms 135032 KB Output is correct
6 Correct 104 ms 135032 KB Output is correct
7 Correct 98 ms 135032 KB Output is correct
8 Correct 95 ms 135032 KB Output is correct
9 Correct 96 ms 135032 KB Output is correct
10 Correct 92 ms 135032 KB Output is correct
11 Correct 94 ms 134956 KB Output is correct
12 Correct 94 ms 135032 KB Output is correct
13 Correct 95 ms 135032 KB Output is correct
14 Correct 100 ms 135160 KB Output is correct
15 Correct 93 ms 135032 KB Output is correct
16 Correct 96 ms 135032 KB Output is correct
17 Correct 94 ms 135032 KB Output is correct
18 Correct 93 ms 135032 KB Output is correct
19 Correct 95 ms 135032 KB Output is correct
20 Correct 98 ms 135032 KB Output is correct
21 Correct 97 ms 135032 KB Output is correct
22 Correct 93 ms 135032 KB Output is correct
23 Correct 93 ms 135032 KB Output is correct
24 Correct 97 ms 135032 KB Output is correct
25 Correct 95 ms 135032 KB Output is correct
26 Correct 94 ms 135032 KB Output is correct
27 Correct 97 ms 135036 KB Output is correct
28 Correct 97 ms 135032 KB Output is correct
29 Correct 92 ms 134904 KB Output is correct
30 Correct 93 ms 135032 KB Output is correct
31 Correct 94 ms 134964 KB Output is correct
32 Correct 95 ms 135028 KB Output is correct
33 Correct 94 ms 135160 KB Output is correct
34 Correct 94 ms 135032 KB Output is correct
35 Correct 95 ms 135032 KB Output is correct
36 Correct 95 ms 135032 KB Output is correct
37 Correct 92 ms 135032 KB Output is correct
38 Correct 98 ms 134972 KB Output is correct
39 Correct 98 ms 135032 KB Output is correct
40 Correct 95 ms 135032 KB Output is correct
41 Correct 98 ms 135032 KB Output is correct
42 Correct 98 ms 135032 KB Output is correct
43 Correct 94 ms 135032 KB Output is correct
44 Correct 100 ms 135076 KB Output is correct
45 Correct 95 ms 135032 KB Output is correct
46 Correct 92 ms 134992 KB Output is correct
47 Correct 96 ms 135032 KB Output is correct
48 Correct 96 ms 135032 KB Output is correct
49 Correct 98 ms 135032 KB Output is correct
50 Correct 102 ms 135032 KB Output is correct
51 Correct 102 ms 135032 KB Output is correct
52 Correct 95 ms 135032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 135032 KB Output is correct
2 Correct 97 ms 135160 KB Output is correct
3 Correct 96 ms 135032 KB Output is correct
4 Correct 95 ms 135032 KB Output is correct
5 Correct 94 ms 135032 KB Output is correct
6 Correct 104 ms 135032 KB Output is correct
7 Correct 98 ms 135032 KB Output is correct
8 Correct 95 ms 135032 KB Output is correct
9 Correct 96 ms 135032 KB Output is correct
10 Correct 92 ms 135032 KB Output is correct
11 Correct 94 ms 134956 KB Output is correct
12 Correct 94 ms 135032 KB Output is correct
13 Correct 95 ms 135032 KB Output is correct
14 Correct 100 ms 135160 KB Output is correct
15 Correct 93 ms 135032 KB Output is correct
16 Correct 96 ms 135032 KB Output is correct
17 Correct 94 ms 135032 KB Output is correct
18 Correct 93 ms 135032 KB Output is correct
19 Correct 95 ms 135032 KB Output is correct
20 Correct 98 ms 135032 KB Output is correct
21 Correct 97 ms 135032 KB Output is correct
22 Correct 93 ms 135032 KB Output is correct
23 Correct 93 ms 135032 KB Output is correct
24 Correct 97 ms 135032 KB Output is correct
25 Correct 95 ms 135032 KB Output is correct
26 Correct 94 ms 135032 KB Output is correct
27 Correct 97 ms 135036 KB Output is correct
28 Correct 97 ms 135032 KB Output is correct
29 Correct 92 ms 134904 KB Output is correct
30 Correct 93 ms 135032 KB Output is correct
31 Correct 94 ms 134964 KB Output is correct
32 Correct 95 ms 135028 KB Output is correct
33 Correct 94 ms 135160 KB Output is correct
34 Correct 94 ms 135032 KB Output is correct
35 Correct 95 ms 135032 KB Output is correct
36 Correct 95 ms 135032 KB Output is correct
37 Correct 99 ms 135032 KB Output is correct
38 Correct 93 ms 135032 KB Output is correct
39 Correct 95 ms 135032 KB Output is correct
40 Correct 99 ms 135032 KB Output is correct
41 Correct 93 ms 135032 KB Output is correct
42 Correct 93 ms 135032 KB Output is correct
43 Correct 95 ms 135032 KB Output is correct
44 Correct 93 ms 135032 KB Output is correct
45 Correct 97 ms 135160 KB Output is correct
46 Correct 95 ms 135036 KB Output is correct
47 Correct 98 ms 135032 KB Output is correct
48 Correct 97 ms 135032 KB Output is correct
49 Correct 93 ms 135032 KB Output is correct
50 Correct 101 ms 134980 KB Output is correct
51 Correct 100 ms 135032 KB Output is correct
52 Correct 103 ms 135032 KB Output is correct
53 Correct 104 ms 135032 KB Output is correct
54 Correct 105 ms 135544 KB Output is correct
55 Correct 106 ms 135540 KB Output is correct
56 Correct 144 ms 139768 KB Output is correct
57 Correct 144 ms 141048 KB Output is correct
58 Correct 144 ms 141176 KB Output is correct
59 Correct 143 ms 140796 KB Output is correct
60 Correct 141 ms 141048 KB Output is correct
61 Correct 145 ms 140792 KB Output is correct
62 Correct 139 ms 141084 KB Output is correct
63 Correct 137 ms 141048 KB Output is correct
64 Correct 134 ms 141048 KB Output is correct
65 Correct 143 ms 141048 KB Output is correct
66 Correct 139 ms 141052 KB Output is correct
67 Correct 140 ms 140792 KB Output is correct
68 Correct 137 ms 141052 KB Output is correct
69 Correct 94 ms 135032 KB Output is correct
70 Correct 96 ms 135032 KB Output is correct
71 Correct 137 ms 141048 KB Output is correct
72 Correct 140 ms 141048 KB Output is correct
73 Correct 139 ms 141048 KB Output is correct
74 Correct 95 ms 135032 KB Output is correct
75 Correct 97 ms 134980 KB Output is correct
76 Correct 93 ms 135032 KB Output is correct
77 Correct 94 ms 135040 KB Output is correct
78 Correct 181 ms 138080 KB Output is correct
79 Correct 165 ms 138232 KB Output is correct
80 Correct 184 ms 138104 KB Output is correct
81 Correct 141 ms 139768 KB Output is correct
82 Correct 183 ms 139408 KB Output is correct
83 Correct 174 ms 139384 KB Output is correct
84 Correct 92 ms 135032 KB Output is correct
85 Correct 98 ms 134972 KB Output is correct
86 Correct 98 ms 135032 KB Output is correct
87 Correct 95 ms 135032 KB Output is correct
88 Correct 98 ms 135032 KB Output is correct
89 Correct 98 ms 135032 KB Output is correct
90 Correct 94 ms 135032 KB Output is correct
91 Correct 100 ms 135076 KB Output is correct
92 Correct 95 ms 135032 KB Output is correct
93 Correct 92 ms 134992 KB Output is correct
94 Correct 96 ms 135032 KB Output is correct
95 Correct 96 ms 135032 KB Output is correct
96 Correct 98 ms 135032 KB Output is correct
97 Correct 102 ms 135032 KB Output is correct
98 Correct 102 ms 135032 KB Output is correct
99 Correct 95 ms 135032 KB Output is correct
100 Correct 100 ms 135032 KB Output is correct
101 Correct 105 ms 135416 KB Output is correct
102 Correct 102 ms 135416 KB Output is correct
103 Correct 195 ms 139384 KB Output is correct
104 Correct 193 ms 139388 KB Output is correct
105 Correct 187 ms 139384 KB Output is correct
106 Correct 180 ms 139384 KB Output is correct
107 Correct 171 ms 139384 KB Output is correct
108 Correct 173 ms 139312 KB Output is correct
109 Correct 136 ms 141048 KB Output is correct
110 Correct 143 ms 141052 KB Output is correct
111 Correct 186 ms 139384 KB Output is correct
112 Correct 198 ms 139384 KB Output is correct
113 Correct 171 ms 139384 KB Output is correct
114 Correct 182 ms 139340 KB Output is correct
115 Correct 183 ms 139384 KB Output is correct