#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define PB push_back
#define FS first
#define SD second
#define ary(k) array<int, k>
template <class A, class B> void cmx(A &x, B y) { x = max<A>(x, y); }
template <class A, class B> void cmn(A &x, B y) { x = min<A>(x, y); }
typedef pair<int, int> pii;
typedef vector<int> vi;
signed main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
const int MM = 5e4 + 5;
int n, s;
cin >> n >> s;
bitset<MM> in;
rep(i, 0, s) {
int x;
cin >> x;
in[x] = 1;
}
vector<bitset<MM>> a(n + 1);
rep(i, 1, n + 1) {
for (int j = i; j <= n; j += i)
a[i][j] = 1;
}
vector<ary(3)> res;
auto op = [&](int t, int x, int y = 0) {
res.PB({t, x, y});
if (t == 3) {
a.PB(~a[x]);
} else if (t == 2) {
assert(y);
a.PB(a[x] & a[y]);
} else {
a.PB(a[x] | a[y]);
}
/*
cerr << "nw " << t << " " << x << " " << y << "\n";
rep(i, 1, n + 1) if (a.back()[i]) cerr << i << " ";
cerr << "\n";*/
};
// [n+1,2n) are suffixes
for (int i = n - 1; i >= 1; i--) {
op(1, n + (n - 1) - i, i);
}
// 2n is 0
op(3, 1);
bool skip = 0;
for (int i = 1; i <= n; i++) {
int j = i;
while (j + 1 <= n && in[j + 1] == in[j])
j++;
if (skip) {
skip = 0;
i = j;
continue;
}
if (i == 1 && !in[i]) {
i = j;
continue;
}
// cerr << "proc " << i << " " << j << "\n";
if (i == j && in[i]) {
op(1, sz(a) - 1, i);
skip = 1;
} else {
if (in[i]) {
// union with [i,n] suffix
op(1, sz(a) - 1, n + n - i);
} else {
// intersect with ~[i,n] suffix
op(3, n + n - i);
op(2, sz(a) - 1, sz(a) - 2);
}
}
i = j;
}
// assert(sz(res) <= 2 * n);
cout << sz(res) << "\n";
for (auto [t, x, y] : res) {
cout << t << " " << x;
if (t != 3)
cout << " " << y;
cout << "\n";
}
/*
rep(i, 1, sz(a)) {
rep(j, 1, n + 1) if (a[i][j]) { cerr << j << " "; }
cerr << "\n";
}*/
}
//
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | #include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll #define rep(i, a, b) for (int i = a; i < (b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define PB push_back #define FS first #define SD second #define ary(k) array<int, k> template <class A, class B> void cmx(A &x, B y) { x = max<A>(x, y); } template <class A, class B> void cmn(A &x, B y) { x = min<A>(x, y); } typedef pair<int, int> pii; typedef vector<int> vi; signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); const int MM = 5e4 + 5; int n, s; cin >> n >> s; bitset<MM> in; rep(i, 0, s) { int x; cin >> x; in[x] = 1; } vector<bitset<MM>> a(n + 1); rep(i, 1, n + 1) { for (int j = i; j <= n; j += i) a[i][j] = 1; } vector<ary(3)> res; auto op = [&](int t, int x, int y = 0) { res.PB({t, x, y}); if (t == 3) { a.PB(~a[x]); } else if (t == 2) { assert(y); a.PB(a[x] & a[y]); } else { a.PB(a[x] | a[y]); } /* cerr << "nw " << t << " " << x << " " << y << "\n"; rep(i, 1, n + 1) if (a.back()[i]) cerr << i << " "; cerr << "\n";*/ }; // [n+1,2n) are suffixes for (int i = n - 1; i >= 1; i--) { op(1, n + (n - 1) - i, i); } // 2n is 0 op(3, 1); bool skip = 0; for (int i = 1; i <= n; i++) { int j = i; while (j + 1 <= n && in[j + 1] == in[j]) j++; if (skip) { skip = 0; i = j; continue; } if (i == 1 && !in[i]) { i = j; continue; } // cerr << "proc " << i << " " << j << "\n"; if (i == j && in[i]) { op(1, sz(a) - 1, i); skip = 1; } else { if (in[i]) { // union with [i,n] suffix op(1, sz(a) - 1, n + n - i); } else { // intersect with ~[i,n] suffix op(3, n + n - i); op(2, sz(a) - 1, sz(a) - 2); } } i = j; } // assert(sz(res) <= 2 * n); cout << sz(res) << "\n"; for (auto [t, x, y] : res) { cout << t << " " << x; if (t != 3) cout << " " << y; cout << "\n"; } /* rep(i, 1, sz(a)) { rep(j, 1, n + 1) if (a[i][j]) { cerr << j << " "; } cerr << "\n"; }*/ } // |
English