Submission #839150

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

using namespace std;
typedef long long ll;
vector<ll>seg;
void update(int i, ll v, int x, int lx, int rx) {
	if (lx + 1 == rx) {
		seg[i] = v;
		return;
	}
	int mid = (lx + rx) / 2, idx1 = 2 * x + 1, idx2 = 2 * x + 2;
	if (i < mid)
		update(i, v, idx1, lx, mid);
	else
		update(i, v, idx2, mid, rx);
	seg[x] = seg[idx1] + seg[idx2];
}
ll get(int l, int r, int x, int lx, int rx) {
	if (lx >= r || rx <= l)
		return 0;
	if (lx >= l && rx <= r)
		return seg[x];
	int mid = (lx + rx), idx1 = 2 * x + 1, idx2 = 2 * x + 2;
	return (get(l, r, idx1, lx, mid) + get(l, r, idx2, mid, rx));
}
long long count_swaps(std::vector<int> v) {
	int n = v.size();
	vector<bool>vis(n, false);
	int siz = 1;
	while (siz < n)
		siz *= 2;
	seg.resize(2 * siz, 0);
	for (int i = 0; i < n; i++)
		update(i, i, 0, 0, siz);
	map<int, priority_queue<int>>idx;
	for (int i = 0; i < n; i++)
		idx[v[i]].push(i);
	vector<boo>vis(n + 1, false);
	for (int i = 0; i < n; i++) {
		if (vis[i])
			continue;
		int j = idx[-v[i]].top();
		vis[i] = vis[j] = true;
		idx[-v[i]].pop();
		ll valJ = get(0, j + 1, 0, 0, siz), valI = get(0, i + 1, 0, 0, siz);
		ll dif = valJ - valI;
		if (valI % 2 == 0 && v[i] < 0)
			ans += dif;
		else
			ans += dif + 1;
		update(i + 1, 1, 0, 0, siz);
		update(j + 1, -1, 0, 0, siz);
	}
	return ans;
}

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:39:9: error: 'boo' was not declared in this scope; did you mean 'bool'?
   39 |  vector<boo>vis(n + 1, false);
      |         ^~~
      |         bool
shoes.cpp:39:12: error: template argument 1 is invalid
   39 |  vector<boo>vis(n + 1, false);
      |            ^
shoes.cpp:39:12: error: template argument 2 is invalid
shoes.cpp:39:13: error: conflicting declaration 'int vis'
   39 |  vector<boo>vis(n + 1, false);
      |             ^~~
shoes.cpp:29:14: note: previous declaration as 'std::vector<bool> vis'
   29 |  vector<bool>vis(n, false);
      |              ^~~
shoes.cpp:49:4: error: 'ans' was not declared in this scope; did you mean 'abs'?
   49 |    ans += dif;
      |    ^~~
      |    abs
shoes.cpp:51:4: error: 'ans' was not declared in this scope; did you mean 'abs'?
   51 |    ans += dif + 1;
      |    ^~~
      |    abs
shoes.cpp:55:9: error: 'ans' was not declared in this scope; did you mean 'abs'?
   55 |  return ans;
      |         ^~~
      |         abs