제출 #850458

#제출 시각아이디문제언어결과실행 시간메모리
850458serifefedartarEkoeko (COCI21_ekoeko)C++17
0 / 110
1068 ms600 KiB
#include <bits/stdc++.h> using namespace std; #define fast ios::sync_with_stdio(0);cin.tie(0); #define s second #define f first typedef long long ll; const ll MOD = 1e9 + 7; const ll LOGN = 20; const ll MAXN = 1e5 + 5; vector<int> occ[26]; int fen[MAXN], n; int query(int k) { int res = 0; while (k >= 1) { res += fen[k]; k -= (k&-k); } return res; } void update(int k, int val) { while (k <= n) { fen[k] += val; k += (k&-k); } } int main() { fast string s; cin >> n >> s; s = "#" + s; for (int i = 0; i < 26; i++) occ[i] = vector<int>(); for (int i = 1; i <= n; i++) occ[s[i]-'a'].push_back(i); for (int i = 0; i < 26; i++) reverse(occ[i].begin(), occ[i].end()); vector<int> v; for (int i = n+1; i <= 2*n; i++) { v.push_back(occ[s[i]-'a'].back()); occ[s[i]-'a'].pop_back(); } int ans = 0; int cnt = 0; for (auto u : v) { ans += cnt - query(u); update(u, 1); cnt++; } cout << ans << "\n"; }
#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...