Submission #157627

# Submission time Handle Problem Language Result Execution time Memory
157627 2019-10-12T15:49:21 Z keta_tsimakuridze Arranging Shoes (IOI19_shoes) C++14
Compilation error
0 ms 0 KB
#include <iostream>
#include <cstdio>
#include <queue>
#include <vector>
using namespace std;
 
long long noneg,k,b[1000005],curindex,cursum,n,a[1000005];
 
queue<long long>q[500005];
vector<long long>s;
 
void update(int ind,int value) { 
 for(int i=ind; i<=n; i+=i&(-i))
   b[i]+=value;
}
 
int curs(int ind1) {
 cursum=0;
 for(int i=ind1; i>=1; i-=i&(-i))
  cursum+=b[i];
  
 return  cursum;
}
 
long long count_swaps(std:: vector<int>s) { 
 noneg=100005; n=s.size();
 
 for(k=0; k<s.size(); k++) a[k+1]=s[k]; 
 
 for(k=1;k<=n;k++)  update(k,1);
 
 for(k=1; k<=n; k++) 
  if(q[a[k]+noneg].size()>0) {
   curindex=q[a[k]+noneg].front();
   q[a[k]+noneg].pop();
   ans+=curs(k)-curs(curindex)-1;
   
   if(a[k]<0) ans++;
   
   update(k,-1);   
   update(curindex,1);
   
  } else q[a[k]*(-1)+noneg].push(k);
 
 
 return ans;
}

Compilation message

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:28:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(k=0; k<s.size(); k++) a[k+1]=s[k]; 
           ~^~~~~~~~~
shoes.cpp:36:4: error: 'ans' was not declared in this scope
    ans+=curs(k)-curs(curindex)-1;
    ^~~
shoes.cpp:36:4: note: suggested alternative: 'abs'
    ans+=curs(k)-curs(curindex)-1;
    ^~~
    abs
shoes.cpp:46:9: error: 'ans' was not declared in this scope
  return ans;
         ^~~
shoes.cpp:46:9: note: suggested alternative: 'abs'
  return ans;
         ^~~
         abs