#include <bits/stdc++.h> #define int long long #define pii pair<int, int> #define piii pair<pair<int,int>, int> #define st first.first #define nd first.second #define rd second #define For(i, l, r) for (int i = l; i <= r; i++) #define Forcin(l, r, a) \ for (int i = l; i <= r; i++) \ cin >> a[i]; #define Ford(i, l, r) for (int i = l; i >= r; i--) #define ben(v) v.begin(), v.end() #define LOCAL 0 #define LOCAL2 0 using namespace std; const int M = 400005, L=64*782; int n, s, ind; bitset <L> target; vector <bitset<L>> sets; vector <piii> ops; void operation(int t, int x, int y=0){ ops.push_back({{x, y}, t}); ind++; if (t==1){ sets.push_back(sets[x]|sets[y]); } else if (t==2){ sets.push_back(sets[x]&sets[y]); } else{ sets.push_back(~sets[x]); } } signed main() { //cin.tie(0)->sync_with_stdio(); if (LOCAL) freopen("a.txt", "r", stdin); if (LOCAL2) freopen("local_out.txt", "w", stdout); //cerr << (M*L)/8/1024/1024 << " MB\n"; cin>>n>>s; sets=vector<bitset<L>>(n+1); For(i, 1, n){ for(int j=i;j<=n;j+=i){ sets[i].set(j); } } For(i, 1, s){ int x; cin>>x; target.set(x); } ind=n; //operation(1, 1, 1); For(i, 1, n){ if (target.test(i)){ if (!sets.back().test(i)){ operation(1, ind, i); } } else { if (sets.back().test(i)){ operation(3, i); operation(2, ind, ind-1); } } } cout << ops.size()<<'\n'; for (auto el:ops){ cout << el.rd<<' '<<el.st<<' '; if (el.rd<3) cout << el.nd<<' '; 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 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 | #include <bits/stdc++.h> #define int long long #define pii pair<int, int> #define piii pair<pair<int,int>, int> #define st first.first #define nd first.second #define rd second #define For(i, l, r) for (int i = l; i <= r; i++) #define Forcin(l, r, a) \ for (int i = l; i <= r; i++) \ cin >> a[i]; #define Ford(i, l, r) for (int i = l; i >= r; i--) #define ben(v) v.begin(), v.end() #define LOCAL 0 #define LOCAL2 0 using namespace std; const int M = 400005, L=64*782; int n, s, ind; bitset <L> target; vector <bitset<L>> sets; vector <piii> ops; void operation(int t, int x, int y=0){ ops.push_back({{x, y}, t}); ind++; if (t==1){ sets.push_back(sets[x]|sets[y]); } else if (t==2){ sets.push_back(sets[x]&sets[y]); } else{ sets.push_back(~sets[x]); } } signed main() { //cin.tie(0)->sync_with_stdio(); if (LOCAL) freopen("a.txt", "r", stdin); if (LOCAL2) freopen("local_out.txt", "w", stdout); //cerr << (M*L)/8/1024/1024 << " MB\n"; cin>>n>>s; sets=vector<bitset<L>>(n+1); For(i, 1, n){ for(int j=i;j<=n;j+=i){ sets[i].set(j); } } For(i, 1, s){ int x; cin>>x; target.set(x); } ind=n; //operation(1, 1, 1); For(i, 1, n){ if (target.test(i)){ if (!sets.back().test(i)){ operation(1, ind, i); } } else { if (sets.back().test(i)){ operation(3, i); operation(2, ind, ind-1); } } } cout << ops.size()<<'\n'; for (auto el:ops){ cout << el.rd<<' '<<el.st<<' '; if (el.rd<3) cout << el.nd<<' '; cout << '\n'; } } |