QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#684926 | #9519. Build a Computer | Rilllo | AC ✓ | 0ms | 3856kb | C++23 | 3.3kb | 2024-10-28 16:38:47 | 2024-10-28 16:38:48 |
Judging History
answer
// https://qoj.ac/contest/1817/problem/9519
// Build a Computer
#include<bits/stdc++.h>
using i64 = long long;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout << std::fixed << std::setprecision(10);
int L, R;
std::cin >> L >> R;
int tot = 1;
std::vector<int> sz;
std::vector<std::array<int, 2>> ch;
sz.push_back(0);
ch.push_back({-1, -1});
tot = 1;
auto add = [&](int x) {
int cur = 0;
sz[cur]++;
for (int j = 20; j >= 0; j--) {
int t = (x >> j & 1);
if (ch[cur][t] == -1) {
sz.push_back(0);
ch.push_back({-1, -1});
ch[cur][t] = tot++;
}
cur = ch[cur][t];
sz[cur]++;
}
};
add(L);
add(R);
// int x = 0;
// std::queue<std::pair<int, int>> q;
// q.push({0, 0});
// while (!q.empty()) {
// auto [x, val] = q.front();
// q.pop();
// if (ch[x][0] != -1) {
// q.emplace(ch[x][0], val * 2);
// }
// if (ch[x][1] != -1) {
// q.emplace(ch[x][1], val * 2 + 1);
// }
// if (ch[x][0] == -1 && ch[x][1] == -1) {
// std::cout << val << "\n";
// }
// }
// edge
int mx = 0;
auto findmx = [&](int x, int tp) {
int cur = 0;
for (int j = 20; j >= 0; j--) {
int t = (x >> j & 1);
if (sz[cur] == 1 && t == tp) {
mx = std::max(mx, j);
}
cur = ch[cur][t];
}
};
findmx(L, 0);
findmx(R, 1);
// std::cout << mx << "\n";
std::vector<int> vis(tot);
tot = mx + 1;
std::vector<std::vector<std::pair<int, int>>> adj(tot);
for (int i = tot - 1; i > 0; i--) {
adj[i].push_back({i - 1, 0});
adj[i].push_back({i - 1, 1});
}
int s = tot++;
adj.resize(tot);
std::map<int, int> mp;
auto last = [&](int x, int tp) {
int cur = 0;
int p = s;
mp[cur] = s;
vis[cur] = 1;
for (int j = 20; j >= 0; j--) {
int t = (x >> j & 1);
int y = ch[cur][t];
// std::cout << cur << " " << ch[cur][0] << " " << ch[cur][1] << " " << sz[cur] << "\n";
if (sz[cur] == 1 && t == tp) {
// std::cout << "!";
adj[p].push_back({j, (t ^ 1)});
}
if (ch[y] == std::array<int, 2>{-1, -1}) {
adj[p].emplace_back(0, t);
break;
}
if (vis[ch[cur][t]] == 0 && (t || p != s)) {
tot++;
mp[ch[cur][t]] = tot - 1;
adj.resize(tot);
adj[p].emplace_back(tot - 1, t);
}
cur = ch[cur][t];
vis[cur] = 1;
if (p != s || t == 1) {
p = mp[cur];
}
}
};
last(L, 0);
if (L != R)
last(R, 1);
// return 0;
std::cout << tot << "\n";
for (int i = 0; i < tot; i++) {
std::cout << adj[i].size() << " ";
for (auto [y, w] : adj[i]) {
std::cout << y + 1 << " " << w << " ";
}
std::cout << "\n";
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3844kb
input:
5 7
output:
5 0 1 3 1 2 4 0 5 1 1 1 1 2 1 0 1 1
result:
ok ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
10 27
output:
12 0 2 1 0 1 1 2 2 0 2 1 2 3 0 3 1 2 6 1 9 1 2 3 1 7 0 1 8 1 2 1 1 1 0 2 4 0 10 1 1 11 0 2 2 0 12 1 2 1 0 1 1
result:
ok ok
Test #3:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
5 13
output:
9 0 2 1 0 1 1 2 2 0 2 1 2 5 1 7 1 2 2 1 6 0 1 1 1 2 3 0 8 1 1 9 0 2 1 0 1 1
result:
ok ok
Test #4:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
1 1000000
output:
39 0 2 1 0 1 1 2 2 0 2 1 2 3 0 3 1 2 4 0 4 1 2 5 0 5 1 2 6 0 6 1 2 7 0 7 1 2 8 0 8 1 2 9 0 9 1 2 10 0 10 1 2 11 0 11 1 2 12 0 12 1 2 13 0 13 1 2 14 0 14 1 2 15 0 15 1 2 16 0 16 1 2 17 0 17 1 2 18 0 18 1 20 19 1 18 1 17 1 16 1 15 1 14 1 13 1 12 1 11 1 10 1 9 1 8 1 7 1 6 1 5 1 4 1 3...
result:
ok ok
Test #5:
score: 0
Accepted
time: 0ms
memory: 3852kb
input:
1 1
output:
2 0 1 1 1
result:
ok ok
Test #6:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
7 9
output:
7 0 2 3 1 5 1 1 4 1 1 1 1 1 6 0 1 7 0 2 1 0 1 1
result:
ok ok
Test #7:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
3 7
output:
6 0 2 1 0 1 1 2 4 1 5 1 1 1 1 2 2 0 6 1 2 1 0 1 1
result:
ok ok
Test #8:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
1 5
output:
5 0 2 1 0 1 1 3 2 1 1 1 4 1 1 5 0 2 1 0 1 1
result:
ok ok
Test #9:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
1 4
output:
5 0 2 1 0 1 1 3 2 1 1 1 4 1 1 5 0 1 1 0
result:
ok ok
Test #10:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
8 9
output:
5 0 1 3 1 1 4 0 1 5 0 2 1 0 1 1
result:
ok ok
Test #11:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
7 51
output:
13 0 2 1 0 1 1 2 2 0 2 1 2 3 0 3 1 2 4 0 4 1 4 5 1 4 1 7 1 9 1 1 8 1 1 1 1 2 5 0 10 1 1 11 0 1 12 0 2 2 0 13 1 2 1 0 1 1
result:
ok ok
Test #12:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
51 79
output:
16 0 2 1 0 1 1 2 2 0 2 1 2 3 0 3 1 2 6 1 11 1 1 7 1 2 4 1 8 0 2 3 1 9 0 1 10 1 1 1 1 1 12 0 1 13 0 2 4 0 14 1 2 3 0 15 1 2 2 0 16 1 2 1 0 1 1
result:
ok ok
Test #13:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
92 99
output:
14 0 2 1 0 1 1 1 4 1 2 5 0 10 1 1 6 1 1 7 1 1 8 1 2 2 1 9 0 2 1 1 1 0 1 11 0 1 12 0 1 13 0 2 2 0 14 1 2 1 0 1 1
result:
ok ok
Test #14:
score: 0
Accepted
time: 0ms
memory: 3500kb
input:
27 36
output:
13 0 2 1 0 1 1 2 2 0 2 1 2 5 1 9 1 1 6 1 2 3 1 7 0 1 8 1 1 1 1 1 10 0 1 11 0 2 3 0 12 1 1 13 0 1 1 0
result:
ok ok
Test #15:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
55 84
output:
17 0 2 1 0 1 1 2 2 0 2 1 2 3 0 3 1 2 4 0 4 1 2 7 1 12 1 1 8 1 2 4 1 9 0 1 10 1 1 11 1 1 1 1 1 13 0 2 5 0 14 1 1 15 0 2 3 0 16 1 1 17 0 1 1 0
result:
ok ok
Test #16:
score: 0
Accepted
time: 0ms
memory: 3856kb
input:
297208 929600
output:
57 0 2 1 0 1 1 2 2 0 2 1 2 3 0 3 1 2 4 0 4 1 2 5 0 5 1 2 6 0 6 1 2 7 0 7 1 2 8 0 8 1 2 9 0 9 1 2 10 0 10 1 2 11 0 11 1 2 12 0 12 1 2 13 0 13 1 2 14 0 14 1 2 15 0 15 1 2 16 0 16 1 2 17 0 17 1 2 18 0 18 1 2 21 1 39 1 2 18 1 22 0 2 17 1 23 0 1 24 1 2 15 1 25 0 2 14 1 26 0 2 13 ...
result:
ok ok
Test #17:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
45728 589156
output:
54 0 2 1 0 1 1 2 2 0 2 1 2 3 0 3 1 2 4 0 4 1 2 5 0 5 1 2 6 0 6 1 2 7 0 7 1 2 8 0 8 1 2 9 0 9 1 2 10 0 10 1 2 11 0 11 1 2 12 0 12 1 2 13 0 13 1 2 14 0 14 1 2 15 0 15 1 2 16 0 16 1 2 17 0 17 1 2 18 0 18 1 5 19 1 18 1 17 1 21 1 36 1 2 15 1 22 0 1 23 1 1 24 1 2 12 1 25 0 2 11 1 2...
result:
ok ok
Test #18:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
129152 138000
output:
47 0 2 1 0 1 1 2 2 0 2 1 2 3 0 3 1 2 4 0 4 1 2 5 0 5 1 2 6 0 6 1 2 7 0 7 1 2 8 0 8 1 2 9 0 9 1 2 10 0 10 1 2 11 0 11 1 2 12 0 12 1 2 15 1 31 1 1 16 1 1 17 1 1 18 1 1 19 1 1 20 1 2 11 1 21 0 2 10 1 22 0 2 9 1 23 0 1 24 1 2 7 1 25 0 2 6 1 26 0 2 5 1 27 0 2 4 1 28 0 2 3 1 29 ...
result:
ok ok
Test #19:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
245280 654141
output:
56 0 2 1 0 1 1 2 2 0 2 1 2 3 0 3 1 2 4 0 4 1 2 5 0 5 1 2 6 0 6 1 2 7 0 7 1 2 8 0 8 1 2 9 0 9 1 2 10 0 10 1 2 11 0 11 1 2 12 0 12 1 2 13 0 13 1 2 14 0 14 1 2 15 0 15 1 2 16 0 16 1 2 17 0 17 1 2 18 0 18 1 3 19 1 21 1 38 1 1 22 1 1 23 1 2 15 1 24 0 1 25 1 1 26 1 1 27 1 1 28 1 ...
result:
ok ok
Test #20:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
202985 296000
output:
52 0 2 1 0 1 1 2 2 0 2 1 2 3 0 3 1 2 4 0 4 1 2 5 0 5 1 2 6 0 6 1 2 7 0 7 1 2 8 0 8 1 2 9 0 9 1 2 10 0 10 1 2 11 0 11 1 2 12 0 12 1 2 13 0 13 1 2 14 0 14 1 2 15 0 15 1 2 18 1 35 1 1 19 1 2 16 1 20 0 2 15 1 21 0 2 14 1 22 0 1 23 1 1 24 1 2 11 1 25 0 2 10 1 26 0 2 9 1 27 0 1 2...
result:
ok ok
Test #21:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
438671 951305
output:
57 0 2 1 0 1 1 2 2 0 2 1 2 3 0 3 1 2 4 0 4 1 2 5 0 5 1 2 6 0 6 1 2 7 0 7 1 2 8 0 8 1 2 9 0 9 1 2 10 0 10 1 2 11 0 11 1 2 12 0 12 1 2 13 0 13 1 2 14 0 14 1 2 15 0 15 1 2 16 0 16 1 2 17 0 17 1 2 18 0 18 1 2 21 1 39 1 1 22 1 2 17 1 23 0 1 24 1 2 15 1 25 0 1 26 1 1 27 1 2 12 1 ...
result:
ok ok
Test #22:
score: 0
Accepted
time: 0ms
memory: 3500kb
input:
425249 739633
output:
56 0 2 1 0 1 1 2 2 0 2 1 2 3 0 3 1 2 4 0 4 1 2 5 0 5 1 2 6 0 6 1 2 7 0 7 1 2 8 0 8 1 2 9 0 9 1 2 10 0 10 1 2 11 0 11 1 2 12 0 12 1 2 13 0 13 1 2 14 0 14 1 2 15 0 15 1 2 16 0 16 1 2 17 0 17 1 2 20 1 38 1 1 21 1 2 17 1 22 0 2 16 1 23 0 1 24 1 1 25 1 1 26 1 1 27 1 1 28 1 2 10...
result:
ok ok
Test #23:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
551207 961718
output:
56 0 2 1 0 1 1 2 2 0 2 1 2 3 0 3 1 2 4 0 4 1 2 5 0 5 1 2 6 0 6 1 2 7 0 7 1 2 8 0 8 1 2 9 0 9 1 2 10 0 10 1 2 11 0 11 1 2 12 0 12 1 2 13 0 13 1 2 14 0 14 1 2 15 0 15 1 2 16 0 16 1 2 17 0 17 1 1 20 1 2 21 0 39 1 2 18 1 22 0 2 17 1 23 0 2 16 1 24 0 1 25 1 1 26 1 2 13 1 27 0 1 ...
result:
ok ok
Test #24:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
114691 598186
output:
55 0 2 1 0 1 1 2 2 0 2 1 2 3 0 3 1 2 4 0 4 1 2 5 0 5 1 2 6 0 6 1 2 7 0 7 1 2 8 0 8 1 2 9 0 9 1 2 10 0 10 1 2 11 0 11 1 2 12 0 12 1 2 13 0 13 1 2 14 0 14 1 2 15 0 15 1 2 16 0 16 1 2 17 0 17 1 2 18 0 18 1 4 19 1 18 1 21 1 37 1 1 22 1 1 23 1 2 14 1 24 0 2 13 1 25 0 2 12 1 26 0 ...
result:
ok ok
Test #25:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
234654 253129
output:
46 0 2 1 0 1 1 2 2 0 2 1 2 3 0 3 1 2 4 0 4 1 2 5 0 5 1 2 6 0 6 1 2 7 0 7 1 2 8 0 8 1 2 9 0 9 1 2 10 0 10 1 2 11 0 11 1 2 12 0 12 1 2 13 0 13 1 1 16 1 1 17 1 1 18 1 2 19 0 33 1 2 14 1 20 0 1 21 1 2 12 1 22 0 1 23 1 2 10 1 24 0 2 9 1 25 0 1 26 1 2 7 1 27 0 2 6 1 28 0 1 29 1 ...
result:
ok ok
Test #26:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
554090 608599
output:
52 0 2 1 0 1 1 2 2 0 2 1 2 3 0 3 1 2 4 0 4 1 2 5 0 5 1 2 6 0 6 1 2 7 0 7 1 2 8 0 8 1 2 9 0 9 1 2 10 0 10 1 2 11 0 11 1 2 12 0 12 1 2 13 0 13 1 2 14 0 14 1 2 15 0 15 1 1 18 1 1 19 0 1 20 0 2 21 0 37 1 2 16 1 22 0 1 23 1 1 24 1 1 25 1 2 12 1 26 0 1 27 1 2 10 1 28 0 2 9 1 29 ...
result:
ok ok
Extra Test:
score: 0
Extra Test Passed