QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#355979#8174. Set Constructionucup-team1209#TL 15ms3656kbC++202.3kb2024-03-17 14:23:072024-03-17 14:23:08

Judging History

你现在查看的是最新测评结果

  • [2024-03-17 14:23:08]
  • 评测
  • 测评结果:TL
  • 用时:15ms
  • 内存:3656kb
  • [2024-03-17 14:23:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define drep(i,y,x) for (int i=(y);i>=(x);i--)
#define pii pair<int,int>
#define fir first
#define sec second
#define MP make_pair
template<typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template<typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
void file() {
    #ifdef zqj
    freopen("a.in","r",stdin);
    #endif
}
typedef long long ll;
using u64 = unsigned long long;
void solve(int n, int m) {
	u64 z = 1ull<<n;
	static std::mt19937_64 gen(0);
	for(;;) {
		std::vector<u64> res = {0, (1ull << n) - 1};
		auto tryins = [&](u64 v) {
			auto iter = lower_bound(res.begin(), res.end(), v);
			if(iter == res.end() || *iter != v) {
				res.insert(iter, v);
				return 1;
			} else {
				return 0;
			}
		};
		static std::queue<u64> Q;
		for(;res.size() < m;) {
			if(Q.empty()) {
				u64 v = gen() % z;
				if(tryins(v)) Q.push(v);
			}
			for(;Q.size();) {
				u64 z = Q.front(); Q.pop();
				static u64 li[10000]; int cc = 0;
				for(u64 p : res) {
					li[cc++] = p & z;
					li[cc++] = p | z;
				}
				for(int i = 0;i < cc;++i) {
					u64 v = li[i];
					if(tryins(v)) Q.push(v);
				}
			}
		}
		if(res.size() == m) {
            
            for (auto x:res) cout<<x<<' ';
            cout<<'\n';
            return;
        }
	}

}

void work(int n, int m) {
    --m;
    int _n=0;
    vector<int>s({0});
    int k=30; while (!(m>>k)) k--;
    drep(i,k-1,0) {
        vector<int>t=s;
        for (auto x:t) s.push_back(x|(1ll<<_n));
        ++_n;
        if (m>>i&1) {
            ++_n;
            s.push_back((1ll<<_n)-1);
        }
    }
    set<ll>S(s.begin(),s.end());
    assert(_n<n);
    S.insert((1ll<<n)-1);
    assert((int)S.size()==m+1);
    for (auto x:S) for (auto y:S) assert(S.count(x&y)&&S.count(x|y));
    assert(S.count(0)&&S.count((1ll<<n)-1));
    for (auto x:S) cout<<x<<' ';
    cout<<'\n';
}

int main() {
    file();
    ios::sync_with_stdio(false), cin.tie(0);
    int T; cin>>T;
    while (T--) {
        int n,m;
        cin>>n>>m;
        if(n <= 8) {
            // std::cerr<<n<<' '<<m<<std::endl;
            solve(n, m);
        } else {
            work(n, m);
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3624kb

input:

3
3 5
4 8
60 2

output:

0 2 3 6 7 
0 1 6 7 8 9 14 15 
0 1152921504606846975 

result:

ok AC

Test #2:

score: 0
Accepted
time: 2ms
memory: 3572kb

input:

30
6 2
6 3
6 4
6 5
6 6
6 7
6 8
6 9
6 10
6 11
6 12
6 13
6 14
6 15
6 16
6 17
6 18
6 19
6 20
6 21
7 2
7 3
7 4
7 5
7 6
7 7
7 8
7 9
7 10
7 11

output:

0 63 
0 62 63 
0 44 46 63 
0 40 46 47 63 
0 8 14 56 62 63 
0 10 26 42 47 58 63 
0 2 7 15 34 39 47 63 
0 4 10 14 20 30 43 47 63 
0 4 12 32 35 36 39 44 47 63 
0 4 32 36 46 48 49 52 53 62 63 
0 16 17 19 32 48 49 51 56 57 59 63 
0 1 2 3 16 17 18 19 24 25 26 27 63 
0 1 8 9 13 16 17 24 25 29 43 47 59 63 
...

result:

ok AC

Test #3:

score: 0
Accepted
time: 6ms
memory: 3656kb

input:

30
7 12
7 13
7 14
7 15
7 16
7 17
7 18
7 19
7 20
7 21
7 22
7 23
7 24
7 25
7 26
7 27
7 28
8 2
8 3
8 4
8 5
8 6
8 7
8 8
8 9
8 10
8 11
8 12
8 13
8 14

output:

0 8 9 10 11 56 57 58 59 62 63 127 
0 1 16 17 31 32 33 48 49 63 112 113 127 
0 1 3 16 17 19 28 29 31 81 83 93 95 127 
0 1 5 9 13 15 33 37 41 45 47 57 61 63 127 
0 2 8 10 32 34 40 42 52 54 60 62 105 107 125 127 
0 16 24 64 66 80 82 88 90 96 98 112 114 120 122 125 127 
0 12 16 17 28 29 96 98 108 110 11...

result:

ok AC

Test #4:

score: 0
Accepted
time: 15ms
memory: 3636kb

input:

30
8 15
8 16
8 17
8 18
8 19
8 20
8 21
8 22
8 23
8 24
8 25
8 26
8 27
8 28
8 29
8 30
8 31
8 32
8 33
8 34
8 35
8 36
9 2
9 3
9 4
9 5
9 6
9 7
9 8
9 9

output:

0 64 66 96 98 192 194 202 224 226 234 241 243 251 255 
0 8 10 15 136 138 143 154 159 168 170 175 186 191 223 255 
0 2 8 9 10 11 42 43 123 136 137 138 139 170 171 251 255 
0 8 32 40 65 73 77 97 99 105 107 109 111 184 249 251 253 255 
0 4 5 20 21 23 132 133 148 149 151 157 159 165 181 183 189 191 255 ...

result:

ok AC

Test #5:

score: 0
Accepted
time: 1ms
memory: 3556kb

input:

30
9 10
9 11
9 12
9 13
9 14
9 15
9 16
9 17
9 18
9 19
9 20
9 21
9 22
9 23
9 24
9 25
9 26
9 27
9 28
9 29
9 30
9 31
9 32
9 33
9 34
9 35
9 36
9 37
9 38
9 39

output:

0 1 2 3 4 5 6 7 15 511 
0 1 2 3 7 8 9 10 11 15 511 
0 1 2 3 7 8 9 10 11 15 31 511 
0 1 3 4 5 7 8 9 11 12 13 15 511 
0 1 3 4 5 7 8 9 11 12 13 15 31 511 
0 1 3 4 5 7 15 16 17 19 20 21 23 31 511 
0 1 3 4 5 7 15 16 17 19 20 21 23 31 63 511 
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 511 
0 1 2 3 4 5 6 7 8 9 ...

result:

ok AC

Test #6:

score: 0
Accepted
time: 1ms
memory: 3600kb

input:

6
9 40
9 41
9 42
9 43
9 44
9 45

output:

0 1 2 3 4 5 6 7 15 16 17 18 19 20 21 22 23 31 63 64 65 66 67 68 69 70 71 79 80 81 82 83 84 85 86 87 95 127 255 511 
0 1 2 3 7 8 9 10 11 15 16 17 18 19 23 24 25 26 27 31 32 33 34 35 39 40 41 42 43 47 48 49 50 51 55 56 57 58 59 63 511 
0 1 2 3 7 8 9 10 11 15 16 17 18 19 23 24 25 26 27 31 32 33 34 35 3...

result:

ok AC

Test #7:

score: -100
Time Limit Exceeded

input:

30
60 1801
60 1802
60 1803
60 1804
60 1805
60 1806
60 1807
60 1808
60 1809
60 1810
60 1811
60 1812
60 1813
60 1814
60 1815
60 1816
60 1817
60 1818
60 1819
60 1820
60 1821
60 1822
60 1823
60 1824
60 1825
60 1826
60 1827
60 1828
60 1829
60 1830

output:

0 1 3 4 5 7 15 16 17 19 20 21 23 31 32 33 35 36 37 39 47 48 49 51 52 53 55 63 64 65 67 68 69 71 79 80 81 83 84 85 87 95 96 97 99 100 101 103 111 112 113 115 116 117 119 127 128 129 131 132 133 135 143 144 145 147 148 149 151 159 160 161 163 164 165 167 175 176 177 179 180 181 183 191 192 193 195 196...

result: