Submission #1110785

# Submission time Handle Problem Language Result Execution time Memory
1110785 2024-11-10T13:27:20 Z epicci23 Arranging Shoes (IOI19_shoes) C++17
Compilation error
0 ms 0 KB
#include "bits/stdc++.h"
using namespace std;
//#define int long long
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)x.size()
 
struct Fenwick{
  vector<int64_t> fw;
  int N;
  Fenwick(int64_t _n){
  	N = _n + 15;
  	fw.assign(N,0);
  }
  void upd(int64_t c){
    for(;c<N;c+=c&-c) fw[c]++;
  }
  int64_t query(int64_t c,int64_t res=0){
  	for(;c;c-=c&-c) res+=fw[c];
  	return res;
  }
};
 
int64_t count_swaps(vector<int> S){
  int64_t n , ans = 0; 
  n = sz(S) / 2;
  int64_t ar[2 * n + 5];
  for(int i=1;i<=2*n;i++) ar[i] = S[i - 1];
 
  if(n<=8){

  	vector<int64_t> xd;
  	for(int i=1;i<=2*n;i++) if(ar[i]<0) xd.push_back(ar[i]);
    sort(all(xd));
    int64_t res = (int)1e9;

    do{

      int hm = 0, p = 1;
      queue<int64_t> q1[n+5];
      queue<int64_t> q2[n+5];

      for(int i=1;i<=2*n;i++){
      	if(ar[i]<0) q1[-ar[i]].push(i);
      	else q2[ar[i]].push(i);
      }

      Fenwick F(2*n);
      for(int u:xd){
       int64_t c = q1[u].front();
  	   q1[u].pop();
  	   int64_t x = q2[u].front();
  	   q1[u].pop();

  	   F.upd(c);
       c+=F.query(2*n)-F.query(c);
       hm+=c-p;
       p++;

       F.upd(x);
       x+=F.query(2*n)-F.query(x);
       hm+=x-p;
       p++;
      }
      res=min(res,hm);
    }while(all(xd));

    return res;
  }

  /*int p = 1;
  while(!q.empty()){
  	int64_t c = q.front();
  	q.pop();
  	int64_t x = pos[-ar[c]].back();
  	pos[-ar[c]].pop_back();

  	F.upd(c);
    c+=F.query(2*n)-F.query(c);
    ans+=c-p;
    p++;

    F.upd(x);
    x+=F.query(2*n)-F.query(x);
    ans+=x-p;
    p++;
  }
 
  return ans;*/
}
 
 
/*void _(){
  int n,ans=0; cin >> n;
  int ar[2*n+5];
  for(int i=1;i<=2*n;i++) cin >> ar[i];
  
  queue<int> q;
  vector<int> pos[n+5];
 
  Fenwick F(2*n);
 
  for(int i=1;i<=2*n;i++){
    if(ar[i]<0) q.push(i);
    else pos[ar[i]].push_back(i);
  }
  
  for(int i=1;i<=n;i++) reverse(all(pos[i]));
 
  int p = 1;
  while(!q.empty()){
  	int64_t c = q.front();
  	q.pop();
  	int64_t x = pos[-ar[c]].back();
  	pos[-ar[c]].pop_back();

  	F.upd(c);
    c+=F.query(2*n)-F.query(c);
    ans+=c-p;
    p++;

    F.upd(x);
    x+=F.query(2*n)-F.query(x);
    ans+=x-p;
    p++;
  }
 
  cout << ans << '\n';
}
 
int32_t main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  int tc=1;//cin >> tc;
  while(tc--) _();
}*/

Compilation message

shoes.cpp: In function 'int64_t count_swaps(std::vector<int>)':
shoes.cpp:64:21: error: no matching function for call to 'min(int64_t&, int&)'
   64 |       res=min(res,hm);
      |                     ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from shoes.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
shoes.cpp:64:21: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
   64 |       res=min(res,hm);
      |                     ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from shoes.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
shoes.cpp:64:21: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
   64 |       res=min(res,hm);
      |                     ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from shoes.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
shoes.cpp:64:21: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   64 |       res=min(res,hm);
      |                     ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from shoes.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
shoes.cpp:64:21: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   64 |       res=min(res,hm);
      |                     ^
shoes.cpp:4:27: error: could not convert '(((void)xd.std::vector<long int>::begin()), xd.std::vector<long int>::end())' from 'std::vector<long int>::iterator' to 'bool'
    4 | #define all(x) (x).begin(),(x).end()
      |                ~~~~~~~~~~~^~~~~~~~~~
      |                           |
      |                           std::vector<long int>::iterator
shoes.cpp:65:12: note: in expansion of macro 'all'
   65 |     }while(all(xd));
      |            ^~~
shoes.cpp:24:15: warning: unused variable 'ans' [-Wunused-variable]
   24 |   int64_t n , ans = 0;
      |               ^~~
shoes.cpp:89:1: warning: control reaches end of non-void function [-Wreturn-type]
   89 | }
      | ^