Submission #1144660

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

#include "grader.cpp"

using namespace std;

#define all(x) x.begin(), x.end()
#define pb push_back
#define nl '\n'

struct Fenw {
	int n;
	vector<int> t;
	
	Fenw(int n) : n(n), t(n + 1) {}
	
	void update(int i, int x) {
		i++;
		for(; i <= n; i += i & -i) t[i] += x;
	}
	int get(int i) {
		int res = 0;
		
		for(; i >= 1; i -= i & -i) res += t[i];
		
		return res;
	}
	
	int get(int l, int r) {
		return get(r + 1) - get(l);
	}
};

long long count_swaps(vector<int> s) {
	int n = s.size();
	
	long long ans = 0;
	
	Fenw fn(n);
	
	bool flag = 0;
	
	map<int, set<int>> st;
	
	for(int i = 0; i < n; i++) {
		st[s[i]].emplace(i);
	}
	
	for(int i = 0; i < n; i++) {
		st[s[i]].erase(i);
		if(fn.get(i, i)) continue;
		
		int x = s[i];
		
		if(flag != (x > 0)) {
			int y = -x;
			
			int j = *st[y].begin();
			st[y].erase(st[y].begin());
			
			ans += j - i - fn.get(i, j);
			fn.update(j, 1);
			
		} else flag = !flag;
	}
	
	return ans;
}

/**
4
2 -2 2 2 -2 -2 -2 2

4
2 -2 2 -2 2 -2 2 -2

**/

Compilation message (stderr)

/usr/bin/ld: /tmp/ccHo8WSr.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccgJu8qi.o:shoes.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status