Submission #298266

#TimeUsernameProblemLanguageResultExecution timeMemory
298266RayaabualjamalArranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 KiB
#include "shoes.h"
#include <cassert>

#include <iostream> 
#include <vector> 
#include <map> 
#include <cstdio>
#define rep(i,a,b) for(int i = a; i<b; i++)
#define per(i,a,b) for(int i = a; i>=b; i--)
#define pb push_back
#define se second
using namespace std;
long long count_swaps(vector<int> s) {
	int n = s.size();
	long long ans = 0; 
	map <int, vector <int> > m;
	rep(i,0,n){
		m[s[i]].pb(i);
	}
	for(auto& vec:m){
		reverse(vec.se.begin(), vec.se.end());
	}
	vector <int> vis(n+n, 0);
	rep(i,0,n){
		if(vis[i])continue;
		//cout << i << " ";
		if(s[i]<0){
			int pos = m[-s[i]].back();
			//cout << pos << " 1" << endl;
			per(j,pos-1, i+1){
				if(vis[j]==0)ans++;
			}
			vis[pos] = 1;
		}else{
			int pos = m[-s[i]].back();
			//cout << pos << " 2" << endl;
			per(j,pos-1, i){
				if(vis[j]==0)ans++;
			}
			vis[pos] = 1;
		}
		m[-s[i]].pop_back();
		m[s[i]].pop_back();
		vis[i]=1;
	}
	//cout << "ans: " << ans << endl;
	return ans;
}

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:21:3: error: 'reverse' was not declared in this scope
   21 |   reverse(vec.se.begin(), vec.se.end());
      |   ^~~~~~~