Submission #718869

#TimeUsernameProblemLanguageResultExecution timeMemory
718869Yell0Arranging Shoes (IOI19_shoes)C++17
100 / 100
79 ms20656 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MN=2e5+2; ll bit[MN]; void upd(int i,ll v) { for(;i<MN;i+=-i&i) bit[i]+=v; } ll qry(int i) { ll ret=0; for(;i>0;i-=-i&i) ret+=bit[i]; return ret; } ll count_swaps(vector<int> S) { int N=S.size()/2; ll ans=0,sub=0; vector<int> sti(N*2+2,0),edi(N*2+2,0); S.insert(S.begin(),0); vector<vector<int>> pos(2*MN); for(int i=1;i<=2*N;++i) pos[S[i]+N].push_back(i); for(int i=0;i<N;++i) for(int j=0;j<pos[i].size();++j) { ans+=(pos[N+N-i][j]<pos[i][j]); int f=min(pos[N+N-i][j],pos[i][j]),s=max(pos[N+N-i][j],pos[i][j]); sti[s]=f; edi[f]=s; } for(int i=1;i<=2*N;++i) { if(sti[i]) { upd(sti[i],-2); if(sti[i]==i-1) { upd(sti[i],1); continue; } ans+=i-sti[i]-1; sub+=qry(i)-qry(sti[i]); upd(i,1); } else upd(i,1); } return ans-sub/2; }

Compilation message (stderr)

shoes.cpp: In function 'll count_swaps(std::vector<int>)':
shoes.cpp:25:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for(int j=0;j<pos[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...
#Verdict Execution timeMemoryGrader output
Fetching results...