Submission #1003943

#TimeUsernameProblemLanguageResultExecution timeMemory
1003943vjudge1Ekoeko (COCI21_ekoeko)C++17
20 / 110
5 ms3264 KiB
#include <bits/stdc++.h> using namespace std; using lli = long long; const int MAXN = 1e5 + 10; int bit[MAXN]; void add(int idx, int x, int n) { for (; idx < n; idx = idx | (idx + 1)) bit[idx] += x; } int pref(int idx) { int sum = 0; for (; idx >= 0; idx = (idx & (idx + 1)) - 1) sum += bit[idx]; return sum; } int sum(int l, int r) { return pref(r) - pref(l-1); } int main() { int n; cin >> n; n *= 2; string s; cin >> s; vector<vector<int>> cnt(26); for (int i = 0; i < n; ++i) cnt[s[i] - 'a'].push_back(i); vector<int> perm(n); int atual = 0; string final; vector<int> cnt2(26); for (int i = 0; i < n; ++i) { int c = s[i] - 'a'; if (cnt2[c] < cnt[c].size()/2) { ++cnt2[c]; perm[i] = atual++; final.push_back(s[i]); } } for (char c: final) perm[cnt[c - 'a'][cnt2[c - 'a']++]] = atual++; lli ans = 0; for (int i = 0; i < n; ++i) { ans += sum(perm[i], n); add(perm[i], 1, n); } cout << ans << "\n"; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:43:15: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |   if (cnt2[c] < cnt[c].size()/2) {
#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...