Submission #827599

# Submission time Handle Problem Language Result Execution time Memory
827599 2023-08-16T15:15:42 Z jlallas384 Arranging Shoes (IOI19_shoes) C++17
100 / 100
489 ms 149596 KB
#include <bits/stdc++.h>
using namespace std;
struct FT{
	vector<int> ft;
	int n;
	FT(int n): ft(n + 1), n(n){}
	void upd(int i){
		for(; i <= n; i += i & -i){
			ft[i]++;
		}
	}
	int qry(int i){
		int res = 0;
		for(; i > 0; i -= i & -i){
			res += ft[i];
		}
		return res;
	}
	int inv(int i){
		return qry(n) - qry(i);
	}
};

long long count_swaps(std::vector<int> a){
	int n = a.size();
	map<int, queue<int>> mp;
	for(int i = 0; i < n; i++){
		mp[a[i]].push(i);
	}
	vector<int> idx(n, -1);
	int cur = 1;
	for(int i = 0; i < n; i++){
		if(idx[i] == -1){
			if(a[i] < 0){
				idx[i] = cur++;
				idx[mp[a[i] * -1].front()] = cur++;
			}else{
				idx[mp[a[i] * -1].front()] = cur++;	
				idx[i] = cur++;			
			}
			mp[a[i] * -1].pop(); 
			mp[a[i]].pop();
		}
	}
	FT ft(2 * n);
	long long ans = 0;
	for(int i = 0; i < n; i++){
		ans += ft.inv(idx[i]);
		ft.upd(idx[i]);
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 296 KB Output is correct
6 Correct 0 ms 300 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 296 KB Output is correct
20 Correct 1 ms 304 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 300 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 308 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 304 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 0 ms 300 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 3 ms 852 KB Output is correct
21 Correct 3 ms 852 KB Output is correct
22 Correct 27 ms 6316 KB Output is correct
23 Correct 27 ms 6308 KB Output is correct
24 Correct 29 ms 6204 KB Output is correct
25 Correct 28 ms 6108 KB Output is correct
26 Correct 29 ms 6228 KB Output is correct
27 Correct 26 ms 6072 KB Output is correct
28 Correct 27 ms 6304 KB Output is correct
29 Correct 26 ms 6320 KB Output is correct
30 Correct 26 ms 6188 KB Output is correct
31 Correct 33 ms 6220 KB Output is correct
32 Correct 26 ms 6228 KB Output is correct
33 Correct 25 ms 6068 KB Output is correct
34 Correct 26 ms 6324 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 300 KB Output is correct
37 Correct 24 ms 6324 KB Output is correct
38 Correct 25 ms 6204 KB Output is correct
39 Correct 28 ms 6320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 418 ms 149424 KB Output is correct
6 Correct 104 ms 17996 KB Output is correct
7 Correct 419 ms 149460 KB Output is correct
8 Correct 27 ms 6228 KB Output is correct
9 Correct 424 ms 149596 KB Output is correct
10 Correct 265 ms 77444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 296 KB Output is correct
6 Correct 0 ms 300 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 296 KB Output is correct
20 Correct 1 ms 304 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 300 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 308 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 304 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 0 ms 296 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 596 KB Output is correct
41 Correct 2 ms 1748 KB Output is correct
42 Correct 2 ms 1748 KB Output is correct
43 Correct 2 ms 1492 KB Output is correct
44 Correct 2 ms 1364 KB Output is correct
45 Correct 1 ms 1236 KB Output is correct
46 Correct 1 ms 1108 KB Output is correct
47 Correct 1 ms 852 KB Output is correct
48 Correct 1 ms 724 KB Output is correct
49 Correct 1 ms 596 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 2 ms 1748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 296 KB Output is correct
6 Correct 0 ms 300 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 296 KB Output is correct
20 Correct 1 ms 304 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 300 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 308 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 304 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 300 KB Output is correct
47 Correct 0 ms 300 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 3 ms 852 KB Output is correct
55 Correct 3 ms 852 KB Output is correct
56 Correct 27 ms 6316 KB Output is correct
57 Correct 27 ms 6308 KB Output is correct
58 Correct 29 ms 6204 KB Output is correct
59 Correct 28 ms 6108 KB Output is correct
60 Correct 29 ms 6228 KB Output is correct
61 Correct 26 ms 6072 KB Output is correct
62 Correct 27 ms 6304 KB Output is correct
63 Correct 26 ms 6320 KB Output is correct
64 Correct 26 ms 6188 KB Output is correct
65 Correct 33 ms 6220 KB Output is correct
66 Correct 26 ms 6228 KB Output is correct
67 Correct 25 ms 6068 KB Output is correct
68 Correct 26 ms 6324 KB Output is correct
69 Correct 1 ms 212 KB Output is correct
70 Correct 1 ms 300 KB Output is correct
71 Correct 24 ms 6324 KB Output is correct
72 Correct 25 ms 6204 KB Output is correct
73 Correct 28 ms 6320 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 0 ms 212 KB Output is correct
76 Correct 0 ms 212 KB Output is correct
77 Correct 0 ms 212 KB Output is correct
78 Correct 418 ms 149424 KB Output is correct
79 Correct 104 ms 17996 KB Output is correct
80 Correct 419 ms 149460 KB Output is correct
81 Correct 27 ms 6228 KB Output is correct
82 Correct 424 ms 149596 KB Output is correct
83 Correct 265 ms 77444 KB Output is correct
84 Correct 0 ms 296 KB Output is correct
85 Correct 0 ms 340 KB Output is correct
86 Correct 1 ms 340 KB Output is correct
87 Correct 1 ms 596 KB Output is correct
88 Correct 2 ms 1748 KB Output is correct
89 Correct 2 ms 1748 KB Output is correct
90 Correct 2 ms 1492 KB Output is correct
91 Correct 2 ms 1364 KB Output is correct
92 Correct 1 ms 1236 KB Output is correct
93 Correct 1 ms 1108 KB Output is correct
94 Correct 1 ms 852 KB Output is correct
95 Correct 1 ms 724 KB Output is correct
96 Correct 1 ms 596 KB Output is correct
97 Correct 1 ms 340 KB Output is correct
98 Correct 1 ms 340 KB Output is correct
99 Correct 2 ms 1748 KB Output is correct
100 Correct 2 ms 1756 KB Output is correct
101 Correct 21 ms 13680 KB Output is correct
102 Correct 9 ms 3668 KB Output is correct
103 Correct 489 ms 149452 KB Output is correct
104 Correct 436 ms 149452 KB Output is correct
105 Correct 379 ms 87236 KB Output is correct
106 Correct 412 ms 149380 KB Output is correct
107 Correct 124 ms 21424 KB Output is correct
108 Correct 187 ms 37344 KB Output is correct
109 Correct 27 ms 6316 KB Output is correct
110 Correct 36 ms 6324 KB Output is correct
111 Correct 366 ms 133368 KB Output is correct
112 Correct 447 ms 117452 KB Output is correct
113 Correct 116 ms 23212 KB Output is correct
114 Correct 455 ms 149392 KB Output is correct
115 Correct 445 ms 149460 KB Output is correct