#include <bits/stdc++.h>
#define ll long long
#define range(i, n) for (int i = 0; i < n; i++)
using namespace std;
constexpr int maxn = 50001;
struct op {
int type;
int a;
int b;
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, s;
cin >> n >> s;
bitset<maxn> cur;
bitset<maxn> goal;
vector<op> ops;
ops.push_back({2, n-1, n});
while (s--) {
int x;
cin >> x;
goal[x] = true;
}
for (int i = 1; i <= n; i++) {
if (goal[i] == cur[i]) continue;
bitset<maxn> calc;
for (int j = i; j <= n; j += i) calc[j] = true;
int index = n+ops.size();
if (goal[i]) {
ops.push_back({1, i, index});
cur |= calc;
} else {
ops.push_back({3, i});
calc.flip();
ops.push_back({2, index, index+1});
cur &= calc;
}
}
cout << ops.size() << "\n";
for (auto &x : ops) {
cout << x.type << " " << x.a;
if (x.type != 3) cout << " " << x.b;
cout << "\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 | #include <bits/stdc++.h> #define ll long long #define range(i, n) for (int i = 0; i < n; i++) using namespace std; constexpr int maxn = 50001; struct op { int type; int a; int b; }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, s; cin >> n >> s; bitset<maxn> cur; bitset<maxn> goal; vector<op> ops; ops.push_back({2, n-1, n}); while (s--) { int x; cin >> x; goal[x] = true; } for (int i = 1; i <= n; i++) { if (goal[i] == cur[i]) continue; bitset<maxn> calc; for (int j = i; j <= n; j += i) calc[j] = true; int index = n+ops.size(); if (goal[i]) { ops.push_back({1, i, index}); cur |= calc; } else { ops.push_back({3, i}); calc.flip(); ops.push_back({2, index, index+1}); cur &= calc; } } cout << ops.size() << "\n"; for (auto &x : ops) { cout << x.type << " " << x.a; if (x.type != 3) cout << " " << x.b; cout << "\n"; } } |
English