QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#696613 | #9519. Build a Computer | Pkind | AC ✓ | 1ms | 4796kb | C++20 | 4.0kb | 2024-10-31 23:50:38 | 2024-10-31 23:50:39 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
int l, r;
cin >> l >> r;
int bitl = __lg(l), bitr = __lg(r);
vector<vector<array<int, 2>>> E(205);
if (l == r) {
int now = 1;
for (int i = bitl; i >= 0; --i) {
E[now].push_back({now + 1, l >> i & 1});
now++;
}
cout << now << '\n';
for (int i = 1; i <= now; ++i) {
cout << E[i].size() << ' ';
for (auto [v, w] : E[i]) {
cout << v << ' ' << w << ' ';
}
cout << '\n';
}
return ;
}
vector<pair<string, int>> build;
auto ts = [&]() {
for (auto [a, b] : build) {
cout << a << ' ' << b << '\n';
}
cout << '\n';
};
bitl++, bitr++;
if (bitl == bitr) {
int BIT = 0;
for (int i = bitl; i >= 1; --i) {
int bit = i - 1;
if (((l >> bit) ^ (r >> bit)) != 0) {
BIT = i;
break;
}
}
string s ;
for (int i = bitr; i >= BIT; --i) {
s += ((r >> (i - 1)) & 1) + '0';
}
for (int i = BIT - 1; i >= 1; --i) {
if ((r >> (i - 1)) & 1) {
build.push_back({s + '0', i - 1});
s += '1';
}
else {
s += '0';
}
}
build.push_back({s, 0});
if (BIT == 1) {
string ss = "";
for (int i = bitl; i >= 1; --i) {
ss += ((l >> (i - 1)) & 1) + '0';
}
build.push_back({ss, 0});
}
else {
int i = 1;
while (((l >> (i - 1)) & 1 ) != 1 && i > BIT) i++;
s = "";
if (!(i > BIT - 1)) {
for (int j = i; j <= bitl; ++j) {
s += (l >> (j - 1) & 1) + '0';
}
reverse(s.begin(), s.end());
build.push_back({s, i - 1});
}
while (1) {
while (i <= BIT - 1 && ((l >> (i - 1)) & 1) == 1) i++;
if (i > BIT - 1) break;
s = "1";
for (int j = i + 1; j <= bitl; ++j) {
s += (l >> (j - 1) & 1) + '0';
}
reverse(s.begin(), s.end());
build.push_back({s, i - 1});
++i;
}
}
//ts();
}
else {
for (int i = bitl + 1; i <= bitr - 1; ++i) {
build.push_back({"1", i - 1});
}
string s = "1";
for (int i = bitr - 1; i >= 1; --i) {
if ((r >> (i - 1)) & 1) {
build.push_back({s + '0', i - 1});
s += '1';
}
else {
s += '0';
}
}
build.push_back({s, 0});
int i = 1;
while (((l >> (i - 1)) & 1 ) != 1) i++;
s = "";
for (int j = i; j <= bitl; ++j) {
s += (l >> (j - 1) & 1) + '0';
}
reverse(s.begin(), s.end());
build.push_back({s, i - 1});
while (1) {
while (i <= bitl && ((l >> (i - 1)) & 1) == 1) i++;
if (i > bitl) break;
s = "1";
for (int j = i + 1; j <= bitl; ++j) {
s += (l >> (j - 1) & 1) + '0';
}
reverse(s.begin(), s.end());
build.push_back({s, i - 1});
++i;
}
//ts();
}
int tot = 1;
vector<int> id(21, -1);
int cnt = 104;
for (int i = 1; i <= 20; ++i) {
id[i] = ++cnt;
}
vector<array<int, 2>> shu(200000); //2e5//////
vector<array<int, 3>> sb;
int mx = 0;
for (auto [a, b] : build) {
//a 字典树
int res = 1;
for (int i = 0; i < (int)a.size() - 1; i++)
{
char c = a[i];
int x = c - '0';
// cerr << x << '\n';
if (!shu[res][x])
{
shu[res][x] = ++tot;
E[res].push_back({tot, x});
}
res = shu[res][x];
}
sb.push_back({res, b, a[(int)a.size() - 1] - '0'});
mx = max(b, mx);
}
///ts();
for (int i = 1; i <= mx; ++i) {
id[i] = ++tot;
}
for (int i = mx; i >= 2; --i) {
E[id[i]].push_back({id[i - 1], 0});
E[id[i]].push_back({id[i - 1], 1});
}
id[0] = ++tot;
if (id[1] != -1) {
E[id[1]].push_back({id[0], 0});
E[id[1]].push_back({id[0], 1});
}
for (auto [u, v, w] : sb) {
// cerr << w << '\n';
E[u].push_back({id[v], w});
}
cout << tot << '\n';
for (int i = 1; i <= tot; ++i) {
cout << E[i].size() << ' ';
for (auto [v, w] : E[i]) {
cout << v << ' ' << w << ' ';
}
cout << '\n';
}
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 4652kb
input:
5 7
output:
5 1 2 1 2 3 1 4 0 2 5 0 5 1 1 5 1 0
result:
ok ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 4652kb
input:
10 27
output:
10 1 2 1 4 3 1 6 0 9 0 8 1 1 4 0 2 5 1 7 0 2 10 0 10 1 1 7 1 2 10 0 10 1 2 7 0 7 1 2 8 0 8 1 0
result:
ok ok
Test #3:
score: 0
Accepted
time: 1ms
memory: 4652kb
input:
5 13
output:
8 1 2 1 4 3 1 5 0 7 0 6 1 1 4 0 2 8 0 8 1 1 8 1 2 8 0 8 1 2 6 0 6 1 0
result:
ok ok
Test #4:
score: 0
Accepted
time: 1ms
memory: 4628kb
input:
1 1000000
output:
39 20 2 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 2 3 1 38 0 2 4 1 37 0 2 5 1 36 0 1 6 0 2 7 1 34 0 1 8 0 1 9 0 1 10 0 1 11 0 2 12 1 29 0 1 13 0 1 14 0 2 15 1 26 0 1 16 0 1 17 0 1 18 0 1 19 0 1 20 0 1 39 0 2 39 0 39 1 2 21 0...
result:
ok ok
Test #5:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
1 1
output:
2 1 2 1 0
result:
ok ok
Test #6:
score: 0
Accepted
time: 1ms
memory: 4684kb
input:
7 9
output:
6 1 2 1 2 3 0 5 1 1 4 0 2 6 0 6 1 1 6 1 0
result:
ok ok
Test #7:
score: 0
Accepted
time: 1ms
memory: 4568kb
input:
3 7
output:
5 1 2 1 3 3 1 4 0 5 1 2 5 0 5 1 2 5 0 5 1 0
result:
ok ok
Test #8:
score: 0
Accepted
time: 1ms
memory: 4664kb
input:
1 5
output:
5 3 2 1 4 1 5 1 1 3 0 2 5 0 5 1 2 5 0 5 1 0
result:
ok ok
Test #9:
score: 0
Accepted
time: 1ms
memory: 4772kb
input:
1 4
output:
5 3 2 1 4 1 5 1 1 3 0 1 5 0 2 5 0 5 1 0
result:
ok ok
Test #10:
score: 0
Accepted
time: 1ms
memory: 4624kb
input:
8 9
output:
5 1 2 1 1 3 0 1 4 0 2 5 1 5 0 0
result:
ok ok
Test #11:
score: 0
Accepted
time: 0ms
memory: 4640kb
input:
7 51
output:
11 3 2 1 9 1 10 1 2 3 1 10 0 2 4 0 11 1 1 5 0 2 6 1 7 0 2 11 0 11 1 2 11 0 11 1 2 7 0 7 1 2 8 0 8 1 2 9 0 9 1 0
result:
ok ok
Test #12:
score: 0
Accepted
time: 1ms
memory: 4732kb
input:
51 79
output:
15 1 2 1 2 3 0 8 1 1 4 0 2 5 1 14 0 2 6 1 13 0 2 7 1 12 0 2 15 0 15 1 2 9 0 14 1 2 10 0 13 1 1 11 1 1 15 1 2 15 0 15 1 2 12 0 12 1 2 13 0 13 1 0
result:
ok ok
Test #13:
score: 0
Accepted
time: 1ms
memory: 4732kb
input:
92 99
output:
14 1 2 1 2 3 1 8 0 1 4 0 1 5 0 1 6 0 2 7 1 13 0 2 14 0 14 1 1 9 1 1 10 1 1 11 1 2 12 0 13 1 2 14 0 14 1 2 14 0 14 1 0
result:
ok ok
Test #14:
score: 0
Accepted
time: 1ms
memory: 4656kb
input:
27 36
output:
12 1 2 1 2 3 0 7 1 1 4 0 2 5 1 11 0 1 6 0 1 12 0 2 8 0 11 1 1 9 1 1 12 1 2 12 0 12 1 2 10 0 10 1 0
result:
ok ok
Test #15:
score: 0
Accepted
time: 1ms
memory: 4796kb
input:
55 84
output:
16 1 2 1 2 3 0 8 1 2 4 1 15 0 1 5 0 2 6 1 13 0 1 7 0 1 16 0 2 9 0 14 1 1 10 1 1 11 1 1 16 1 2 16 0 16 1 2 12 0 12 1 2 13 0 13 1 2 14 0 14 1 0
result:
ok ok
Test #16:
score: 0
Accepted
time: 1ms
memory: 4704kb
input:
297208 929600
output:
53 1 2 1 4 3 1 21 0 52 0 51 1 2 4 1 51 0 1 5 0 1 6 0 1 7 0 2 8 1 47 0 1 9 0 2 10 1 45 0 2 11 1 44 0 2 12 1 43 0 2 13 1 42 0 1 14 0 2 15 1 40 0 1 16 0 1 17 0 1 18 0 1 19 0 1 20 0 1 53 0 2 22 0 50 1 1 23 1 2 24 0 48 1 2 25 0 47 1 2 26 0 46 1 1 27 1 2 28 0 44 1 2 29 0 43 1 2...
result:
ok ok
Test #17:
score: 0
Accepted
time: 1ms
memory: 4636kb
input:
45728 589156
output:
47 4 2 1 44 1 45 1 46 1 2 3 0 42 1 2 4 0 21 1 1 5 0 2 6 1 43 0 2 7 1 42 0 2 8 1 41 0 2 9 1 40 0 2 10 1 39 0 2 11 1 38 0 1 12 0 2 13 1 36 0 1 14 0 2 15 1 34 0 2 16 1 33 0 1 17 0 1 18 0 2 19 1 30 0 1 20 0 1 47 0 1 22 1 2 23 0 39 1 2 24 0 38 1 1 25 1 2 26 0 36 1 1 27 1 2 28 0 ...
result:
ok ok
Test #18:
score: 0
Accepted
time: 1ms
memory: 4640kb
input:
129152 138000
output:
39 1 2 1 2 3 0 19 1 1 4 0 1 5 0 1 6 0 2 7 1 38 0 2 8 1 37 0 1 9 0 2 10 1 35 0 2 11 1 34 0 1 12 0 1 13 0 1 14 0 2 15 1 30 0 1 16 0 1 17 0 1 18 0 1 39 0 1 20 1 1 21 1 1 22 1 1 23 1 2 24 0 36 1 2 25 0 35 1 2 26 0 34 1 1 33 1 2 39 0 39 1 2 27 0 27 1 2 28 0 28 1 2 29 0 29 1 ...
result:
ok ok
Test #19:
score: 0
Accepted
time: 1ms
memory: 4732kb
input:
245280 654141
output:
50 2 2 1 49 1 2 3 0 21 1 1 4 0 2 5 1 47 0 2 6 1 46 0 2 7 1 45 0 2 8 1 44 0 2 9 1 43 0 2 10 1 42 0 1 11 0 2 12 1 40 0 2 13 1 39 0 1 14 0 1 15 0 2 16 1 36 0 2 17 1 35 0 2 18 1 34 0 2 19 1 33 0 1 20 0 2 50 0 50 1 1 22 1 2 23 0 45 1 1 24 1 1 25 1 1 26 1 1 27 1 1 28 1 2 29 0 39...
result:
ok ok
Test #20:
score: 0
Accepted
time: 1ms
memory: 4640kb
input:
202985 296000
output:
51 1 2 1 2 3 0 20 1 1 4 0 2 5 1 50 0 1 6 0 1 7 0 1 8 0 1 9 0 2 10 1 45 0 1 11 0 1 12 0 1 13 0 2 14 1 41 0 1 15 0 1 16 0 1 17 0 1 18 0 1 19 0 1 51 0 2 21 0 50 1 2 22 0 49 1 2 23 0 48 1 1 24 1 1 25 1 2 26 0 45 1 2 27 0 44 1 2 28 0 43 1 1 29 1 1 30 1 1 31 1 2 32 0 39 1 1 ...
result:
ok ok
Test #21:
score: 0
Accepted
time: 0ms
memory: 4628kb
input:
438671 951305
output:
55 1 2 1 2 3 1 54 0 4 4 1 21 0 53 0 52 1 1 5 0 2 6 1 51 0 1 7 0 1 8 0 1 9 0 1 10 0 2 11 1 46 0 1 12 0 1 13 0 1 14 0 1 15 0 1 16 0 1 17 0 2 18 1 39 0 1 19 0 1 20 0 2 55 0 55 1 1 22 1 2 23 0 50 1 1 24 1 1 25 1 2 26 0 47 1 2 27 0 46 1 2 28 0 45 1 1 29 1 1 30 1 2 31 0 42 1 ...
result:
ok ok
Test #22:
score: 0
Accepted
time: 0ms
memory: 4628kb
input:
425249 739633
output:
55 1 2 1 2 3 0 21 1 2 4 1 54 0 2 5 1 53 0 1 6 0 2 7 1 51 0 1 8 0 1 9 0 2 10 1 48 0 1 11 0 1 12 0 2 13 1 45 0 1 14 0 1 15 0 2 16 1 42 0 2 17 1 41 0 1 18 0 1 19 0 1 20 0 2 55 0 55 1 2 22 0 53 1 2 23 0 52 1 1 24 1 1 25 1 1 26 1 1 27 1 1 28 1 2 29 0 46 1 1 30 1 2 31 0 44 1 ...
result:
ok ok
Test #23:
score: 0
Accepted
time: 1ms
memory: 4632kb
input:
551207 961718
output:
56 1 2 1 2 3 1 21 0 2 4 1 55 0 1 5 0 2 6 1 53 0 1 7 0 2 8 1 51 0 1 9 0 2 10 1 49 0 2 11 1 48 0 1 12 0 1 13 0 2 14 1 45 0 1 15 0 2 16 1 43 0 2 17 1 42 0 1 18 0 2 19 1 40 0 2 20 1 39 0 1 56 0 2 22 0 55 1 2 23 0 54 1 2 24 0 53 1 1 25 1 1 26 1 2 27 0 50 1 1 28 1 2 29 0 48 1 2...
result:
ok ok
Test #24:
score: 0
Accepted
time: 1ms
memory: 4652kb
input:
114691 598186
output:
54 3 2 1 52 1 53 1 2 3 0 21 1 1 4 0 2 5 1 51 0 1 6 0 1 7 0 2 8 1 48 0 1 9 0 1 10 0 1 11 0 1 12 0 1 13 0 2 14 1 42 0 1 15 0 2 16 1 40 0 1 17 0 2 18 1 38 0 1 19 0 2 20 1 36 0 1 54 0 1 22 1 2 23 0 48 1 2 24 0 47 1 2 25 0 46 1 2 26 0 45 1 2 27 0 44 1 2 28 0 43 1 2 29 0 42 1 2...
result:
ok ok
Test #25:
score: 0
Accepted
time: 1ms
memory: 4648kb
input:
234654 253129
output:
46 1 2 1 1 3 1 1 4 1 2 5 1 19 0 1 6 0 2 7 1 44 0 2 8 1 43 0 2 9 1 42 0 1 10 0 1 11 0 2 12 1 39 0 2 13 1 38 0 1 14 0 1 15 0 2 16 1 35 0 1 17 0 1 18 0 2 46 0 46 1 2 20 0 45 1 1 21 1 2 22 0 43 1 1 23 1 2 24 0 41 1 2 25 0 40 1 1 26 1 2 27 0 38 1 2 28 0 37 1 1 29 1 1 30 1 1 3...
result:
ok ok
Test #26:
score: 0
Accepted
time: 1ms
memory: 4772kb
input:
554090 608599
output:
52 1 2 1 1 3 0 1 4 0 2 5 1 21 0 1 6 0 2 7 1 50 0 1 8 0 1 9 0 2 10 1 47 0 1 11 0 1 12 0 2 13 1 44 0 1 14 0 2 15 1 42 0 1 16 0 2 17 1 40 0 1 18 0 2 19 1 38 0 2 20 1 37 0 2 52 0 52 1 2 22 0 51 1 1 23 1 1 24 1 1 25 1 2 26 0 47 1 1 27 1 2 28 0 45 1 2 29 0 44 1 2 30 0 43 1 1 3...
result:
ok ok
Extra Test:
score: 0
Extra Test Passed