제출 #707577

#제출 시각아이디문제언어결과실행 시간메모리
707577Trisanu_DasEkoeko (COCI21_ekoeko)C++17
110 / 110
13 ms2728 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array const int mxN=1e5; int n, cnt[26], p[mxN], ft[mxN+1]; string s, a, b; ll ans; vector<int> oc1[26], oc2[26]; void upd(int i) { for (++i; i <= n; i += i & -i) ++ft[i]; } int qry(int i) { int ans = 0; for (++i; i > 0; i -= i & -i) ans += ft[i]; return ans; } int main() { cin >> n >> s; for (char c : s) ++cnt[c-'a']; for (int i=0; i<26; ++i) cnt[i] /= 2; for (int i = 0, x = 0; i < 2*n; ++i) { if (cnt[s[i]-'a']) a += s[i], ans += x, --cnt[s[i]-'a']; else b += s[i], ++x; } for (int i = 0; i < n; ++i) { oc1[a[i] - 'a'].push_back(i); oc2[b[i] - 'a'].push_back(i); } for (int i = 0; i < 26; ++i) for (int j=0; j<oc1[i].size(); ++j) p[oc2[i][j]] = oc1[i][j]; for (int i=0; i<n; ++i) { ans += i - qry(p[i]); upd(p[i]); } cout << ans << '\n'; return 0; }

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

Main.cpp: In function 'int main()':
Main.cpp:36:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |   for (int j=0; j<oc1[i].size(); ++j)
      |                 ~^~~~~~~~~~~~~~
#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...