#include <bits/stdc++.h> using namespace std; int n,m,i,j,a,b,md,k,d,t; long long q1,q2,x,y; vector<array<long long,2>> h,v; array<long long,36> f; vector<array<int,2>> z; char ca; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for(i=0;i<m;i++) { cin >> a >> b; z.push_back({a-1,b-1}); } for(i=0;i<n;i++) for(j=i+1;j<=n;j++) { h={}; if(j<17 && i<17) h.push_back({(1<<j)-(1<<i),0}); else if(j>=17 && i<17) h.push_back({(1<<17)-(1<<i),(1<<(j-17))-1}); else h.push_back({0,(1<<(j-17))-(1<<(i-17))}); for(k=m-1;k>=0;k--) { v={}; if(z[k][0]<17 && z[k][1]<17) { y=1<<z[k][0]; x=1<<z[k][1]; for(auto qq:h) if(qq[0]&x){ v.push_back(qq); if(!(qq[0]&y)) v.push_back({qq[0]-x+y,qq[1]}); } else if(!(qq[0]&y)) v.push_back(qq); } else if(z[k][0]>=17 && z[k][1]<17) { y=1<<(z[k][0]-17); x=1<<z[k][1]; for(auto qq:h) if(qq[0]&x){ v.push_back(qq); if(!(qq[1]&y)) v.push_back({qq[0]-x,qq[1]+y}); } else if(!(qq[1]&y)) v.push_back(qq); } else if(z[k][0]<17 && z[k][1]>=17) { y=1<<z[k][0]; x=1<<(z[k][1]-17); for(auto qq:h) if(qq[1]&x){ v.push_back(qq); if(!(qq[0]&y)) v.push_back({qq[0]+y,qq[1]-x}); } else if(!(qq[0]&y)) v.push_back(qq); } else { y=1<<(z[k][0]-17); x=1<<(z[k][1]-17); for(auto qq:h) if(qq[1]&x){ v.push_back(qq); if(!(qq[1]&y)) v.push_back({qq[0],qq[1]-x+y}); } else if(!(qq[1]&y)) v.push_back(qq); } h=v; } f[j-i]+=h.size()%2; } for(i=1;i<=n;i++) cout << f[i]%2 << ' '; 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 81 82 83 84 85 86 87 | #include <bits/stdc++.h> using namespace std; int n,m,i,j,a,b,md,k,d,t; long long q1,q2,x,y; vector<array<long long,2>> h,v; array<long long,36> f; vector<array<int,2>> z; char ca; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for(i=0;i<m;i++) { cin >> a >> b; z.push_back({a-1,b-1}); } for(i=0;i<n;i++) for(j=i+1;j<=n;j++) { h={}; if(j<17 && i<17) h.push_back({(1<<j)-(1<<i),0}); else if(j>=17 && i<17) h.push_back({(1<<17)-(1<<i),(1<<(j-17))-1}); else h.push_back({0,(1<<(j-17))-(1<<(i-17))}); for(k=m-1;k>=0;k--) { v={}; if(z[k][0]<17 && z[k][1]<17) { y=1<<z[k][0]; x=1<<z[k][1]; for(auto qq:h) if(qq[0]&x){ v.push_back(qq); if(!(qq[0]&y)) v.push_back({qq[0]-x+y,qq[1]}); } else if(!(qq[0]&y)) v.push_back(qq); } else if(z[k][0]>=17 && z[k][1]<17) { y=1<<(z[k][0]-17); x=1<<z[k][1]; for(auto qq:h) if(qq[0]&x){ v.push_back(qq); if(!(qq[1]&y)) v.push_back({qq[0]-x,qq[1]+y}); } else if(!(qq[1]&y)) v.push_back(qq); } else if(z[k][0]<17 && z[k][1]>=17) { y=1<<z[k][0]; x=1<<(z[k][1]-17); for(auto qq:h) if(qq[1]&x){ v.push_back(qq); if(!(qq[0]&y)) v.push_back({qq[0]+y,qq[1]-x}); } else if(!(qq[0]&y)) v.push_back(qq); } else { y=1<<(z[k][0]-17); x=1<<(z[k][1]-17); for(auto qq:h) if(qq[1]&x){ v.push_back(qq); if(!(qq[1]&y)) v.push_back({qq[0],qq[1]-x+y}); } else if(!(qq[1]&y)) v.push_back(qq); } h=v; } f[j-i]+=h.size()%2; } for(i=1;i<=n;i++) cout << f[i]%2 << ' '; cout << '\n'; } |