Submission #500877

# Submission time Handle Problem Language Result Execution time Memory
500877 2022-01-01T14:16:48 Z Khizri Arranging Shoes (IOI19_shoes) C++17
100 / 100
443 ms 149792 KB
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"OK"<<endl;
const int mxn=2e5+5;
ll color[mxn],n,tree[mxn];
ll query(int ind){
    ll ans=0;
    while(ind>0){
        ans+=tree[ind];
        ind-=(ind&(-ind));
    }
    return ans;
}
void update(int ind,int val){
    while(ind<=n){
        tree[ind]+=val;
        ind+=(ind&(-ind));
    }
}
bool f(pii a,pii b){
    return a.F+a.S<b.F+b.S;
}
ll funk(vector<pii>&vt){
    ll ans=0;
    sort(all(vt),f);
    for(int i=0;i<n/2;i++){
        ll x=vt[i].F+query(vt[i].F);
        ans+=abs(x-1);
        update(vt[i].F,-1);
        ll y=vt[i].S+query(vt[i].S);
        ans+=abs(y-1);
        update(vt[i].S,-1);
    }
    return ans;
}
long long count_swaps(vector<int> s) {
    n=s.size();
    map<int,queue<int>>mp;
	vector<pii>vt;
	for(int i=0;i<n;i++){
        if(mp[-s[i]].size()>0){
            int x=mp[-s[i]].front();
            mp[-s[i]].pop();
            if(s[i]<0){
                vt.pb({i+1,x});
            }
            else{
                vt.pb({x,i+1});
            }
        }
        else{
            mp[s[i]].push(i+1);
        }
	}
    ll ans=funk(vt);
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 4 ms 716 KB Output is correct
21 Correct 4 ms 804 KB Output is correct
22 Correct 48 ms 4260 KB Output is correct
23 Correct 34 ms 5528 KB Output is correct
24 Correct 36 ms 5560 KB Output is correct
25 Correct 32 ms 5756 KB Output is correct
26 Correct 36 ms 5588 KB Output is correct
27 Correct 37 ms 5412 KB Output is correct
28 Correct 36 ms 5912 KB Output is correct
29 Correct 39 ms 5980 KB Output is correct
30 Correct 34 ms 5908 KB Output is correct
31 Correct 34 ms 5524 KB Output is correct
32 Correct 36 ms 6048 KB Output is correct
33 Correct 35 ms 5788 KB Output is correct
34 Correct 38 ms 5908 KB Output is correct
35 Correct 0 ms 296 KB Output is correct
36 Correct 0 ms 280 KB Output is correct
37 Correct 33 ms 5920 KB Output is correct
38 Correct 32 ms 5956 KB Output is correct
39 Correct 33 ms 5920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 425 ms 148348 KB Output is correct
6 Correct 156 ms 18264 KB Output is correct
7 Correct 397 ms 149524 KB Output is correct
8 Correct 36 ms 5920 KB Output is correct
9 Correct 399 ms 149712 KB Output is correct
10 Correct 260 ms 77504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
38 Correct 0 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 588 KB Output is correct
41 Correct 3 ms 1732 KB Output is correct
42 Correct 2 ms 1740 KB Output is correct
43 Correct 2 ms 1484 KB Output is correct
44 Correct 2 ms 1356 KB Output is correct
45 Correct 2 ms 1228 KB Output is correct
46 Correct 2 ms 1100 KB Output is correct
47 Correct 2 ms 844 KB Output is correct
48 Correct 1 ms 716 KB Output is correct
49 Correct 1 ms 588 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 2 ms 1740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 0 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 0 ms 204 KB Output is correct
44 Correct 0 ms 204 KB Output is correct
45 Correct 0 ms 204 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 0 ms 204 KB Output is correct
50 Correct 0 ms 204 KB Output is correct
51 Correct 1 ms 204 KB Output is correct
52 Correct 1 ms 332 KB Output is correct
53 Correct 1 ms 332 KB Output is correct
54 Correct 4 ms 716 KB Output is correct
55 Correct 4 ms 804 KB Output is correct
56 Correct 48 ms 4260 KB Output is correct
57 Correct 34 ms 5528 KB Output is correct
58 Correct 36 ms 5560 KB Output is correct
59 Correct 32 ms 5756 KB Output is correct
60 Correct 36 ms 5588 KB Output is correct
61 Correct 37 ms 5412 KB Output is correct
62 Correct 36 ms 5912 KB Output is correct
63 Correct 39 ms 5980 KB Output is correct
64 Correct 34 ms 5908 KB Output is correct
65 Correct 34 ms 5524 KB Output is correct
66 Correct 36 ms 6048 KB Output is correct
67 Correct 35 ms 5788 KB Output is correct
68 Correct 38 ms 5908 KB Output is correct
69 Correct 0 ms 296 KB Output is correct
70 Correct 0 ms 280 KB Output is correct
71 Correct 33 ms 5920 KB Output is correct
72 Correct 32 ms 5956 KB Output is correct
73 Correct 33 ms 5920 KB Output is correct
74 Correct 1 ms 204 KB Output is correct
75 Correct 0 ms 204 KB Output is correct
76 Correct 0 ms 204 KB Output is correct
77 Correct 0 ms 204 KB Output is correct
78 Correct 425 ms 148348 KB Output is correct
79 Correct 156 ms 18264 KB Output is correct
80 Correct 397 ms 149524 KB Output is correct
81 Correct 36 ms 5920 KB Output is correct
82 Correct 399 ms 149712 KB Output is correct
83 Correct 260 ms 77504 KB Output is correct
84 Correct 0 ms 204 KB Output is correct
85 Correct 0 ms 332 KB Output is correct
86 Correct 1 ms 332 KB Output is correct
87 Correct 1 ms 588 KB Output is correct
88 Correct 3 ms 1732 KB Output is correct
89 Correct 2 ms 1740 KB Output is correct
90 Correct 2 ms 1484 KB Output is correct
91 Correct 2 ms 1356 KB Output is correct
92 Correct 2 ms 1228 KB Output is correct
93 Correct 2 ms 1100 KB Output is correct
94 Correct 2 ms 844 KB Output is correct
95 Correct 1 ms 716 KB Output is correct
96 Correct 1 ms 588 KB Output is correct
97 Correct 1 ms 332 KB Output is correct
98 Correct 1 ms 332 KB Output is correct
99 Correct 2 ms 1740 KB Output is correct
100 Correct 3 ms 1712 KB Output is correct
101 Correct 25 ms 13656 KB Output is correct
102 Correct 11 ms 3668 KB Output is correct
103 Correct 443 ms 149404 KB Output is correct
104 Correct 370 ms 149412 KB Output is correct
105 Correct 283 ms 87204 KB Output is correct
106 Correct 422 ms 149560 KB Output is correct
107 Correct 131 ms 21392 KB Output is correct
108 Correct 159 ms 37400 KB Output is correct
109 Correct 40 ms 5900 KB Output is correct
110 Correct 33 ms 5916 KB Output is correct
111 Correct 402 ms 133656 KB Output is correct
112 Correct 401 ms 117400 KB Output is correct
113 Correct 153 ms 23432 KB Output is correct
114 Correct 417 ms 149528 KB Output is correct
115 Correct 423 ms 149792 KB Output is correct