Submission #1072034

#TimeUsernameProblemLanguageResultExecution timeMemory
1072034PikachudoraEHEArranging Shoes (IOI19_shoes)C++14
10 / 100
81 ms136284 KiB
#include "shoes.h" #include<bits/stdc++.h> #define ll long long using namespace std; const int N = 2e5+5; const int OFFSET = 1e5; int n; int a[N],chk[N]; queue<int>q[N]; struct fenwick{ int f[N]; void update(int idx,int v){ for(int i=idx;i<N;i+=i&-i){ f[i]+=v; } return; } int sum(int idx){ int s=0; for(int i=idx;i>0;i-=i&-i){ s+=f[i]; } return s; } }f,f2; long long count_swaps(std::vector<int> s){ for(int i=1;i<=s.size();i++){a[i]=s[i-1];f.update(i,1);} ll ans=0;ll n = s.size(); for(int i=1;i<=n;i++){ if(a[i]<0){ q[OFFSET-a[i]].push(i); } else{ q[a[i]].push(i); } } for(int i=1;i<=n;i++){ if(chk[i])continue; if(a[i]<0){ int ii = q[(-1)*a[i]].front(); q[(-1)*a[i]].pop(); chk[ii]=1; ans+=f.sum(ii)-f.sum(i)-1; } else{ int ii = q[OFFSET+a[i]].front(); q[OFFSET+a[i]].pop(); chk[ii]=1; ans+=f.sum(ii)-f.sum(i); } } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:27:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int i=1;i<=s.size();i++){a[i]=s[i-1];f.update(i,1);}
      |                 ~^~~~~~~~~~
#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...