Submission #155770

# Submission time Handle Problem Language Result Execution time Memory
155770 2019-09-30T13:27:51 Z Sasuke0004 Arranging Shoes (IOI19_shoes) C++17
50 / 100
477 ms 29484 KB
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
ll i,j,n,t,ans,k,b[200001],fix[200001],c[200001],seg[200001];
pair <ll,ll> a[200001];
map <ll,ll> m;
vector <ll> 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;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4984 KB Output is correct
2 Correct 7 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4984 KB Output is correct
2 Correct 7 ms 4984 KB Output is correct
3 Correct 7 ms 5112 KB Output is correct
4 Correct 7 ms 5112 KB Output is correct
5 Correct 6 ms 5112 KB Output is correct
6 Correct 7 ms 5112 KB Output is correct
7 Correct 7 ms 5112 KB Output is correct
8 Correct 7 ms 5112 KB Output is correct
9 Correct 6 ms 5084 KB Output is correct
10 Correct 7 ms 5112 KB Output is correct
11 Correct 6 ms 4984 KB Output is correct
12 Correct 6 ms 5112 KB Output is correct
13 Correct 6 ms 5116 KB Output is correct
14 Correct 6 ms 4984 KB Output is correct
15 Correct 6 ms 4988 KB Output is correct
16 Correct 6 ms 5112 KB Output is correct
17 Correct 6 ms 5112 KB Output is correct
18 Correct 6 ms 5112 KB Output is correct
19 Correct 6 ms 5112 KB Output is correct
20 Correct 6 ms 4988 KB Output is correct
21 Correct 6 ms 4984 KB Output is correct
22 Correct 6 ms 4984 KB Output is correct
23 Correct 6 ms 5112 KB Output is correct
24 Correct 6 ms 5112 KB Output is correct
25 Correct 6 ms 4984 KB Output is correct
26 Correct 6 ms 4984 KB Output is correct
27 Correct 8 ms 5084 KB Output is correct
28 Correct 6 ms 5112 KB Output is correct
29 Correct 6 ms 5116 KB Output is correct
30 Correct 6 ms 5112 KB Output is correct
31 Correct 7 ms 5112 KB Output is correct
32 Correct 6 ms 5112 KB Output is correct
33 Correct 7 ms 5120 KB Output is correct
34 Correct 6 ms 4984 KB Output is correct
35 Correct 6 ms 4984 KB Output is correct
36 Correct 6 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4984 KB Output is correct
2 Correct 7 ms 4984 KB Output is correct
3 Correct 6 ms 4984 KB Output is correct
4 Correct 6 ms 5112 KB Output is correct
5 Correct 6 ms 5112 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 7 ms 4984 KB Output is correct
10 Correct 6 ms 4984 KB Output is correct
11 Correct 6 ms 4984 KB Output is correct
12 Correct 6 ms 4984 KB Output is correct
13 Correct 6 ms 4984 KB Output is correct
14 Correct 6 ms 4984 KB Output is correct
15 Correct 6 ms 4984 KB Output is correct
16 Correct 6 ms 5112 KB Output is correct
17 Correct 7 ms 5112 KB Output is correct
18 Correct 7 ms 5240 KB Output is correct
19 Correct 7 ms 5244 KB Output is correct
20 Correct 16 ms 6436 KB Output is correct
21 Correct 16 ms 6516 KB Output is correct
22 Incorrect 114 ms 15592 KB Output isn't correct
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 6 ms 5116 KB Output is correct
3 Correct 6 ms 4988 KB Output is correct
4 Correct 6 ms 5112 KB Output is correct
5 Incorrect 477 ms 29484 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4984 KB Output is correct
2 Correct 7 ms 4984 KB Output is correct
3 Correct 7 ms 5112 KB Output is correct
4 Correct 7 ms 5112 KB Output is correct
5 Correct 6 ms 5112 KB Output is correct
6 Correct 7 ms 5112 KB Output is correct
7 Correct 7 ms 5112 KB Output is correct
8 Correct 7 ms 5112 KB Output is correct
9 Correct 6 ms 5084 KB Output is correct
10 Correct 7 ms 5112 KB Output is correct
11 Correct 6 ms 4984 KB Output is correct
12 Correct 6 ms 5112 KB Output is correct
13 Correct 6 ms 5116 KB Output is correct
14 Correct 6 ms 4984 KB Output is correct
15 Correct 6 ms 4988 KB Output is correct
16 Correct 6 ms 5112 KB Output is correct
17 Correct 6 ms 5112 KB Output is correct
18 Correct 6 ms 5112 KB Output is correct
19 Correct 6 ms 5112 KB Output is correct
20 Correct 6 ms 4988 KB Output is correct
21 Correct 6 ms 4984 KB Output is correct
22 Correct 6 ms 4984 KB Output is correct
23 Correct 6 ms 5112 KB Output is correct
24 Correct 6 ms 5112 KB Output is correct
25 Correct 6 ms 4984 KB Output is correct
26 Correct 6 ms 4984 KB Output is correct
27 Correct 8 ms 5084 KB Output is correct
28 Correct 6 ms 5112 KB Output is correct
29 Correct 6 ms 5116 KB Output is correct
30 Correct 6 ms 5112 KB Output is correct
31 Correct 7 ms 5112 KB Output is correct
32 Correct 6 ms 5112 KB Output is correct
33 Correct 7 ms 5120 KB Output is correct
34 Correct 6 ms 4984 KB Output is correct
35 Correct 6 ms 4984 KB Output is correct
36 Correct 6 ms 4984 KB Output is correct
37 Correct 6 ms 5112 KB Output is correct
38 Correct 6 ms 4988 KB Output is correct
39 Correct 7 ms 5112 KB Output is correct
40 Correct 7 ms 5112 KB Output is correct
41 Correct 10 ms 5372 KB Output is correct
42 Correct 10 ms 5368 KB Output is correct
43 Correct 9 ms 5368 KB Output is correct
44 Correct 9 ms 5284 KB Output is correct
45 Correct 9 ms 5240 KB Output is correct
46 Correct 9 ms 5240 KB Output is correct
47 Correct 8 ms 5244 KB Output is correct
48 Correct 7 ms 5240 KB Output is correct
49 Correct 8 ms 5240 KB Output is correct
50 Correct 7 ms 5240 KB Output is correct
51 Correct 7 ms 5112 KB Output is correct
52 Correct 8 ms 5368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4984 KB Output is correct
2 Correct 7 ms 4984 KB Output is correct
3 Correct 7 ms 5112 KB Output is correct
4 Correct 7 ms 5112 KB Output is correct
5 Correct 6 ms 5112 KB Output is correct
6 Correct 7 ms 5112 KB Output is correct
7 Correct 7 ms 5112 KB Output is correct
8 Correct 7 ms 5112 KB Output is correct
9 Correct 6 ms 5084 KB Output is correct
10 Correct 7 ms 5112 KB Output is correct
11 Correct 6 ms 4984 KB Output is correct
12 Correct 6 ms 5112 KB Output is correct
13 Correct 6 ms 5116 KB Output is correct
14 Correct 6 ms 4984 KB Output is correct
15 Correct 6 ms 4988 KB Output is correct
16 Correct 6 ms 5112 KB Output is correct
17 Correct 6 ms 5112 KB Output is correct
18 Correct 6 ms 5112 KB Output is correct
19 Correct 6 ms 5112 KB Output is correct
20 Correct 6 ms 4988 KB Output is correct
21 Correct 6 ms 4984 KB Output is correct
22 Correct 6 ms 4984 KB Output is correct
23 Correct 6 ms 5112 KB Output is correct
24 Correct 6 ms 5112 KB Output is correct
25 Correct 6 ms 4984 KB Output is correct
26 Correct 6 ms 4984 KB Output is correct
27 Correct 8 ms 5084 KB Output is correct
28 Correct 6 ms 5112 KB Output is correct
29 Correct 6 ms 5116 KB Output is correct
30 Correct 6 ms 5112 KB Output is correct
31 Correct 7 ms 5112 KB Output is correct
32 Correct 6 ms 5112 KB Output is correct
33 Correct 7 ms 5120 KB Output is correct
34 Correct 6 ms 4984 KB Output is correct
35 Correct 6 ms 4984 KB Output is correct
36 Correct 6 ms 4984 KB Output is correct
37 Correct 6 ms 4984 KB Output is correct
38 Correct 6 ms 5112 KB Output is correct
39 Correct 6 ms 5112 KB Output is correct
40 Correct 6 ms 4984 KB Output is correct
41 Correct 6 ms 5112 KB Output is correct
42 Correct 6 ms 5112 KB Output is correct
43 Correct 7 ms 4984 KB Output is correct
44 Correct 6 ms 4984 KB Output is correct
45 Correct 6 ms 4984 KB Output is correct
46 Correct 6 ms 4984 KB Output is correct
47 Correct 6 ms 4984 KB Output is correct
48 Correct 6 ms 4984 KB Output is correct
49 Correct 6 ms 4984 KB Output is correct
50 Correct 6 ms 5112 KB Output is correct
51 Correct 7 ms 5112 KB Output is correct
52 Correct 7 ms 5240 KB Output is correct
53 Correct 7 ms 5244 KB Output is correct
54 Correct 16 ms 6436 KB Output is correct
55 Correct 16 ms 6516 KB Output is correct
56 Incorrect 114 ms 15592 KB Output isn't correct
57 Halted 0 ms 0 KB -