#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, s; cin >> n >> s; bitset<50001> B; for (int i = 1; i <= s; i++) { int x; cin >> x; B.set(x); } bitset<50001> A[n + 1]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (j % i == 0) { A[i].set(j); } } } bitset<50001> S; vector<vector<int>> operations; for (int i = 1; i <= n; i++) { if (S[i] && !B[i]) { operations.push_back({3, i}); operations.push_back({2, n + int(operations.size()), n + int(operations.size()) - 1}); S = S & (~A[i]); } else if (!S[i] && B[i]) { if (operations.empty()) { operations.push_back({1, i, i}); S = A[i]; } else { operations.push_back({1, i, n + int(operations.size())}); S = S | A[i]; } } } cout << operations.size() << "\n"; for (int i = 0; i < operations.size(); i++) { for (int j = 0; j < operations[i].size(); j++) { cout << operations[i][j] << " "; } cout << "\n"; } return 0; }
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 | #include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, s; cin >> n >> s; bitset<50001> B; for (int i = 1; i <= s; i++) { int x; cin >> x; B.set(x); } bitset<50001> A[n + 1]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (j % i == 0) { A[i].set(j); } } } bitset<50001> S; vector<vector<int>> operations; for (int i = 1; i <= n; i++) { if (S[i] && !B[i]) { operations.push_back({3, i}); operations.push_back({2, n + int(operations.size()), n + int(operations.size()) - 1}); S = S & (~A[i]); } else if (!S[i] && B[i]) { if (operations.empty()) { operations.push_back({1, i, i}); S = A[i]; } else { operations.push_back({1, i, n + int(operations.size())}); S = S | A[i]; } } } cout << operations.size() << "\n"; for (int i = 0; i < operations.size(); i++) { for (int j = 0; j < operations[i].size(); j++) { cout << operations[i][j] << " "; } cout << "\n"; } return 0; } |