Submission #776983

#TimeUsernameProblemLanguageResultExecution timeMemory
776983Trisanu_DasArranging Shoes (IOI19_shoes)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
 
ll n, BIT[100005];
queue<ll> l_unpair[100005], r_unpair[100005];
 
void upd(int idx, ll val){
  for(int i = idx; i < n + 1; i += (i & (-i))) BIT[i] += val;
}
 
ll qry(int idx){
  ll ans = 0;
  for(int i = idx; i > 0; i -= (i & (-i))) ans += BIT[i];
  return ans;
}
 
ll count_swaps(vector<int> s){
  n = s.size();
  ll swaps = 0;
  for(int i = 1; i < n + 1; i++){
    ll shoe_sz = s[i - 1];
    if(s_szhoe < 0){
      shoe_sz *= -1; // extracting shoe size;
      if(!r_unpair[shoe_sz].empty()){ //has a shoe unpaired of this(shoe_sz) size.
        ll shoe_need = r_unpair[shoe_sz].front(); r_unpair[shoe_sz].pop();
        swaps += qry(i) - qry(shoe_need - 1);
        upd(shoe_need, 1);
      }else{ // no shoe.
        l_unpair[shoe_sz].push(i); upd(i, 1);
      }
    }else{
      if(!l_unpair[shoe_sz].empty()){ //has a shoe unpaired of this(shoe_sz) size.
        ll shoe_need = l_unpair[shoe_sz].front(); l_unpair[shoe_sz].pop();
        swaps += qry(i) - qry(shoe_need);
        upd(shoe_need, 1);
      }else{ // no shoe.
        r_unpair[shoe_sz].push(i); upd(i, 1);
      }
    }
  }
  return swaps;
} 

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:23:8: error: 's_szhoe' was not declared in this scope
   23 |     if(s_szhoe < 0){
      |        ^~~~~~~