Submission #557394

#TimeUsernameProblemLanguageResultExecution timeMemory
557394new_accEkoeko (COCI21_ekoeko)C++14
110 / 110
46 ms27360 KiB
#include<bits/stdc++.h> #define fi first #define se second #define pitem item* using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vl; const int N=1e6+10; const int SS=1<<19; const int INFi=2e9; const ll INFl=1e13; const ll mod2=998244353; const ll mod=1e9+7; const ll mod3=1000696969; const ll p=70032301; const ull p2=913; const int L=20; int t[N],seg[(SS<<1)+10],wsk[N],il[N],pom[N]; vi g[N]; void upd(int a,int b){ for(a+=SS;a>0;a>>=1) seg[a]+=b; } int Query(int a,int b){ int res=0; for(a+=SS-1,b+=SS+1;(a>>1)!=(b>>1);a>>=1,b>>=1){ if(!(a&1)) res+=seg[a+1]; if(b&1) res+=seg[b-1]; } return res; } ll cnt(string a,string b){ a="#"+a,b="#"+b; for(int i=1;i<a.size();i++){ int curr=int(a[i])-96; g[curr].push_back(i); } ll res=0; for(int i=1;i<b.size();i++){ int curr=int(b[i])-96; int currl=g[curr][wsk[curr]++]; res+=(ll)Query(currl,a.size()); upd(currl,1); } return res; } void solve(){ int n; string s; cin>>n>>s; for(int i=0;i<s.size();i++) il[int(s[i])-96]++; string res; for(int i=0;i<s.size();i++){ pom[int(s[i])-96]++; if(pom[int(s[i])-96]<=(il[int(s[i])-96]>>1)) res+=s[i]; } res=res+res; cout<<cnt(s,res)<<"\n"; } int main(){ ios_base::sync_with_stdio(0),cin.tie(0); int tt=1; while(tt--) solve(); }

Compilation message (stderr)

Main.cpp: In function 'll cnt(std::string, std::string)':
Main.cpp:35:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for(int i=1;i<a.size();i++){
      |                 ~^~~~~~~~~
Main.cpp:40:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i=1;i<b.size();i++){
      |                 ~^~~~~~~~~
Main.cpp: In function 'void solve()':
Main.cpp:52:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for(int i=0;i<s.size();i++) il[int(s[i])-96]++;
      |                 ~^~~~~~~~~
Main.cpp:54:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for(int i=0;i<s.size();i++){
      |                 ~^~~~~~~~~
#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...