Submission #815750

#TimeUsernameProblemLanguageResultExecution timeMemory
815750exodus_Ekoeko (COCI21_ekoeko)C++14
20 / 110
48 ms4616 KiB
#include<bits/stdc++.h> using namespace std; const int N = 2e5+1; int segtree[4*N] = {0}; int freq[30]; vector<char>urt; deque<int>dex[30]; vector<int>isi; void update(int idx, int low, int high, int val) { if(high==low && low==val) { segtree[idx]=1; return; } if(val<low || val>high) return; int mid=(low+high)/2; update(2*idx,low,mid,val); update(2*idx+1,mid+1,high,val); segtree[idx] = segtree[2*idx]+segtree[2*idx+1]; } int quer(int idx, int low, int high, int l, int r) { if(low>=l && high<=r) { return segtree[idx]; } if(low>r || high<l) return 0; int mid = (low+high)/2; int left = quer(2*idx,low,mid,l,r); int right = quer(2*idx+1,mid+1,high,l,r); return left+right; } int main() { int n; cin >> n; n*=2; string asli; cin >> asli; for(int i=0; i<n; i++) { freq[asli[i]-97]++; } for(int i=0; i<n; i++) { if(freq[asli[i]-97]>0) { urt.push_back(asli[i]); freq[asli[i]-97]-=2; } } int sizeurt=urt.size(); for(int i=0; i<sizeurt; i++) { urt.push_back(urt[i]); } for(int i=0; i<n; i++) { dex[urt[i]-97].push_back(i); } for(int i=0; i<n; i++) { isi.push_back(dex[asli[i]-97].front()); dex[asli[i]-97].pop_front(); } int jwbn=0; for(int i=0; i<n; i++) { jwbn+=quer(1,0,n-1,isi[i]+1,n-1); update(1,0,n-1,isi[i]); } cout << jwbn << endl; return 0; }
#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...