Submission #1119383

#TimeUsernameProblemLanguageResultExecution timeMemory
1119383ezzzayEkoeko (COCI21_ekoeko)C++14
0 / 110
1083 ms286148 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define ff first #define ss second #define pb push_back const int N=3e6+5; vector<int>a[N],b[N]; int p[N]; int bit[N]; int find(int idx){ int s=0; while(idx>0){ s+=bit[idx]; idx-= idx & -idx; } return s; } void update(int idx, int val){ while(idx<N){ bit[idx]+=val; idx+= idx & -idx; } } signed main(){ int n; cin>>n; string s; cin>>s; for(int i=0;i<2*n;i++){ if(i<n)a[s[i]-'0'].pb(i); else b[s[i]-'0'].pb(i); } for(int i=n-1;i>=0;i--){ p[ b[s[i]-'0'].back() - n +1 ] =i+1; b[s[i]-'0'].pop_back(); } int ans=0; for(int i=1;i<=n;i++){ update(p[i],1); ans+=i-find(p[i]); } 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...