Submission #155991

# Submission time Handle Problem Language Result Execution time Memory
155991 2019-10-02T14:03:27 Z GioChkhaidze Arranging Shoes (IOI19_shoes) C++14
100 / 100
159 ms 31500 KB
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
const int N=200005;
long long a[2*N],G[2*N],s[2*N],n;
vector < long long > f1[2*N],f2[2*N]; 
 
void Upd(long long x,long long dl) {
	while (x<=2*N) {
		G[x]+=dl;
		x+=(x & -x);
	}
}
 
long long Get(long long x) {
	long long res=0;
	while (0<x) {
		res+=G[x];
		x-=(x & -x);
	}
	return res;
}

long long count_swaps(std::vector<int> s) {
	long long ans=0;
    long long n=s.size();
  
	for (int i=0; i<n; i++) {
		a[i+1]=s[i];
		if (a[i+1]>0) f1[a[i+1]].push_back(i+1);
		if (a[i+1]<0) f2[-a[i+1]].push_back(i+1);
		Upd(i+1,1);
	}
	
	for (int i=0; i<n; i++)
		reverse(f1[i].begin(),f1[i].end()),
		reverse(f2[i].begin(),f2[i].end());
	
	for (int i=1; i<=n/2; i++) {
		long long l=1,r=n,mid,idx=-1;
		
		while (l<=r) {
			mid=(l+r)/2;
			if (1<=Get(mid)) { idx=mid; r=mid-1; } 
								   else l=mid+1;
		}

		if (a[idx]<0) {
			long long x=-a[idx];
			ans+=Get(f1[x].back()-1)-1;

			Upd(idx,-1);
			Upd(f1[x].back(),-1);
			f1[x].pop_back();
			f2[x].pop_back();
		}
			else {
			long long x=a[idx];
			ans+=Get(f2[x].back()-1);
			Upd(idx,-1);
			Upd(f2[x].back(),-1);
			f1[x].pop_back();
			f2[x].pop_back();
		}
	}

	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 19 ms 19192 KB Output is correct
2 Correct 18 ms 19192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 19192 KB Output is correct
2 Correct 18 ms 19192 KB Output is correct
3 Correct 19 ms 19192 KB Output is correct
4 Correct 19 ms 19192 KB Output is correct
5 Correct 19 ms 19196 KB Output is correct
6 Correct 20 ms 19196 KB Output is correct
7 Correct 19 ms 19192 KB Output is correct
8 Correct 18 ms 19204 KB Output is correct
9 Correct 19 ms 19192 KB Output is correct
10 Correct 20 ms 19192 KB Output is correct
11 Correct 19 ms 19192 KB Output is correct
12 Correct 19 ms 19192 KB Output is correct
13 Correct 19 ms 19192 KB Output is correct
14 Correct 19 ms 19192 KB Output is correct
15 Correct 19 ms 19192 KB Output is correct
16 Correct 19 ms 19192 KB Output is correct
17 Correct 19 ms 19192 KB Output is correct
18 Correct 19 ms 19192 KB Output is correct
19 Correct 20 ms 19192 KB Output is correct
20 Correct 20 ms 19192 KB Output is correct
21 Correct 23 ms 19192 KB Output is correct
22 Correct 20 ms 19192 KB Output is correct
23 Correct 19 ms 19192 KB Output is correct
24 Correct 20 ms 19192 KB Output is correct
25 Correct 19 ms 19192 KB Output is correct
26 Correct 20 ms 19192 KB Output is correct
27 Correct 20 ms 19192 KB Output is correct
28 Correct 20 ms 19192 KB Output is correct
29 Correct 19 ms 19192 KB Output is correct
30 Correct 19 ms 19192 KB Output is correct
31 Correct 20 ms 19196 KB Output is correct
32 Correct 19 ms 19192 KB Output is correct
33 Correct 19 ms 19196 KB Output is correct
34 Correct 20 ms 19140 KB Output is correct
35 Correct 20 ms 19192 KB Output is correct
36 Correct 19 ms 19212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 19192 KB Output is correct
2 Correct 18 ms 19192 KB Output is correct
3 Correct 37 ms 19180 KB Output is correct
4 Correct 19 ms 19208 KB Output is correct
5 Correct 20 ms 19196 KB Output is correct
6 Correct 19 ms 19192 KB Output is correct
7 Correct 19 ms 19192 KB Output is correct
8 Correct 19 ms 19192 KB Output is correct
9 Correct 19 ms 19192 KB Output is correct
10 Correct 18 ms 19192 KB Output is correct
11 Correct 19 ms 19192 KB Output is correct
12 Correct 19 ms 19192 KB Output is correct
13 Correct 19 ms 19192 KB Output is correct
14 Correct 20 ms 19192 KB Output is correct
15 Correct 19 ms 19192 KB Output is correct
16 Correct 19 ms 19192 KB Output is correct
17 Correct 19 ms 19192 KB Output is correct
18 Correct 19 ms 19192 KB Output is correct
19 Correct 20 ms 19192 KB Output is correct
20 Correct 26 ms 19960 KB Output is correct
21 Correct 25 ms 20032 KB Output is correct
22 Correct 86 ms 27032 KB Output is correct
23 Correct 80 ms 26968 KB Output is correct
24 Correct 86 ms 26860 KB Output is correct
25 Correct 80 ms 26704 KB Output is correct
26 Correct 86 ms 26852 KB Output is correct
27 Correct 80 ms 26724 KB Output is correct
28 Correct 82 ms 26988 KB Output is correct
29 Correct 82 ms 26860 KB Output is correct
30 Correct 82 ms 26860 KB Output is correct
31 Correct 86 ms 26848 KB Output is correct
32 Correct 82 ms 26860 KB Output is correct
33 Correct 81 ms 26732 KB Output is correct
34 Correct 82 ms 27016 KB Output is correct
35 Correct 19 ms 19192 KB Output is correct
36 Correct 20 ms 19192 KB Output is correct
37 Correct 81 ms 26860 KB Output is correct
38 Correct 83 ms 26864 KB Output is correct
39 Correct 82 ms 26988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 19192 KB Output is correct
2 Correct 20 ms 19192 KB Output is correct
3 Correct 20 ms 19164 KB Output is correct
4 Correct 20 ms 19192 KB Output is correct
5 Correct 146 ms 31500 KB Output is correct
6 Correct 120 ms 27644 KB Output is correct
7 Correct 152 ms 31344 KB Output is correct
8 Correct 87 ms 27292 KB Output is correct
9 Correct 124 ms 31356 KB Output is correct
10 Correct 159 ms 28792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 19192 KB Output is correct
2 Correct 18 ms 19192 KB Output is correct
3 Correct 19 ms 19192 KB Output is correct
4 Correct 19 ms 19192 KB Output is correct
5 Correct 19 ms 19196 KB Output is correct
6 Correct 20 ms 19196 KB Output is correct
7 Correct 19 ms 19192 KB Output is correct
8 Correct 18 ms 19204 KB Output is correct
9 Correct 19 ms 19192 KB Output is correct
10 Correct 20 ms 19192 KB Output is correct
11 Correct 19 ms 19192 KB Output is correct
12 Correct 19 ms 19192 KB Output is correct
13 Correct 19 ms 19192 KB Output is correct
14 Correct 19 ms 19192 KB Output is correct
15 Correct 19 ms 19192 KB Output is correct
16 Correct 19 ms 19192 KB Output is correct
17 Correct 19 ms 19192 KB Output is correct
18 Correct 19 ms 19192 KB Output is correct
19 Correct 20 ms 19192 KB Output is correct
20 Correct 20 ms 19192 KB Output is correct
21 Correct 23 ms 19192 KB Output is correct
22 Correct 20 ms 19192 KB Output is correct
23 Correct 19 ms 19192 KB Output is correct
24 Correct 20 ms 19192 KB Output is correct
25 Correct 19 ms 19192 KB Output is correct
26 Correct 20 ms 19192 KB Output is correct
27 Correct 20 ms 19192 KB Output is correct
28 Correct 20 ms 19192 KB Output is correct
29 Correct 19 ms 19192 KB Output is correct
30 Correct 19 ms 19192 KB Output is correct
31 Correct 20 ms 19196 KB Output is correct
32 Correct 19 ms 19192 KB Output is correct
33 Correct 19 ms 19196 KB Output is correct
34 Correct 20 ms 19140 KB Output is correct
35 Correct 20 ms 19192 KB Output is correct
36 Correct 19 ms 19212 KB Output is correct
37 Correct 24 ms 19192 KB Output is correct
38 Correct 19 ms 19192 KB Output is correct
39 Correct 20 ms 19192 KB Output is correct
40 Correct 19 ms 19192 KB Output is correct
41 Correct 20 ms 19320 KB Output is correct
42 Correct 26 ms 19320 KB Output is correct
43 Correct 20 ms 19192 KB Output is correct
44 Correct 35 ms 19320 KB Output is correct
45 Correct 21 ms 19320 KB Output is correct
46 Correct 23 ms 19224 KB Output is correct
47 Correct 24 ms 19192 KB Output is correct
48 Correct 20 ms 19192 KB Output is correct
49 Correct 20 ms 19192 KB Output is correct
50 Correct 21 ms 19192 KB Output is correct
51 Correct 22 ms 19192 KB Output is correct
52 Correct 26 ms 19320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 19192 KB Output is correct
2 Correct 18 ms 19192 KB Output is correct
3 Correct 19 ms 19192 KB Output is correct
4 Correct 19 ms 19192 KB Output is correct
5 Correct 19 ms 19196 KB Output is correct
6 Correct 20 ms 19196 KB Output is correct
7 Correct 19 ms 19192 KB Output is correct
8 Correct 18 ms 19204 KB Output is correct
9 Correct 19 ms 19192 KB Output is correct
10 Correct 20 ms 19192 KB Output is correct
11 Correct 19 ms 19192 KB Output is correct
12 Correct 19 ms 19192 KB Output is correct
13 Correct 19 ms 19192 KB Output is correct
14 Correct 19 ms 19192 KB Output is correct
15 Correct 19 ms 19192 KB Output is correct
16 Correct 19 ms 19192 KB Output is correct
17 Correct 19 ms 19192 KB Output is correct
18 Correct 19 ms 19192 KB Output is correct
19 Correct 20 ms 19192 KB Output is correct
20 Correct 20 ms 19192 KB Output is correct
21 Correct 23 ms 19192 KB Output is correct
22 Correct 20 ms 19192 KB Output is correct
23 Correct 19 ms 19192 KB Output is correct
24 Correct 20 ms 19192 KB Output is correct
25 Correct 19 ms 19192 KB Output is correct
26 Correct 20 ms 19192 KB Output is correct
27 Correct 20 ms 19192 KB Output is correct
28 Correct 20 ms 19192 KB Output is correct
29 Correct 19 ms 19192 KB Output is correct
30 Correct 19 ms 19192 KB Output is correct
31 Correct 20 ms 19196 KB Output is correct
32 Correct 19 ms 19192 KB Output is correct
33 Correct 19 ms 19196 KB Output is correct
34 Correct 20 ms 19140 KB Output is correct
35 Correct 20 ms 19192 KB Output is correct
36 Correct 19 ms 19212 KB Output is correct
37 Correct 37 ms 19180 KB Output is correct
38 Correct 19 ms 19208 KB Output is correct
39 Correct 20 ms 19196 KB Output is correct
40 Correct 19 ms 19192 KB Output is correct
41 Correct 19 ms 19192 KB Output is correct
42 Correct 19 ms 19192 KB Output is correct
43 Correct 19 ms 19192 KB Output is correct
44 Correct 18 ms 19192 KB Output is correct
45 Correct 19 ms 19192 KB Output is correct
46 Correct 19 ms 19192 KB Output is correct
47 Correct 19 ms 19192 KB Output is correct
48 Correct 20 ms 19192 KB Output is correct
49 Correct 19 ms 19192 KB Output is correct
50 Correct 19 ms 19192 KB Output is correct
51 Correct 19 ms 19192 KB Output is correct
52 Correct 19 ms 19192 KB Output is correct
53 Correct 20 ms 19192 KB Output is correct
54 Correct 26 ms 19960 KB Output is correct
55 Correct 25 ms 20032 KB Output is correct
56 Correct 86 ms 27032 KB Output is correct
57 Correct 80 ms 26968 KB Output is correct
58 Correct 86 ms 26860 KB Output is correct
59 Correct 80 ms 26704 KB Output is correct
60 Correct 86 ms 26852 KB Output is correct
61 Correct 80 ms 26724 KB Output is correct
62 Correct 82 ms 26988 KB Output is correct
63 Correct 82 ms 26860 KB Output is correct
64 Correct 82 ms 26860 KB Output is correct
65 Correct 86 ms 26848 KB Output is correct
66 Correct 82 ms 26860 KB Output is correct
67 Correct 81 ms 26732 KB Output is correct
68 Correct 82 ms 27016 KB Output is correct
69 Correct 19 ms 19192 KB Output is correct
70 Correct 20 ms 19192 KB Output is correct
71 Correct 81 ms 26860 KB Output is correct
72 Correct 83 ms 26864 KB Output is correct
73 Correct 82 ms 26988 KB Output is correct
74 Correct 19 ms 19192 KB Output is correct
75 Correct 20 ms 19192 KB Output is correct
76 Correct 20 ms 19164 KB Output is correct
77 Correct 20 ms 19192 KB Output is correct
78 Correct 146 ms 31500 KB Output is correct
79 Correct 120 ms 27644 KB Output is correct
80 Correct 152 ms 31344 KB Output is correct
81 Correct 87 ms 27292 KB Output is correct
82 Correct 124 ms 31356 KB Output is correct
83 Correct 159 ms 28792 KB Output is correct
84 Correct 24 ms 19192 KB Output is correct
85 Correct 19 ms 19192 KB Output is correct
86 Correct 20 ms 19192 KB Output is correct
87 Correct 19 ms 19192 KB Output is correct
88 Correct 20 ms 19320 KB Output is correct
89 Correct 26 ms 19320 KB Output is correct
90 Correct 20 ms 19192 KB Output is correct
91 Correct 35 ms 19320 KB Output is correct
92 Correct 21 ms 19320 KB Output is correct
93 Correct 23 ms 19224 KB Output is correct
94 Correct 24 ms 19192 KB Output is correct
95 Correct 20 ms 19192 KB Output is correct
96 Correct 20 ms 19192 KB Output is correct
97 Correct 21 ms 19192 KB Output is correct
98 Correct 22 ms 19192 KB Output is correct
99 Correct 26 ms 19320 KB Output is correct
100 Correct 20 ms 19320 KB Output is correct
101 Correct 29 ms 20216 KB Output is correct
102 Correct 29 ms 20060 KB Output is correct
103 Correct 153 ms 31352 KB Output is correct
104 Correct 127 ms 31480 KB Output is correct
105 Correct 147 ms 29088 KB Output is correct
106 Correct 123 ms 31468 KB Output is correct
107 Correct 112 ms 27768 KB Output is correct
108 Correct 126 ms 28120 KB Output is correct
109 Correct 82 ms 27628 KB Output is correct
110 Correct 81 ms 26988 KB Output is correct
111 Correct 126 ms 30692 KB Output is correct
112 Correct 148 ms 30072 KB Output is correct
113 Correct 114 ms 27768 KB Output is correct
114 Correct 124 ms 31352 KB Output is correct
115 Correct 123 ms 31352 KB Output is correct