Submission #201414

#TimeUsernameProblemLanguageResultExecution timeMemory
201414khulegubArranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 KiB
#include "shoes.h"
#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define xx first
#define yy second
#define ll(x) (x*2) + 1
#define rr(x) (x*2) + 2

using namespace std;

typedef long long i64;

vector<int> ft;

int query(int x){
	int sm = 0;
	while (x){
		sm += ft[x];
		x -= x & (-x);
	}
	return sm;
}
int query(int l, int r){
	int bb = 0;
	if (l != 0) bb = query(b - 1);
	return query(r) - bb;
}
int update(int x, int v){
	while (x){
		ft[x] += v;
		x += x & (-x);
	}
}

i64 count_swaps(std::vector<int> s) {

	i64 ans = 0LL;
	int n = s.size();

	ft.resize(n);

	vector<int> maap_l[100005], maap_r[100005];


	for (int i = n - 1; i >= 0; i--){
		if (s[i] < 0) maap_l[s[i] * -1].pb(i);
		else maap_r[s[i]].pb(i);
	}

	vector<bool> taken(n, 0);

	for (int i = 0; i < n; i++){
		int tmp;
		if (!taken[i]){
			if (s[i] < 0){
				maap_r[s[i]].pop_back();
				tmp = maap_r[s[i]].back();
			}
			else{
				maap_l[s[i]].pop_back();
				tmp = maap_l[s[i]].back();
			}

			taken[tmp] = 1;

			if (s[i] < 0){
				ans += tmp - i - 1;
			}
			else{
				ans += tmp - i;
			}

			ans -= query(i, tmp);
			update(tmp, 1);
		}
	}

	return ans;
}

Compilation message (stderr)

shoes.cpp: In function 'int query(int, int)':
shoes.cpp:27:25: error: 'b' was not declared in this scope
  if (l != 0) bb = query(b - 1);
                         ^
shoes.cpp:27:25: note: suggested alternative: 'bb'
  if (l != 0) bb = query(b - 1);
                         ^
                         bb
shoes.cpp: In function 'int update(int, int)':
shoes.cpp:35:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^