Submission #1219844

#TimeUsernameProblemLanguageResultExecution timeMemory
1219844nickolasarapidisArranging Shoes (IOI19_shoes)C++17
Compilation error
0 ms0 KiB
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 200000;

vector<long long> cnt(MAXN, 0), ST(4*MAXN, 0);

void update(int v, int l, int r, int k, int x){
	if(l == r){
		ST[v] += x;
		return;
	}
	int m = (l + r)/2;
	if(k <= m){
		update(2*v, l, m, k, x);
	}
	else{
		update(2*v + 1, m + 1, r, k, x);
	}
	ST[v] = ST[2*v] + ST[2*v + 1];
	return;
}

long long sum(int v, int l, int r, int a, int b){
	if(l > b or r < a) return 0;
	if(l >= a and r <= b) return ST[v];
	int m = (l + r)/2;
	return sum(2*v, l, m, a, b) + sum(2*v + 1, m + 1, r, a, b);
}

long long count_swaps(vector<int> S){
	map<int, vector<int>> m;
	long long ans = 0;
	for(int i = 0; i < S.size(); i++){
		if(S[i] > 0 and m[-S[i]].size() > 0){
			int j = m[-S[i]].back();
			ans += i - j + 1 + sum(1, 0, N - 1, j, i);
			update(1, 0, N - 1, i, -1);
			update(1, 0, N - 1, j, 1);
			m[-S[i]].pop_back();
		}
		else if(S[i] < 0 and m[-S[i]].size() > 0){
			int j = m[-S[i]].back();
			ans += i - j + sum(1, 0, N - 1, j, i);
			update(1, 0, N - 1, i, -1);
			update(1, 0, N - 1, j, 1);
			m[-S[i]].pop_back();
		}
		else{
			m[S[i]].push_back(i);
		}
	}
	return ans;
}

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:38:54: error: 'N' was not declared in this scope
   38 |                         ans += i - j + 1 + sum(1, 0, N - 1, j, i);
      |                                                      ^
shoes.cpp:45:50: error: 'N' was not declared in this scope
   45 |                         ans += i - j + sum(1, 0, N - 1, j, i);
      |                                                  ^