File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ // Permutation
2+ // https://youtu.be/-j02o6__jgs?t=7302
3+ struct Perm : vector<int > {
4+ #define n (int )(size())
5+ #define p (*this )
6+ Perm (int _n): vector<int >(_n) {
7+ iota (begin (), end (), 0 );
8+ }
9+ template <class ...Args> Perm (Args...args): vector<int>(args...) {}
10+ Perm (initializer_list<int > a): vector<int >(a.begin(),a.end()) {}
11+ Perm operator +(const Perm& a) const {
12+ Perm r (n);
13+ for (int i = 0 ; i < n; ++i) r[i] = p[a[i]];
14+ return r;
15+ }
16+ Perm& operator +=(const Perm& a) {
17+ return *this = (*this )+a;
18+ }
19+ Perm operator -() const {
20+ Perm r (n);
21+ for (int i = 0 ; i < n; ++i) r[p[i]] = i;
22+ return r;
23+ }
24+ Perm operator -(const Perm& a) const {
25+ return *this + -a;
26+ }
27+ Perm& operator -=(const Perm& a) {
28+ return *this += -a;
29+ }
30+ // next permutation
31+ bool operator ++() {
32+ return next_permutation (begin (),end ());
33+ }
34+ #undef n
35+ #undef p
36+ };
You can’t perform that action at this time.
0 commit comments