#include <bits/stdc++.h> #define rep(i, j, k) for (int i = (j); i <= (k); ++i) #define per(i, j, k) for (int i = (j); i >= (k); --i) #define SZ(v) int((v).size()) #define ALL(v) (v).begin(),(v).end() #define fi first #define se second using ll = long long; using pii = std::pair<int, int>; using pll = std::pair<ll, ll>; template<class T> void chkmn(T &x, T y) { if (y < x) x = y; } template<class T> void chkmx(T &x, T y) { if (y > x) x = y; } using namespace std; const int maxn = 50010; int n, m, a[maxn], vis[maxn]; bitset<maxn> bs[maxn], cur; vector<tuple<int, int, int>> ans; int main() { cin.tie(nullptr) -> ios::sync_with_stdio(false); cin >> n >> m; rep (i, 1, m) cin >> a[i], vis[a[i]] = 1; rep (i, 1, n) rep (j, 1, n / i) bs[i].set(i * j); int pos = n; cur = bs[n]; rep (i, 1, n) { if (cur.test(i) && !vis[i]) { ans.emplace_back(3, i, i); ans.emplace_back(2, pos, pos + 1); pos += 2, cur &= (bs[i].flip()); } else if (!cur.test(i) && vis[i]) { ans.emplace_back(1, pos, i); pos++, cur |= bs[i]; } } cout << SZ(ans) << '\n'; for (auto [op, x, y] : ans) { if (op != 3) cout << op << ' ' << x << ' ' << y << '\n'; else cout << op << ' ' << x << '\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 | #include <bits/stdc++.h> #define rep(i, j, k) for (int i = (j); i <= (k); ++i) #define per(i, j, k) for (int i = (j); i >= (k); --i) #define SZ(v) int((v).size()) #define ALL(v) (v).begin(),(v).end() #define fi first #define se second using ll = long long; using pii = std::pair<int, int>; using pll = std::pair<ll, ll>; template<class T> void chkmn(T &x, T y) { if (y < x) x = y; } template<class T> void chkmx(T &x, T y) { if (y > x) x = y; } using namespace std; const int maxn = 50010; int n, m, a[maxn], vis[maxn]; bitset<maxn> bs[maxn], cur; vector<tuple<int, int, int>> ans; int main() { cin.tie(nullptr) -> ios::sync_with_stdio(false); cin >> n >> m; rep (i, 1, m) cin >> a[i], vis[a[i]] = 1; rep (i, 1, n) rep (j, 1, n / i) bs[i].set(i * j); int pos = n; cur = bs[n]; rep (i, 1, n) { if (cur.test(i) && !vis[i]) { ans.emplace_back(3, i, i); ans.emplace_back(2, pos, pos + 1); pos += 2, cur &= (bs[i].flip()); } else if (!cur.test(i) && vis[i]) { ans.emplace_back(1, pos, i); pos++, cur |= bs[i]; } } cout << SZ(ans) << '\n'; for (auto [op, x, y] : ans) { if (op != 3) cout << op << ' ' << x << ' ' << y << '\n'; else cout << op << ' ' << x << '\n'; } } |