제출 #420678

#제출 시각아이디문제언어결과실행 시간메모리
420678SSRSArranging Shoes (IOI19_shoes)C++14
70 / 100
1074 ms65248 KiB
#include <bits/stdc++.h> using namespace std; const int INF = 1000000; struct binary_indexed_tree{ int N; vector<int> BIT; binary_indexed_tree(int N): N(N), BIT(N + 1, 0){ } void add(int i, int x){ i++; while (i <= N){ BIT[i] += x; i += i & -i; } } int sum(int i){ int ans = 0; while (i > 0){ ans += BIT[i]; i -= i & -i; } return ans; } int sum(int L, int R){ return sum(R) - sum(L); } }; bool compare(vector<int> &a, vector<int> &b, int x, int y){ if (a[x] < a[y] && a[y] < b[x] && b[x] < b[y]){ return true; } if (a[y] < a[x] && a[x] < b[y] && b[y] < b[x]){ return false; } if (b[x] < a[y]){ return true; } if (b[y] < a[x]){ return false; } return x < y; } void merge_sort(vector<int> &A, vector<int> &a, vector<int> &b, int l, int r){ if (r - l == 1){ return; } int m = (l + r) / 2; merge_sort(A, a, b, l, m); merge_sort(A, a, b, m, r); vector<int> ans; int p1 = l, p2 = m; while (!(p1 == m && p2 == r)){ if (p1 == m){ ans.push_back(A[p2]); p2++; } else if (p2 == r){ ans.push_back(A[p1]); p1++; } else if (compare(a, b, A[p1], A[p2])){ ans.push_back(A[p1]); p1++; } else { ans.push_back(A[p2]); p2++; } } for (int i = 0; i < r - l; i++){ A[l + i] = ans[i]; } } long long count_swaps(vector<int> S){ int n = S.size() / 2; vector<int> a, b, x; map<int, vector<int>> mp1; map<int, int> mp2; for (int i = 0; i < n * 2; i++){ if (mp1[-S[i]].size() == mp2[-S[i]]){ mp1[S[i]].push_back(i); } else { a.push_back(mp1[-S[i]][mp2[-S[i]]]); b.push_back(i); x.push_back(abs(S[i])); mp2[-S[i]]++; } } vector<int> A(n); for (int i = 0; i < n; i++){ A[i] = i; } merge_sort(A, a, b, 0, n); vector<int> S2; for (int i = 0; i < n; i++){ S2.push_back(-x[A[i]]); S2.push_back(x[A[i]]); } map<int, vector<int>> mp3; for (int i = 0; i < n * 2; i++){ mp3[S2[i]].push_back(i); } map<int, int> mp4; vector<int> p; for (int i = 0; i < n * 2; i++){ p.push_back(mp3[S[i]][mp4[S[i]]]); mp4[S[i]]++; } long long ans = 0; binary_indexed_tree BIT(n * 2); for (int i = 0; i < n * 2; i++){ ans += BIT.sum(p[i] + 1, n * 2); BIT.add(p[i], 1); } return ans; }

컴파일 시 표준 에러 (stderr) 메시지

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:77:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'std::map<int, int>::mapped_type' {aka 'int'} [-Wsign-compare]
   77 |     if (mp1[-S[i]].size() == mp2[-S[i]]){
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...