QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#729130 | #9519. Build a Computer | complexor | AC ✓ | 1ms | 3892kb | C++20 | 2.5kb | 2024-11-09 16:32:00 | 2024-11-09 16:32:05 |
Judging History
answer
#include <bits/stdc++.h>
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef __int128 LLL;
typedef std::pair<int, int> pii;
typedef std::pair<int, LL> pil;
typedef std::pair<LL, int> pli;
typedef std::pair<LL, LL> pll;
#define fi first
#define se second
#define MP std::make_pair
LL read()
{
LL s = 0; int f = 1;
char c = getchar();
while (!(c >= '0' && c <= '9'))
f ^= (c == '-'), c = getchar();
while (c >= '0' && c <= '9')
s = s * 10 + (c ^ 48), c = getchar();
return f ? s : -s;
}
template<typename T> void write(T x, char end = '\n')
{
static int d[100], cur = 0;
do{ d[++cur] = x % 10; } while (x /= 10);
while (cur) putchar('0' + d[cur--]);
putchar(end);
}
const int MAXN = 100005, inf = 0x3f3f3f3f, MAXV = 1000006, MAXP = 400005, MAXS = 6000006, V = 59;
const LL INF = 0x1f3f3f3f3f3f3f3fll;
const int MOD = 998244353;
auto fplus = [](int x, int y){ return x + y >= MOD ? x + y - MOD : x + y; };
auto fminus = [](int x, int y){ return x >= y ? x - y : x + MOD - y; };
auto Fplus = [](int &x, int y){ return x = fplus(x, y); };
auto Fminus = [](int &x, int y){ return x = fminus(x, y); };
template<typename T> T& Fmax(T& x, T y){ return x = x < y ? y : x; };
template<typename T> T& Fmin(T& x, T y){ return x = x < y ? x : y; };
int L, R, n, m, id[100];
std::vector<pii> e[MAXN];
int tran(int x, int o)
{
for (pii p : e[x])
if (o == p.se) return p.fi;
e[x].emplace_back(++n, o); return n;
}
void dfs(int x, int l, int r, int d, bool zero)
{
if (!l && r == (1 << (d + 1)) - 1)
{
for (; m <= d; m++)
id[m] = ++n, e[id[m]].emplace_back(id[m - 1], 0), e[id[m]].emplace_back(id[m - 1], 1);
e[x].emplace_back(id[d], 0), e[x].emplace_back(id[d], 1);
return ;
}
if (!d) return e[x].emplace_back(id[0], l), void();
int lo = l >> d & 1, ro = r >> d & 1;
int ll = l ^ (lo << d), rr = r ^ (ro << d);
if (lo == ro)
{
if (lo || !zero) e[x].emplace_back(++n, lo), dfs(n, ll, rr, d - 1, 0);
else dfs(x, ll, rr, d - 1, 1);
}
else
{
int mid = (1 << d) - 1;
if (zero) dfs(x, ll, mid, d - 1, 1);
else e[x].emplace_back(++n, 0), dfs(n, ll, mid, d - 1, 0);
e[x].emplace_back(++n, 1), dfs(n, 0, rr, d - 1, 0);
}
}
int main()
{
L = read(), R = read();
n = 2, m = 1, id[0] = 2, dfs(1, L, R, 19, 1);
printf("%d\n", n);
for (int i = 1; i <= n; i++)
{
printf("%d ", e[i].size());
for (pii p : e[i]) printf("%d %d ", p.fi, p.se);
putchar('\n');
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3788kb
input:
5 7
output:
5 1 3 1 0 2 4 0 5 1 1 2 1 2 2 0 2 1
result:
ok ok
Test #2:
score: 0
Accepted
time: 1ms
memory: 3892kb
input:
10 27
output:
12 2 3 1 8 1 0 2 4 0 6 1 1 5 1 2 2 0 2 1 2 7 0 7 1 2 2 0 2 1 2 9 0 11 1 2 10 0 10 1 2 7 0 7 1 1 12 0 2 7 0 7 1
result:
ok ok
Test #3:
score: 0
Accepted
time: 1ms
memory: 3764kb
input:
5 13
output:
10 2 3 1 6 1 0 2 4 0 5 1 1 2 1 2 2 0 2 1 2 7 0 9 1 2 8 0 8 1 2 2 0 2 1 1 10 0 2 2 0 2 1
result:
ok ok
Test #4:
score: 0
Accepted
time: 1ms
memory: 3848kb
input:
1 1000000
output:
62 20 2 1 3 1 4 1 6 1 8 1 10 1 12 1 14 1 16 1 18 1 20 1 22 1 24 1 26 1 28 1 30 1 32 1 34 1 36 1 38 1 0 2 2 0 2 1 2 5 0 5 1 2 2 0 2 1 2 7 0 7 1 2 5 0 5 1 2 9 0 9 1 2 7 0 7 1 2 11 0 11 1 2 9 0 9 1 2 13 0 13 1 2 11 0 11 1 2 15 0 15 1 2 13 0 13 1 2 17 0 17 1 2 15 0 15 1 2 19 0 19 1 2 1...
result:
ok ok
Test #5:
score: 0
Accepted
time: 1ms
memory: 3836kb
input:
1 1
output:
2 1 2 1 0
result:
ok ok
Test #6:
score: 0
Accepted
time: 1ms
memory: 3840kb
input:
7 9
output:
7 2 3 1 5 1 0 1 4 1 1 2 1 1 6 0 1 7 0 2 2 0 2 1
result:
ok ok
Test #7:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
3 7
output:
5 2 3 1 4 1 0 1 2 1 2 5 0 5 1 2 2 0 2 1
result:
ok ok
Test #8:
score: 0
Accepted
time: 1ms
memory: 3756kb
input:
1 5
output:
5 3 2 1 3 1 4 1 0 2 2 0 2 1 1 5 0 2 2 0 2 1
result:
ok ok
Test #9:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
1 4
output:
5 3 2 1 3 1 4 1 0 2 2 0 2 1 1 5 0 1 2 0
result:
ok ok
Test #10:
score: 0
Accepted
time: 1ms
memory: 3748kb
input:
8 9
output:
5 1 3 1 0 1 4 0 1 5 0 2 2 0 2 1
result:
ok ok
Test #11:
score: 0
Accepted
time: 1ms
memory: 3840kb
input:
7 51
output:
14 4 3 1 5 1 8 1 10 1 0 1 4 1 1 2 1 2 7 0 7 1 2 2 0 2 1 2 6 0 6 1 2 9 0 9 1 2 7 0 7 1 2 11 0 12 1 2 9 0 9 1 1 13 0 1 14 0 2 6 0 6 1
result:
ok ok
Test #12:
score: 0
Accepted
time: 1ms
memory: 3776kb
input:
51 79
output:
15 2 3 1 12 1 0 1 4 1 2 5 0 10 1 2 6 0 8 1 1 7 1 1 2 1 2 9 0 9 1 2 2 0 2 1 2 11 0 11 1 2 9 0 9 1 1 13 0 1 14 0 2 15 0 15 1 2 11 0 11 1
result:
ok ok
Test #13:
score: 0
Accepted
time: 1ms
memory: 3844kb
input:
92 99
output:
12 1 3 1 0 2 4 0 9 1 1 5 1 1 6 1 1 7 1 2 8 0 8 1 2 2 0 2 1 1 10 0 1 11 0 1 12 0 2 8 0 8 1
result:
ok ok
Test #14:
score: 0
Accepted
time: 1ms
memory: 3836kb
input:
27 36
output:
14 2 3 1 9 1 0 1 4 1 2 5 0 7 1 1 6 1 1 2 1 2 8 0 8 1 2 2 0 2 1 1 10 0 1 11 0 2 12 0 13 1 2 8 0 8 1 1 14 0 1 2 0
result:
ok ok
Test #15:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
55 84
output:
19 2 3 1 11 1 0 1 4 1 2 5 0 8 1 1 6 1 1 7 1 1 2 1 2 10 0 10 1 2 2 0 2 1 2 9 0 9 1 1 12 0 2 13 0 15 1 2 14 0 14 1 2 10 0 10 1 1 16 0 2 17 0 18 1 2 9 0 9 1 1 19 0 1 2 0
result:
ok ok
Test #16:
score: 0
Accepted
time: 1ms
memory: 3844kb
input:
297208 929600
output:
70 2 3 1 43 1 0 2 4 0 41 1 2 5 0 38 1 1 6 1 2 7 0 36 1 2 8 0 34 1 2 9 0 31 1 1 10 1 2 11 0 29 1 2 12 0 27 1 2 13 0 21 1 1 14 1 1 15 1 1 16 1 1 17 1 1 18 1 2 20 0 20 1 2 2 0 2 1 2 19 0 19 1 2 26 0 26 1 2 20 0 20 1 2 22 0 22 1 2 23 0 23 1 2 24 0 24 1 2 25 0 25 1 2 28 0 28 1 ...
result:
ok ok
Test #17:
score: 0
Accepted
time: 1ms
memory: 3840kb
input:
45728 589156
output:
67 5 3 1 32 1 35 1 37 1 39 1 0 2 4 0 28 1 1 5 1 1 6 1 2 7 0 26 1 2 8 0 23 1 1 9 1 2 10 0 20 1 1 11 1 2 12 0 18 1 1 13 1 2 17 0 17 1 2 2 0 2 1 2 14 0 14 1 2 15 0 15 1 2 16 0 16 1 2 19 0 19 1 2 17 0 17 1 2 22 0 22 1 2 19 0 19 1 2 21 0 21 1 2 25 0 25 1 2 22 0 22 1 2 24 0 24 1 2...
result:
ok ok
Test #18:
score: 0
Accepted
time: 1ms
memory: 3832kb
input:
129152 138000
output:
48 2 3 1 25 1 0 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 2 9 0 23 1 2 10 0 21 1 2 11 0 19 1 1 12 1 2 18 0 18 1 2 2 0 2 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 0 20 1 2 18 0 18 1 2 22 0 22 1 2 20 0 20 1 2 24 0 24 1 2 22 0 22 1 1 26 0 1 27 0 1 28 0 1 29 0 2 ...
result:
ok ok
Test #19:
score: 0
Accepted
time: 1ms
memory: 3848kb
input:
245280 654141
output:
68 3 3 1 33 1 38 1 0 1 4 1 1 5 1 2 6 0 26 1 1 7 1 1 8 1 1 9 1 1 10 1 1 11 1 2 12 0 24 1 2 13 0 22 1 2 14 0 20 1 1 15 1 2 19 0 19 1 2 2 0 2 1 2 16 0 16 1 2 17 0 17 1 2 18 0 18 1 2 21 0 21 1 2 19 0 19 1 2 23 0 23 1 2 21 0 21 1 2 25 0 25 1 2 23 0 23 1 2 32 0 32 1 2 25 0 25 1 ...
result:
ok ok
Test #20:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
202985 296000
output:
63 2 3 1 43 1 0 1 4 1 2 5 0 41 1 2 6 0 39 1 2 7 0 35 1 1 8 1 1 9 1 2 10 0 33 1 2 11 0 31 1 2 12 0 26 1 1 13 1 1 14 1 1 15 1 2 16 0 23 1 1 17 1 2 18 0 21 1 2 19 0 20 1 1 2 1 2 2 0 2 1 2 22 0 22 1 2 2 0 2 1 2 25 0 25 1 2 22 0 22 1 2 24 0 24 1 2 30 0 30 1 2 25 0 25 1 2 27 0 2...
result:
ok ok
Test #21:
score: 0
Accepted
time: 1ms
memory: 3776kb
input:
438671 951305
output:
69 2 3 1 44 1 0 1 4 1 2 5 0 41 1 1 6 1 2 7 0 37 1 1 8 1 1 9 1 2 10 0 35 1 2 11 0 33 1 2 12 0 29 1 1 13 1 1 14 1 2 15 0 27 1 2 16 0 25 1 2 17 0 21 1 1 18 1 1 19 1 1 20 1 1 2 1 2 24 0 24 1 2 2 0 2 1 2 22 0 22 1 2 23 0 23 1 2 26 0 26 1 2 24 0 24 1 2 28 0 28 1 2 26 0 26 1 2 3...
result:
ok ok
Test #22:
score: 0
Accepted
time: 1ms
memory: 3816kb
input:
425249 739633
output:
71 2 3 1 45 1 0 1 4 1 2 5 0 43 1 2 6 0 36 1 1 7 1 1 8 1 1 9 1 1 10 1 1 11 1 2 12 0 33 1 1 13 1 2 14 0 31 1 2 15 0 28 1 1 16 1 2 17 0 26 1 2 18 0 24 1 2 19 0 22 1 2 20 0 21 1 1 2 1 2 2 0 2 1 2 23 0 23 1 2 2 0 2 1 2 25 0 25 1 2 23 0 23 1 2 27 0 27 1 2 25 0 25 1 2 30 0 30 1 ...
result:
ok ok
Test #23:
score: 0
Accepted
time: 1ms
memory: 3792kb
input:
551207 961718
output:
75 1 3 1 0 2 4 0 48 1 2 5 0 46 1 2 6 0 44 1 2 7 0 40 1 1 8 1 1 9 1 2 10 0 37 1 1 11 1 2 12 0 35 1 2 13 0 32 1 1 14 1 2 15 0 30 1 2 16 0 27 1 1 17 1 2 18 0 25 1 2 19 0 22 1 1 20 1 1 21 1 1 2 1 2 24 0 24 1 2 2 0 2 1 2 23 0 23 1 2 26 0 26 1 2 24 0 24 1 2 29 0 29 1 2 26 0 26 1...
result:
ok ok
Test #24:
score: 0
Accepted
time: 1ms
memory: 3780kb
input:
114691 598186
output:
74 4 3 1 43 1 48 1 50 1 0 1 4 1 1 5 1 2 6 0 41 1 2 7 0 39 1 2 8 0 37 1 2 9 0 35 1 2 10 0 33 1 2 11 0 31 1 2 12 0 29 1 2 13 0 27 1 2 14 0 25 1 2 15 0 23 1 2 16 0 21 1 2 17 0 19 1 1 18 1 1 2 1 2 20 0 20 1 2 2 0 2 1 2 22 0 22 1 2 20 0 20 1 2 24 0 24 1 2 22 0 22 1 2 26 0 26 1 2 ...
result:
ok ok
Test #25:
score: 0
Accepted
time: 1ms
memory: 3840kb
input:
234654 253129
output:
57 1 3 1 0 1 4 1 1 5 1 2 6 0 38 1 2 7 0 35 1 1 8 1 2 9 0 32 1 1 10 1 2 11 0 30 1 2 12 0 27 1 1 13 1 2 14 0 25 1 2 15 0 20 1 1 16 1 1 17 1 1 18 1 1 19 1 2 2 0 2 1 2 24 0 24 1 2 2 0 2 1 2 21 0 21 1 2 22 0 22 1 2 23 0 23 1 2 26 0 26 1 2 24 0 24 1 2 29 0 29 1 2 26 0 26 1 2 28...
result:
ok ok
Test #26:
score: 0
Accepted
time: 1ms
memory: 3836kb
input:
554090 608599
output:
61 1 3 1 0 1 4 0 1 5 0 2 6 0 43 1 2 7 0 38 1 1 8 1 1 9 1 1 10 1 2 11 0 35 1 1 12 1 2 13 0 33 1 2 14 0 31 1 2 15 0 27 1 1 16 1 1 17 1 2 18 0 24 1 1 19 1 2 20 0 22 1 1 21 1 2 2 0 2 1 2 23 0 23 1 2 2 0 2 1 2 26 0 26 1 2 23 0 23 1 2 25 0 25 1 2 30 0 30 1 2 26 0 26 1 2 28 0 28...
result:
ok ok
Extra Test:
score: 0
Extra Test Passed