답안 #155768

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
155768 2019-09-30T13:25:38 Z Sasuke0004 Arranging Shoes (IOI19_shoes) C++17
50 / 100
498 ms 22776 KB
#include <bits/stdc++.h>
using namespace std;
int i,j,n,t,ans,k,b[200001],fix[200001],c[200001],seg[200001];
pair <int,int> a[200001];
map <int,int> m;
vector <int> v[200001];
 void upd(int h,int l,int r,int val,int ind) {
    if (ind<l || ind>r) return;
    if (l==ind && r==ind) {seg[h]=1;return;}
    upd(h*2,l,(l+r)/2,val,ind);
    upd(h*2+1,(l+r)/2+1,r,val,ind);
    seg[h]=seg[h*2]+seg[h*2+1];
}
int get(int h,int l,int r,int L,int R) {
    if (l>R || r<L) return 0;
    if (l>=L && r<=R) return seg[h];
    return get(h*2,l,(l+r)/2,L,R)+get(h*2+1,(l+r)/2+1,r,L,R);
}
int64_t count_swaps(vector<int> p){
    n=p.size()/2;
    for (i=1;i<=2*n;i++) {
        b[i]=p[i-1];
        c[i]=b[i];
        if (b[i]>0) {fix[b[i]]++;v[b[i]].push_back(i);}
    }
   for (i=1;i<=2*n;i++) {
        m[b[i]]=0;
       if (b[i]<0) {v[abs(b[i])].push_back(i);}
    }
    for (i=1;i<=2*n;i++) {
        if (b[i]>0)  m[b[i]]=0;
        else
        m[b[i]]+=1;
    }
    t=1;
    for (i=1;i<=2*n;i++) {
        if (b[i]==0) continue;
        if (b[i]>0) {
            a[t].first=v[b[i]][m[-1*b[i]]];
            a[t].second=i;
            m[-1*b[i]]++;
            m[b[i]]++;
            b[a[t].first]=0;
            b[a[t].second]=0;
            t++;
        }
        else
        {
            a[t].first=i;
            a[t].second=v[-1*b[i]][m[-1*b[i]]];
            m[-1*b[i]]++;
            m[b[i]]++;
            b[a[t].first]=0;
            b[a[t].second]=0;
            t++;
        }
    } 
       for (i=1;i<=n;i++) {
        if (c[min(a[i].first,a[i].second)]>0) {ans=ans+max(a[i].first,a[i].second)-min(a[i].first,a[i].second);}
        else
        ans=ans+max(a[i].second,a[i].first)-min(a[i].second,a[i].first)-1;
    }
    for (i=1;i<=n;i++) {
        ans=ans-get(1,1,2*n+1,min(a[i].first,a[i].second),max(a[i].first,a[i].second));
        upd(1,1,2*n+1,1,a[i].first);
        upd(1,1,2*n+1,1,a[i].second);
    } 
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 6 ms 4984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 6 ms 4984 KB Output is correct
3 Correct 6 ms 4984 KB Output is correct
4 Correct 6 ms 4984 KB Output is correct
5 Correct 6 ms 4984 KB Output is correct
6 Correct 6 ms 4984 KB Output is correct
7 Correct 6 ms 5112 KB Output is correct
8 Correct 6 ms 5112 KB Output is correct
9 Correct 6 ms 5112 KB Output is correct
10 Correct 6 ms 4984 KB Output is correct
11 Correct 6 ms 5112 KB Output is correct
12 Correct 6 ms 4984 KB Output is correct
13 Correct 7 ms 4984 KB Output is correct
14 Correct 3 ms 5112 KB Output is correct
15 Correct 7 ms 5116 KB Output is correct
16 Correct 7 ms 5112 KB Output is correct
17 Correct 7 ms 5112 KB Output is correct
18 Correct 7 ms 5112 KB Output is correct
19 Correct 7 ms 4984 KB Output is correct
20 Correct 7 ms 4988 KB Output is correct
21 Correct 7 ms 4984 KB Output is correct
22 Correct 7 ms 5112 KB Output is correct
23 Correct 7 ms 4984 KB Output is correct
24 Correct 7 ms 4984 KB Output is correct
25 Correct 6 ms 4984 KB Output is correct
26 Correct 6 ms 4988 KB Output is correct
27 Correct 6 ms 4984 KB Output is correct
28 Correct 4 ms 5112 KB Output is correct
29 Correct 7 ms 4984 KB Output is correct
30 Correct 7 ms 5112 KB Output is correct
31 Correct 8 ms 4984 KB Output is correct
32 Correct 7 ms 5112 KB Output is correct
33 Correct 7 ms 5112 KB Output is correct
34 Correct 7 ms 5112 KB Output is correct
35 Correct 6 ms 5084 KB Output is correct
36 Correct 6 ms 5084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 6 ms 4984 KB Output is correct
3 Correct 6 ms 4984 KB Output is correct
4 Correct 6 ms 5116 KB Output is correct
5 Correct 6 ms 5112 KB Output is correct
6 Correct 6 ms 5112 KB Output is correct
7 Correct 6 ms 5036 KB Output is correct
8 Correct 6 ms 4984 KB Output is correct
9 Correct 6 ms 5112 KB Output is correct
10 Correct 6 ms 4984 KB Output is correct
11 Correct 6 ms 5112 KB Output is correct
12 Correct 6 ms 5112 KB Output is correct
13 Correct 6 ms 5112 KB Output is correct
14 Correct 6 ms 5112 KB Output is correct
15 Correct 6 ms 5112 KB Output is correct
16 Correct 6 ms 5112 KB Output is correct
17 Correct 7 ms 5112 KB Output is correct
18 Correct 8 ms 5112 KB Output is correct
19 Correct 7 ms 5112 KB Output is correct
20 Correct 15 ms 5880 KB Output is correct
21 Correct 16 ms 5880 KB Output is correct
22 Incorrect 112 ms 11200 KB Output isn't correct
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5112 KB Output is correct
2 Correct 6 ms 5020 KB Output is correct
3 Correct 6 ms 5112 KB Output is correct
4 Correct 7 ms 5004 KB Output is correct
5 Incorrect 498 ms 22776 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 6 ms 4984 KB Output is correct
3 Correct 6 ms 4984 KB Output is correct
4 Correct 6 ms 4984 KB Output is correct
5 Correct 6 ms 4984 KB Output is correct
6 Correct 6 ms 4984 KB Output is correct
7 Correct 6 ms 5112 KB Output is correct
8 Correct 6 ms 5112 KB Output is correct
9 Correct 6 ms 5112 KB Output is correct
10 Correct 6 ms 4984 KB Output is correct
11 Correct 6 ms 5112 KB Output is correct
12 Correct 6 ms 4984 KB Output is correct
13 Correct 7 ms 4984 KB Output is correct
14 Correct 3 ms 5112 KB Output is correct
15 Correct 7 ms 5116 KB Output is correct
16 Correct 7 ms 5112 KB Output is correct
17 Correct 7 ms 5112 KB Output is correct
18 Correct 7 ms 5112 KB Output is correct
19 Correct 7 ms 4984 KB Output is correct
20 Correct 7 ms 4988 KB Output is correct
21 Correct 7 ms 4984 KB Output is correct
22 Correct 7 ms 5112 KB Output is correct
23 Correct 7 ms 4984 KB Output is correct
24 Correct 7 ms 4984 KB Output is correct
25 Correct 6 ms 4984 KB Output is correct
26 Correct 6 ms 4988 KB Output is correct
27 Correct 6 ms 4984 KB Output is correct
28 Correct 4 ms 5112 KB Output is correct
29 Correct 7 ms 4984 KB Output is correct
30 Correct 7 ms 5112 KB Output is correct
31 Correct 8 ms 4984 KB Output is correct
32 Correct 7 ms 5112 KB Output is correct
33 Correct 7 ms 5112 KB Output is correct
34 Correct 7 ms 5112 KB Output is correct
35 Correct 6 ms 5084 KB Output is correct
36 Correct 6 ms 5084 KB Output is correct
37 Correct 6 ms 5112 KB Output is correct
38 Correct 6 ms 5112 KB Output is correct
39 Correct 6 ms 4984 KB Output is correct
40 Correct 6 ms 5112 KB Output is correct
41 Correct 20 ms 5240 KB Output is correct
42 Correct 7 ms 5240 KB Output is correct
43 Correct 8 ms 5240 KB Output is correct
44 Correct 8 ms 5112 KB Output is correct
45 Correct 7 ms 5112 KB Output is correct
46 Correct 7 ms 5112 KB Output is correct
47 Correct 8 ms 5112 KB Output is correct
48 Correct 7 ms 5112 KB Output is correct
49 Correct 7 ms 5112 KB Output is correct
50 Correct 7 ms 5112 KB Output is correct
51 Correct 7 ms 5112 KB Output is correct
52 Correct 8 ms 5240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 6 ms 4984 KB Output is correct
3 Correct 6 ms 4984 KB Output is correct
4 Correct 6 ms 4984 KB Output is correct
5 Correct 6 ms 4984 KB Output is correct
6 Correct 6 ms 4984 KB Output is correct
7 Correct 6 ms 5112 KB Output is correct
8 Correct 6 ms 5112 KB Output is correct
9 Correct 6 ms 5112 KB Output is correct
10 Correct 6 ms 4984 KB Output is correct
11 Correct 6 ms 5112 KB Output is correct
12 Correct 6 ms 4984 KB Output is correct
13 Correct 7 ms 4984 KB Output is correct
14 Correct 3 ms 5112 KB Output is correct
15 Correct 7 ms 5116 KB Output is correct
16 Correct 7 ms 5112 KB Output is correct
17 Correct 7 ms 5112 KB Output is correct
18 Correct 7 ms 5112 KB Output is correct
19 Correct 7 ms 4984 KB Output is correct
20 Correct 7 ms 4988 KB Output is correct
21 Correct 7 ms 4984 KB Output is correct
22 Correct 7 ms 5112 KB Output is correct
23 Correct 7 ms 4984 KB Output is correct
24 Correct 7 ms 4984 KB Output is correct
25 Correct 6 ms 4984 KB Output is correct
26 Correct 6 ms 4988 KB Output is correct
27 Correct 6 ms 4984 KB Output is correct
28 Correct 4 ms 5112 KB Output is correct
29 Correct 7 ms 4984 KB Output is correct
30 Correct 7 ms 5112 KB Output is correct
31 Correct 8 ms 4984 KB Output is correct
32 Correct 7 ms 5112 KB Output is correct
33 Correct 7 ms 5112 KB Output is correct
34 Correct 7 ms 5112 KB Output is correct
35 Correct 6 ms 5084 KB Output is correct
36 Correct 6 ms 5084 KB Output is correct
37 Correct 6 ms 4984 KB Output is correct
38 Correct 6 ms 5116 KB Output is correct
39 Correct 6 ms 5112 KB Output is correct
40 Correct 6 ms 5112 KB Output is correct
41 Correct 6 ms 5036 KB Output is correct
42 Correct 6 ms 4984 KB Output is correct
43 Correct 6 ms 5112 KB Output is correct
44 Correct 6 ms 4984 KB Output is correct
45 Correct 6 ms 5112 KB Output is correct
46 Correct 6 ms 5112 KB Output is correct
47 Correct 6 ms 5112 KB Output is correct
48 Correct 6 ms 5112 KB Output is correct
49 Correct 6 ms 5112 KB Output is correct
50 Correct 6 ms 5112 KB Output is correct
51 Correct 7 ms 5112 KB Output is correct
52 Correct 8 ms 5112 KB Output is correct
53 Correct 7 ms 5112 KB Output is correct
54 Correct 15 ms 5880 KB Output is correct
55 Correct 16 ms 5880 KB Output is correct
56 Incorrect 112 ms 11200 KB Output isn't correct
57 Halted 0 ms 0 KB -