Submission #798064

#TimeUsernameProblemLanguageResultExecution timeMemory
798064MularstyleArranging Shoes (IOI19_shoes)C++14
0 / 100
1 ms440 KiB
#include<bits/stdc++.h> using namespace std; #include "shoes.h" #define ll long long int n; ll ar[200005]; bool vis[200005]; void up(int idx,int x) { while(idx<=n)ar[idx]+=x,idx+=(idx&-idx); } int re(int idx) { ll sum=0; while(idx>0)sum+=ar[idx],idx-=(idx&-idx); return sum; } long long count_swaps(std::vector<int> os) { ll ans=0; n=os.size(); int s[n+5]; for(int i=1;i<=n;i++) s[i]=os[i-1]; vector<int> S[n]; int pidx[n+5]; for(int i=1;i<=n;i++) { up(i,1); S[abs(s[i])].push_back(i); } for(int i=1;i<=n;i++) { if(S[i].empty())continue; for(int a=0;a<S[i].size();a++) { if(s[S[i][a]]>=0)continue; for(int b=0;b<S[i].size();b++) { if(s[S[i][b]]<=0)continue; pidx[S[i][a]]=S[i][b]; pidx[S[i][b]]=S[i][a]; S[i][a]=0; S[i][b]=0; break; } } } for(int i=1;i<=n;i++) { if(vis[pidx[i]])continue; vis[i]=1; // ans+=re(pidx[i]); ans+=( ( re(pidx[i])-re(i-1) ) -2 ); if(s[i]>0)//rightonleft ans++; up(i,-1); up(pidx[i],-1); } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:42:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         for(int a=0;a<S[i].size();a++)
      |                     ~^~~~~~~~~~~~
shoes.cpp:45:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |             for(int b=0;b<S[i].size();b++)
      |                         ~^~~~~~~~~~~~
#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...