-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector_next_permutation.cpp
More file actions
40 lines (33 loc) · 994 Bytes
/
vector_next_permutation.cpp
File metadata and controls
40 lines (33 loc) · 994 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "vector_next_permutataion.h"
#include <algorithm>
#include <numeric>
VectorNextPermutation::VectorNextPermutation()
{}
void VectorNextPermutation::addOnSegment(size_t L, size_t R, long long add)
{
std::transform(data_.begin() + L, data_.begin() + R + 1,
data_.begin() + L,
[add] (long long elem) {
return elem + add;
});
}
long long VectorNextPermutation::getSumOnSegment(size_t L, size_t R)
{
return std::accumulate(data_.begin() + L, data_.begin() + R + 1, (long long)0);
}
void VectorNextPermutation::applyNextPermutation(size_t L, size_t R)
{
std::next_permutation(data_.begin() + L, data_.begin() + R + 1);
}
void VectorNextPermutation::insert(size_t newPos, long long x)
{
data_.insert(data_.begin() + newPos, x);
}
void VectorNextPermutation::setElem(size_t pos, long long x)
{
data_.at(pos) = x;
}
size_t VectorNextPermutation::size() const
{
return data_.size();
}