Submission #155773

# Submission time Handle Problem Language Result Execution time Memory
155773 2019-09-30T13:29:59 Z Sasuke0004 Arranging Shoes (IOI19_shoes) C++17
100 / 100
652 ms 74360 KB
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
ll i,j,n,t,ans,k,b[2000001],fix[2000001],c[2000001],seg[2000001];
pair <ll,ll> a[2000001];
map <ll,ll> m;
vector <ll> v[2000001];
 void upd(ll h,ll l,ll r,ll val,ll 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];
}
ll get(ll h,ll l,ll r,ll L,ll 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 52 ms 47352 KB Output is correct
2 Correct 53 ms 47324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 47352 KB Output is correct
2 Correct 53 ms 47324 KB Output is correct
3 Correct 51 ms 47416 KB Output is correct
4 Correct 54 ms 47324 KB Output is correct
5 Correct 44 ms 47352 KB Output is correct
6 Correct 45 ms 47352 KB Output is correct
7 Correct 45 ms 47352 KB Output is correct
8 Correct 44 ms 47352 KB Output is correct
9 Correct 44 ms 47352 KB Output is correct
10 Correct 44 ms 47352 KB Output is correct
11 Correct 44 ms 47352 KB Output is correct
12 Correct 44 ms 47352 KB Output is correct
13 Correct 44 ms 47352 KB Output is correct
14 Correct 44 ms 47288 KB Output is correct
15 Correct 44 ms 47352 KB Output is correct
16 Correct 45 ms 47352 KB Output is correct
17 Correct 44 ms 47352 KB Output is correct
18 Correct 45 ms 47352 KB Output is correct
19 Correct 44 ms 47352 KB Output is correct
20 Correct 44 ms 47352 KB Output is correct
21 Correct 45 ms 47352 KB Output is correct
22 Correct 44 ms 47352 KB Output is correct
23 Correct 44 ms 47352 KB Output is correct
24 Correct 44 ms 47352 KB Output is correct
25 Correct 45 ms 47352 KB Output is correct
26 Correct 45 ms 47352 KB Output is correct
27 Correct 44 ms 47352 KB Output is correct
28 Correct 44 ms 47352 KB Output is correct
29 Correct 44 ms 47324 KB Output is correct
30 Correct 44 ms 47352 KB Output is correct
31 Correct 44 ms 47352 KB Output is correct
32 Correct 44 ms 47352 KB Output is correct
33 Correct 44 ms 47352 KB Output is correct
34 Correct 44 ms 47352 KB Output is correct
35 Correct 44 ms 47352 KB Output is correct
36 Correct 44 ms 47352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 47352 KB Output is correct
2 Correct 53 ms 47324 KB Output is correct
3 Correct 44 ms 47352 KB Output is correct
4 Correct 45 ms 47300 KB Output is correct
5 Correct 44 ms 47352 KB Output is correct
6 Correct 45 ms 47356 KB Output is correct
7 Correct 45 ms 47352 KB Output is correct
8 Correct 45 ms 47356 KB Output is correct
9 Correct 44 ms 47352 KB Output is correct
10 Correct 44 ms 47352 KB Output is correct
11 Correct 45 ms 47356 KB Output is correct
12 Correct 44 ms 47352 KB Output is correct
13 Correct 44 ms 47312 KB Output is correct
14 Correct 44 ms 47352 KB Output is correct
15 Correct 47 ms 47352 KB Output is correct
16 Correct 44 ms 47352 KB Output is correct
17 Correct 45 ms 47352 KB Output is correct
18 Correct 46 ms 47480 KB Output is correct
19 Correct 46 ms 47480 KB Output is correct
20 Correct 54 ms 48756 KB Output is correct
21 Correct 54 ms 48756 KB Output is correct
22 Correct 151 ms 59368 KB Output is correct
23 Correct 135 ms 59368 KB Output is correct
24 Correct 148 ms 59340 KB Output is correct
25 Correct 152 ms 59416 KB Output is correct
26 Correct 153 ms 59496 KB Output is correct
27 Correct 134 ms 59484 KB Output is correct
28 Correct 146 ms 59368 KB Output is correct
29 Correct 145 ms 59496 KB Output is correct
30 Correct 145 ms 59436 KB Output is correct
31 Correct 150 ms 59496 KB Output is correct
32 Correct 145 ms 59368 KB Output is correct
33 Correct 144 ms 59400 KB Output is correct
34 Correct 145 ms 59368 KB Output is correct
35 Correct 44 ms 47352 KB Output is correct
36 Correct 44 ms 47324 KB Output is correct
37 Correct 146 ms 59336 KB Output is correct
38 Correct 153 ms 59372 KB Output is correct
39 Correct 152 ms 59520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 47352 KB Output is correct
2 Correct 45 ms 47356 KB Output is correct
3 Correct 44 ms 47352 KB Output is correct
4 Correct 54 ms 47348 KB Output is correct
5 Correct 504 ms 74104 KB Output is correct
6 Correct 296 ms 62040 KB Output is correct
7 Correct 485 ms 74128 KB Output is correct
8 Correct 155 ms 59568 KB Output is correct
9 Correct 511 ms 74216 KB Output is correct
10 Correct 442 ms 67548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 47352 KB Output is correct
2 Correct 53 ms 47324 KB Output is correct
3 Correct 51 ms 47416 KB Output is correct
4 Correct 54 ms 47324 KB Output is correct
5 Correct 44 ms 47352 KB Output is correct
6 Correct 45 ms 47352 KB Output is correct
7 Correct 45 ms 47352 KB Output is correct
8 Correct 44 ms 47352 KB Output is correct
9 Correct 44 ms 47352 KB Output is correct
10 Correct 44 ms 47352 KB Output is correct
11 Correct 44 ms 47352 KB Output is correct
12 Correct 44 ms 47352 KB Output is correct
13 Correct 44 ms 47352 KB Output is correct
14 Correct 44 ms 47288 KB Output is correct
15 Correct 44 ms 47352 KB Output is correct
16 Correct 45 ms 47352 KB Output is correct
17 Correct 44 ms 47352 KB Output is correct
18 Correct 45 ms 47352 KB Output is correct
19 Correct 44 ms 47352 KB Output is correct
20 Correct 44 ms 47352 KB Output is correct
21 Correct 45 ms 47352 KB Output is correct
22 Correct 44 ms 47352 KB Output is correct
23 Correct 44 ms 47352 KB Output is correct
24 Correct 44 ms 47352 KB Output is correct
25 Correct 45 ms 47352 KB Output is correct
26 Correct 45 ms 47352 KB Output is correct
27 Correct 44 ms 47352 KB Output is correct
28 Correct 44 ms 47352 KB Output is correct
29 Correct 44 ms 47324 KB Output is correct
30 Correct 44 ms 47352 KB Output is correct
31 Correct 44 ms 47352 KB Output is correct
32 Correct 44 ms 47352 KB Output is correct
33 Correct 44 ms 47352 KB Output is correct
34 Correct 44 ms 47352 KB Output is correct
35 Correct 44 ms 47352 KB Output is correct
36 Correct 44 ms 47352 KB Output is correct
37 Correct 44 ms 47352 KB Output is correct
38 Correct 44 ms 47352 KB Output is correct
39 Correct 52 ms 47352 KB Output is correct
40 Correct 54 ms 47352 KB Output is correct
41 Correct 47 ms 47612 KB Output is correct
42 Correct 46 ms 47608 KB Output is correct
43 Correct 46 ms 47484 KB Output is correct
44 Correct 46 ms 47608 KB Output is correct
45 Correct 46 ms 47480 KB Output is correct
46 Correct 46 ms 47480 KB Output is correct
47 Correct 46 ms 47480 KB Output is correct
48 Correct 46 ms 47480 KB Output is correct
49 Correct 46 ms 47480 KB Output is correct
50 Correct 45 ms 47480 KB Output is correct
51 Correct 46 ms 47480 KB Output is correct
52 Correct 46 ms 47608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 47352 KB Output is correct
2 Correct 53 ms 47324 KB Output is correct
3 Correct 51 ms 47416 KB Output is correct
4 Correct 54 ms 47324 KB Output is correct
5 Correct 44 ms 47352 KB Output is correct
6 Correct 45 ms 47352 KB Output is correct
7 Correct 45 ms 47352 KB Output is correct
8 Correct 44 ms 47352 KB Output is correct
9 Correct 44 ms 47352 KB Output is correct
10 Correct 44 ms 47352 KB Output is correct
11 Correct 44 ms 47352 KB Output is correct
12 Correct 44 ms 47352 KB Output is correct
13 Correct 44 ms 47352 KB Output is correct
14 Correct 44 ms 47288 KB Output is correct
15 Correct 44 ms 47352 KB Output is correct
16 Correct 45 ms 47352 KB Output is correct
17 Correct 44 ms 47352 KB Output is correct
18 Correct 45 ms 47352 KB Output is correct
19 Correct 44 ms 47352 KB Output is correct
20 Correct 44 ms 47352 KB Output is correct
21 Correct 45 ms 47352 KB Output is correct
22 Correct 44 ms 47352 KB Output is correct
23 Correct 44 ms 47352 KB Output is correct
24 Correct 44 ms 47352 KB Output is correct
25 Correct 45 ms 47352 KB Output is correct
26 Correct 45 ms 47352 KB Output is correct
27 Correct 44 ms 47352 KB Output is correct
28 Correct 44 ms 47352 KB Output is correct
29 Correct 44 ms 47324 KB Output is correct
30 Correct 44 ms 47352 KB Output is correct
31 Correct 44 ms 47352 KB Output is correct
32 Correct 44 ms 47352 KB Output is correct
33 Correct 44 ms 47352 KB Output is correct
34 Correct 44 ms 47352 KB Output is correct
35 Correct 44 ms 47352 KB Output is correct
36 Correct 44 ms 47352 KB Output is correct
37 Correct 44 ms 47352 KB Output is correct
38 Correct 45 ms 47300 KB Output is correct
39 Correct 44 ms 47352 KB Output is correct
40 Correct 45 ms 47356 KB Output is correct
41 Correct 45 ms 47352 KB Output is correct
42 Correct 45 ms 47356 KB Output is correct
43 Correct 44 ms 47352 KB Output is correct
44 Correct 44 ms 47352 KB Output is correct
45 Correct 45 ms 47356 KB Output is correct
46 Correct 44 ms 47352 KB Output is correct
47 Correct 44 ms 47312 KB Output is correct
48 Correct 44 ms 47352 KB Output is correct
49 Correct 47 ms 47352 KB Output is correct
50 Correct 44 ms 47352 KB Output is correct
51 Correct 45 ms 47352 KB Output is correct
52 Correct 46 ms 47480 KB Output is correct
53 Correct 46 ms 47480 KB Output is correct
54 Correct 54 ms 48756 KB Output is correct
55 Correct 54 ms 48756 KB Output is correct
56 Correct 151 ms 59368 KB Output is correct
57 Correct 135 ms 59368 KB Output is correct
58 Correct 148 ms 59340 KB Output is correct
59 Correct 152 ms 59416 KB Output is correct
60 Correct 153 ms 59496 KB Output is correct
61 Correct 134 ms 59484 KB Output is correct
62 Correct 146 ms 59368 KB Output is correct
63 Correct 145 ms 59496 KB Output is correct
64 Correct 145 ms 59436 KB Output is correct
65 Correct 150 ms 59496 KB Output is correct
66 Correct 145 ms 59368 KB Output is correct
67 Correct 144 ms 59400 KB Output is correct
68 Correct 145 ms 59368 KB Output is correct
69 Correct 44 ms 47352 KB Output is correct
70 Correct 44 ms 47324 KB Output is correct
71 Correct 146 ms 59336 KB Output is correct
72 Correct 153 ms 59372 KB Output is correct
73 Correct 152 ms 59520 KB Output is correct
74 Correct 52 ms 47352 KB Output is correct
75 Correct 45 ms 47356 KB Output is correct
76 Correct 44 ms 47352 KB Output is correct
77 Correct 54 ms 47348 KB Output is correct
78 Correct 504 ms 74104 KB Output is correct
79 Correct 296 ms 62040 KB Output is correct
80 Correct 485 ms 74128 KB Output is correct
81 Correct 155 ms 59568 KB Output is correct
82 Correct 511 ms 74216 KB Output is correct
83 Correct 442 ms 67548 KB Output is correct
84 Correct 44 ms 47352 KB Output is correct
85 Correct 44 ms 47352 KB Output is correct
86 Correct 52 ms 47352 KB Output is correct
87 Correct 54 ms 47352 KB Output is correct
88 Correct 47 ms 47612 KB Output is correct
89 Correct 46 ms 47608 KB Output is correct
90 Correct 46 ms 47484 KB Output is correct
91 Correct 46 ms 47608 KB Output is correct
92 Correct 46 ms 47480 KB Output is correct
93 Correct 46 ms 47480 KB Output is correct
94 Correct 46 ms 47480 KB Output is correct
95 Correct 46 ms 47480 KB Output is correct
96 Correct 46 ms 47480 KB Output is correct
97 Correct 45 ms 47480 KB Output is correct
98 Correct 46 ms 47480 KB Output is correct
99 Correct 46 ms 47608 KB Output is correct
100 Correct 46 ms 47544 KB Output is correct
101 Correct 75 ms 50032 KB Output is correct
102 Correct 67 ms 49016 KB Output is correct
103 Correct 652 ms 74232 KB Output is correct
104 Correct 534 ms 74196 KB Output is correct
105 Correct 507 ms 68472 KB Output is correct
106 Correct 513 ms 74220 KB Output is correct
107 Correct 324 ms 62296 KB Output is correct
108 Correct 393 ms 63864 KB Output is correct
109 Correct 150 ms 59724 KB Output is correct
110 Correct 145 ms 59368 KB Output is correct
111 Correct 503 ms 73012 KB Output is correct
112 Correct 546 ms 71436 KB Output is correct
113 Correct 335 ms 62456 KB Output is correct
114 Correct 475 ms 74104 KB Output is correct
115 Correct 587 ms 74360 KB Output is correct