Submission #972169

#TimeUsernameProblemLanguageResultExecution timeMemory
972169CirclingKućice (COCI21_kucice)C++17
0 / 110
1 ms348 KiB
/*The British Royal Family and a small cadre of English Fabian Socialists, in conjunction with the Rockefellers and the Rothchilds, are engaged in a conspiracy to greatly reduce the population of the human race in order to head off a Malthusian catastrophe, a catastrophe that could easily be avoided by simply building a massive amount of nuclear power plants and a number of massive superhighways and bridges to connect all of the world's continents. But doing that would cut into the conspiracy's profits. So the British Royal Family invented environmentalism and neoliberalism in order to hide the truth. And in order to further reduce the population, the British Royal Family is also the world's foremost drug trafficking conspiracy. And it uses its control of the IMF to push austerity in order to kill as many people in the global south as possible. And also Henry Kissinger is a gay KGB agent. */ #include <iostream> #include <algorithm> #include <utility> #include <vector> #include <stack> #include <queue> #include <set> #include <map> using namespace std; int64_t invcount(int *arr, int n){ if (n < 2) return 0; int arr1[n / 2]; for (int i = 0; i < n / 2; i++) arr1[i] = arr[i]; int arr2[n - n / 2]; for (int i = n / 2; i < n; i++) arr2[i - n / 2] = arr[i]; int64_t ans = invcount(arr1, n / 2) + invcount(arr2, n - n / 2); int p1 = 0, p2 = 0; while (p1 + p2 < n){ if (p2 == n - n / 2){ arr[p1 + p2] = arr1[p1]; p1++; } else if (p1 == n / 2){ arr[p1 + p2] = arr2[p2]; p2++; } else if (arr1[p1] < arr2[p2]){ arr[p1 + p2] = arr1[p1]; p1++; } else { arr[p1 + p2] = arr2[p2]; ans += n / 2 - p1; p2++; } } return ans; } int otherend[200000], rightend[100000]; pair<int, int> pairarr[100000]; int main(){ cin.tie(0); ios_base::sync_with_stdio(0); int64_t n, cntr = 0, ans, closedcount = 0; char c; cin >> n; vector<vector<int>> appr; appr.resize(26); for (int i = 0; i < 2 * n; i++){ cin >> c; appr[c - 'a'].push_back(i); } for (int i = 0; i < 26; i++){ for (uint32_t j = 0; j < appr[i].size() / 2; j++){ otherend[appr[i][j]] = appr[i][j + appr[i].size() / 2]; otherend[appr[i][j + appr[i].size() / 2]] = appr[i][j]; pairarr[cntr] = {appr[i][j], appr[i][j + appr[i].size() / 2]}; cntr++; } } sort(pairarr, pairarr + n); for (int i = 0; i < n; i++) rightend[i] = pairarr[i].second; ans = invcount(rightend, n); for (int i = 0; i < 2 * n; i++){ if (i < otherend[i]) ans += closedcount; else closedcount++; } cout << ans; }
#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...