Submission #151924

#TimeUsernameProblemLanguageResultExecution timeMemory
151924ivandasfsArranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 KiB
#include <iostream>
#include <cstdio>
#include <set>

using namespace std;

typedef long long ll;

const int OFF = 1e5;

int off = 1;

set<int> s[200005];
int tur[600005];
//int a[200005];

void update(int node, int val) {
	if (!node) return ;
	if (node>=off) {
		tur[node] = val;
	}else {
		tur[node] = tur[node*2] + tur[node*2+1];
	}
	update(node/2, val);
}

int query(int l, int r, int x, int y, int node) {
	if (x>r or y<l) return 0;
	if (l>=x and r<=y) return tur[node];
	return query(l, (l+r)/2, x, y, node*2)+query((l+r)/2+1, r, x, y, node*2+1);
}

ll count_swaps(int *a) {
	int n = sizeof(a)/sizeof(a[0]);
	while (off<n) off*=2;
	for (int i=0 ; i<n ; i++) {
		update(off+i, 1);
		s[a[i]+OFF].insert(i);
	}
	ll sol=0;
	for (int i=0 ; i<n ; i++) {
		if (!a[i]) continue;
		//cout <<a[i]<<endl;
		int pos=*s[-a[i]+OFF].begin();
		//cout <<i<<":"<<pos<<endl;
		int g=query(0, off-1, i, pos, 1)-2;
		if (a[i]>0) g++;
		sol+=g;
		//cout <<"sol="<<sol<<endl;
		update(pos+off, 0);
		s[a[i]+OFF].erase(s[a[i]+OFF].begin());
		s[-a[i]+OFF].erase(s[-a[i]+OFF].begin());
		a[pos]=0;
	}
	return sol;
}

Compilation message (stderr)

/tmp/ccgUGixq.o: In function `main':
grader.cpp:(.text.startup+0x272): undefined reference to `count_swaps(std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status