fork(1) download
  1. #include<iostream>
  2. #include<bits/stdc++.h>
  3. #include<stdio.h>
  4. using namespace std;
  5. #define fo(i,n) for(i=0;i<(n);++i)
  6. #define repA(i,j,n) for(i=(j);i<=(n);++i)
  7. #define repD(i,j,n) for(i=(j);i>=(n);--i)
  8. #define pb push_back
  9. #define mp make_pair
  10. #define X first
  11. #define Y second
  12. #define endl "\n"
  13. #define PI 3.1415926535897932384626433832795
  14. typedef long long int lli;
  15. typedef long double mytype;
  16. typedef pair<lli,lli> ii;
  17. typedef vector<ii> vii;
  18. typedef vector<lli> vi;
  19.  
  20. const int me = 20;
  21. struct Gauss {
  22. int table[me];
  23.  
  24. Gauss() {
  25. for(int i = 0; i < me; i++) {
  26. table[i] = 0;
  27. }
  28. }
  29.  
  30. int size() {
  31. int ans = 0;
  32. for(int i = 0; i < me; i++) {
  33. if(table[i]) ans++;
  34. }
  35. return ans;
  36. }
  37.  
  38. bool can(int x) {
  39. for(int i = me-1; i >= 0; i--) {
  40. x = std::min(x, x ^ table[i]);
  41. }
  42. return x == 0;
  43. }
  44.  
  45. void add(int x) {
  46. for(int i = me-1; i >= 0 && x; i--) {
  47. if(table[i] == 0) {
  48. table[i] = x;
  49. x = 0;
  50. } else {
  51. x = std::min(x, x ^ table[i]);
  52. }
  53. }
  54. }
  55.  
  56. int best() {
  57. int x = 0;
  58. for(int i = me-1; i >= 0; i--) {
  59. x = std::max(x, x ^ table[i]);
  60. }
  61. return x;
  62. }
  63. void prt()
  64. {
  65. for(int i = me-1; i >= 0; i--) {
  66. if(table[i])
  67. cout<<table[i]<<" ";
  68. }
  69. cout<<endl;
  70. }
  71. };
  72.  
  73. int main(void) {
  74. ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  75.  
  76. Gauss test;
  77. test.add(4);
  78. test.prt();
  79.  
  80. test.add(1);
  81. test.prt();
  82.  
  83. test.add(8);
  84. test.prt();
  85. return 0;
  86. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
4 
4 1 
4 1 8