12tqian's Competitive Programming Library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub 12tqian/cp-library

:heavy_check_mark: library/data-structures/range-vector.hpp

Verified with

Code

#pragma once 

template <class T> class range_vector : public std::vector<T> {
public:
	int min_index;

	range_vector() : min_index(0) {}

	range_vector(int _min_index, int _max_index, T&& values = T())
		: std::vector<T>(_max_index - _min_index + 1, values), min_index(_min_index) {
		assert(_min_index <= _max_index + 1);
	}
	
	range_vector(int _max_index, T&& values = T())
		: std::vector<T>(_max_index + 1, values), min_index(0) {
		assert(0 <= _max_index + 1);
	}
	
	T& operator[](int i) { std::vector<T>& self = *this; return self[i - min_index]; }
};
template <class T> class range_vector : public std::vector<T> {
public:
	int min_index;

	range_vector() : min_index(0) {}

	range_vector(int _min_index, int _max_index, T&& values = T())
		: std::vector<T>(_max_index - _min_index + 1, values), min_index(_min_index) {
		assert(_min_index <= _max_index + 1);
	}
	
	range_vector(int _max_index, T&& values = T())
		: std::vector<T>(_max_index + 1, values), min_index(0) {
		assert(0 <= _max_index + 1);
	}
	
	T& operator[](int i) { std::vector<T>& self = *this; return self[i - min_index]; }
};
Back to top page