#include <bitset>
#include <iostream>
#include <string>
#include <vector>
constexpr int MAX = 50001;
using namespace std;
int main()
{
int n, s, b;
cin >> n >> s;
vector<bitset<MAX>> sets(n + 1);
for (int j = 1; j <= n; ++j)
{
for (int i = j; i <= n; i += j)
{
sets[j].set(i);
}
}
bitset<MAX> target;
for (int i = 0; i < s; ++i)
{
cin >> b;
target.set(b);
}
int cnt = n;
bitset<MAX> current = sets[n];
vector<string> res;
for (int i = 1; i <= n; ++i)
{
if (target.test(i))
{
if (!current.test(i))
{
res.push_back("1 " + to_string(i) + " " + to_string(cnt));
++cnt;
current |= sets[i];
}
}
else
{
if (current.test(i))
{
res.push_back("3 " + to_string(i));
++cnt;
res.push_back("2 " + to_string(cnt - 1) + " " + to_string(cnt));
++cnt;
current &= ~sets[i];
}
}
}
cout << res.size() << endl;
for (const string x : res)
{
cout << x << endl;
}
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 62 63 64 65 66 67 68 69 70 | #include <bitset> #include <iostream> #include <string> #include <vector> constexpr int MAX = 50001; using namespace std; int main() { int n, s, b; cin >> n >> s; vector<bitset<MAX>> sets(n + 1); for (int j = 1; j <= n; ++j) { for (int i = j; i <= n; i += j) { sets[j].set(i); } } bitset<MAX> target; for (int i = 0; i < s; ++i) { cin >> b; target.set(b); } int cnt = n; bitset<MAX> current = sets[n]; vector<string> res; for (int i = 1; i <= n; ++i) { if (target.test(i)) { if (!current.test(i)) { res.push_back("1 " + to_string(i) + " " + to_string(cnt)); ++cnt; current |= sets[i]; } } else { if (current.test(i)) { res.push_back("3 " + to_string(i)); ++cnt; res.push_back("2 " + to_string(cnt - 1) + " " + to_string(cnt)); ++cnt; current &= ~sets[i]; } } } cout << res.size() << endl; for (const string x : res) { cout << x << endl; } return 0; } |
English