QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#679087 | #9519. Build a Computer | ucup-team4435# | AC ✓ | 0ms | 3804kb | C++23 | 3.6kb | 2024-10-26 16:50:28 | 2024-10-26 16:50:29 |
Judging History
answer
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
#define rep1n(i, n) for (int i = 1; i <= (n); ++i)
#define repr(i, n) for (int i = (n) - 1; i >= 0; --i)
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define each(x, a) for (auto &x : a)
#define ar array
#define vec vector
#define range(i, n) rep(i, n)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pair<int, int>>;
using vvi = vector<vi>;
int Bit(int mask, int b) { return (mask >> b) & 1; }
template<class T>
bool ckmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template<class T>
bool ckmax(T &a, const T &b) {
if (b > a) {
a = b;
return true;
}
return false;
}
// [l, r)
template<typename T, typename F>
T FindFirstTrue(T l, T r, const F &predicat) {
--l;
while (r - l > 1) {
T mid = l + (r - l) / 2;
if (predicat(mid)) {
r = mid;
} else {
l = mid;
}
}
return r;
}
template<typename T, typename F>
T FindLastFalse(T l, T r, const F &predicat) {
return FindFirstTrue(l, r, predicat) - 1;
}
const int INFi = 1e9;
const ll INF = 2e18;
const int LG = 20;
void solve() {
int L, R; cin >> L >> R;
int s = 0;
int bit = 0;
while ((1 << bit) <= R) bit++;
bit--;
vector<vector<pair<int, int>>> g(bit + 2);
vector<int> oth = {bit + 1};
bool eq = true;
int from = 0;
int bb = 0;
auto Get = [&] (int t) {
while (oth.size() <= t) {
int k = oth.size();
int who = g.size();
oth.push_back(who);
g.emplace_back();
g[who].emplace_back(oth[k - 1], 1);
g[who].emplace_back(oth[k - 1], 0);
}
return oth[t];
};
for(int i = bit; i >= 0; --i) {
g[bit - i].emplace_back(bit - i + 1, (R >> i) & 1);
if ((R >> i) & 1) {
if (!eq) {
int nx = Get(i);
g[bit - i].emplace_back(nx, 0);
}
}
if (eq && (L >> i) != (R >> i)) {
eq = false;
from = bit - i;
bb = i;
}
}
auto create = [&] () {
int v = g.size();
g.emplace_back();
return v;
};
if (!eq) {
int cur = from;
if ((L >> from) == 0) {
cur = 0;
}
for(int i = bb; i >= 0; --i) {
int to = cur;
if (L >> i) {
int nx = oth[0];
if (i != 0) nx = create();
g[cur].emplace_back(nx, (L >> i) & 1);
to = nx;
}
if ((L >> i) & 1) {
} else if (i != bb) {
int wt = Get(i);
g[cur].emplace_back(wt, 1);
}
cur = to;
}
}
cout << g.size() << '\n';
rep(i, g.size()) {
cout << g[i].size() << ' ';
for(auto &[x, y] : g[i]) cout << x + 1 << ' ' << y << ' ';
cout << '\n';
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(12) << fixed;
int t = 1;
rep(i, t) {
solve();
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3524kb
input:
5 7
output:
5 1 2 1 2 3 1 5 0 2 4 1 4 0 0 1 4 1
result:
ok ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3728kb
input:
10 27
output:
12 2 2 1 10 1 2 3 1 9 0 1 4 0 2 5 1 7 0 2 6 1 6 0 0 2 6 1 6 0 2 7 1 7 0 2 8 1 8 0 2 11 0 8 1 1 12 1 2 6 0 6 1
result:
ok ok
Test #3:
score: 0
Accepted
time: 0ms
memory: 3516kb
input:
5 13
output:
9 2 2 1 8 1 2 3 1 7 0 1 4 0 2 5 1 5 0 0 2 5 1 5 0 2 6 1 6 0 2 9 0 6 1 1 5 1
result:
ok ok
Test #4:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
1 1000000
output:
39 20 2 1 39 1 38 1 37 1 36 1 35 1 34 1 33 1 32 1 31 1 30 1 29 1 28 1 27 1 26 1 25 1 24 1 23 1 22 1 21 1 2 3 1 39 0 2 4 1 38 0 2 5 1 37 0 1 6 0 2 7 1 35 0 1 8 0 1 9 0 1 10 0 1 11 0 2 12 1 30 0 1 13 0 1 14 0 2 15 1 27 0 1 16 0 1 17 0 1 18 0 1 19 0 1 20 0 1 21 0 0 2 21 1 21 0 2 2...
result:
ok ok
Test #5:
score: 0
Accepted
time: 0ms
memory: 3728kb
input:
1 1
output:
2 1 2 1 0
result:
ok ok
Test #6:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
7 9
output:
7 2 2 1 6 1 1 3 0 1 4 0 2 5 1 5 0 0 1 7 1 1 5 1
result:
ok ok
Test #7:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
3 7
output:
6 2 2 1 6 1 2 3 1 5 0 2 4 1 4 0 0 2 4 1 4 0 1 4 1
result:
ok ok
Test #8:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
1 5
output:
5 3 2 1 5 1 4 1 1 3 0 2 4 1 4 0 0 2 4 1 4 0
result:
ok ok
Test #9:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
1 4
output:
5 3 2 1 5 1 4 1 1 3 0 1 4 0 0 2 4 1 4 0
result:
ok ok
Test #10:
score: 0
Accepted
time: 0ms
memory: 3588kb
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: 3532kb
input:
7 51
output:
13 4 2 1 11 1 10 1 12 1 2 3 1 11 0 1 4 0 1 5 0 2 6 1 8 0 2 7 1 7 0 0 2 7 1 7 0 2 8 1 8 0 2 9 1 9 0 2 10 1 10 0 1 13 1 1 7 1
result:
ok ok
Test #12:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
51 79
output:
16 2 2 1 12 1 1 3 0 1 4 0 2 5 1 11 0 2 6 1 10 0 2 7 1 9 0 2 8 1 8 0 0 2 8 1 8 0 2 9 1 9 0 2 10 1 10 0 1 13 1 2 14 0 11 1 2 15 0 10 1 1 16 1 1 8 1
result:
ok ok
Test #13:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
92 99
output:
14 1 2 1 2 3 1 10 0 1 4 0 1 5 0 1 6 0 2 7 1 9 0 2 8 1 8 0 0 2 8 1 8 0 1 11 1 1 12 1 1 13 1 2 14 0 9 1 2 8 0 8 1
result:
ok ok
Test #14:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
27 36
output:
13 2 2 1 10 1 1 3 0 1 4 0 2 5 1 9 0 1 6 0 1 7 0 0 2 7 1 7 0 2 8 1 8 0 1 11 1 2 12 0 9 1 1 13 1 1 7 1
result:
ok ok
Test #15:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
55 84
output:
17 2 2 1 13 1 1 3 0 2 4 1 12 0 1 5 0 2 6 1 10 0 1 7 0 1 8 0 0 2 8 1 8 0 2 9 1 9 0 2 10 1 10 0 2 11 1 11 0 1 14 1 2 15 0 11 1 1 16 1 1 17 1 1 8 1
result:
ok ok
Test #16:
score: 0
Accepted
time: 0ms
memory: 3480kb
input:
297208 929600
output:
57 2 2 1 40 1 2 3 1 39 0 2 4 1 38 0 1 5 0 1 6 0 1 7 0 2 8 1 34 0 1 9 0 2 10 1 32 0 2 11 1 31 0 2 12 1 30 0 2 13 1 29 0 1 14 0 2 15 1 27 0 1 16 0 1 17 0 1 18 0 1 19 0 1 20 0 1 21 0 0 2 21 1 21 0 2 22 1 22 0 2 23 1 23 0 2 24 1 24 0 2 25 1 25 0 2 26 1 26 0 2 27 1 27 0 2 28 1...
result:
ok ok
Test #17:
score: 0
Accepted
time: 0ms
memory: 3732kb
input:
45728 589156
output:
54 5 2 1 39 1 38 1 37 1 40 1 1 3 0 1 4 0 1 5 0 2 6 1 36 0 2 7 1 35 0 2 8 1 34 0 2 9 1 33 0 2 10 1 32 0 2 11 1 31 0 1 12 0 2 13 1 29 0 1 14 0 2 15 1 27 0 2 16 1 26 0 1 17 0 1 18 0 2 19 1 23 0 1 20 0 1 21 0 0 2 21 1 21 0 2 22 1 22 0 2 23 1 23 0 2 24 1 24 0 2 25 1 25 0 2 26 1 ...
result:
ok ok
Test #18:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
129152 138000
output:
47 2 2 1 32 1 1 3 0 1 4 0 1 5 0 1 6 0 2 7 1 31 0 2 8 1 30 0 1 9 0 2 10 1 28 0 2 11 1 27 0 1 12 0 1 13 0 1 14 0 2 15 1 23 0 1 16 0 1 17 0 1 18 0 1 19 0 0 2 19 1 19 0 2 20 1 20 0 2 21 1 21 0 2 22 1 22 0 2 23 1 23 0 2 24 1 24 0 2 25 1 25 0 2 26 1 26 0 2 27 1 27 0 2 28 1 28 0...
result:
ok ok
Test #19:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
245280 654141
output:
56 3 2 1 39 1 40 1 1 3 0 1 4 0 2 5 1 37 0 2 6 1 36 0 2 7 1 35 0 2 8 1 34 0 2 9 1 33 0 2 10 1 32 0 1 11 0 2 12 1 30 0 2 13 1 29 0 1 14 0 1 15 0 2 16 1 26 0 2 17 1 25 0 2 18 1 24 0 2 19 1 23 0 1 20 0 2 21 1 21 0 0 2 21 1 21 0 2 22 1 22 0 2 23 1 23 0 2 24 1 24 0 2 25 1 25 0 2 ...
result:
ok ok
Test #20:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
202985 296000
output:
52 2 2 1 36 1 1 3 0 1 4 0 2 5 1 35 0 1 6 0 1 7 0 1 8 0 1 9 0 2 10 1 30 0 1 11 0 1 12 0 1 13 0 2 14 1 26 0 1 15 0 1 16 0 1 17 0 1 18 0 1 19 0 1 20 0 0 2 20 1 20 0 2 21 1 21 0 2 22 1 22 0 2 23 1 23 0 2 24 1 24 0 2 25 1 25 0 2 26 1 26 0 2 27 1 27 0 2 28 1 28 0 2 29 1 29 0 ...
result:
ok ok
Test #21:
score: 0
Accepted
time: 0ms
memory: 3484kb
input:
438671 951305
output:
57 2 2 1 40 1 2 3 1 39 0 2 4 1 38 0 1 5 0 2 6 1 36 0 1 7 0 1 8 0 1 9 0 1 10 0 2 11 1 31 0 1 12 0 1 13 0 1 14 0 1 15 0 1 16 0 1 17 0 2 18 1 24 0 1 19 0 1 20 0 2 21 1 21 0 0 2 21 1 21 0 2 22 1 22 0 2 23 1 23 0 2 24 1 24 0 2 25 1 25 0 2 26 1 26 0 2 27 1 27 0 2 28 1 28 0 2 2...
result:
ok ok
Test #22:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
425249 739633
output:
56 2 2 1 39 1 1 3 0 2 4 1 38 0 2 5 1 37 0 1 6 0 2 7 1 35 0 1 8 0 1 9 0 2 10 1 32 0 1 11 0 1 12 0 2 13 1 29 0 1 14 0 1 15 0 2 16 1 26 0 2 17 1 25 0 1 18 0 1 19 0 1 20 0 2 21 1 21 0 0 2 21 1 21 0 2 22 1 22 0 2 23 1 23 0 2 24 1 24 0 2 25 1 25 0 2 26 1 26 0 2 27 1 27 0 2 28 1...
result:
ok ok
Test #23:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
551207 961718
output:
56 1 2 1 2 3 1 39 0 2 4 1 38 0 1 5 0 2 6 1 36 0 1 7 0 2 8 1 34 0 1 9 0 2 10 1 32 0 2 11 1 31 0 1 12 0 1 13 0 2 14 1 28 0 1 15 0 2 16 1 26 0 2 17 1 25 0 1 18 0 2 19 1 23 0 2 20 1 22 0 1 21 0 0 2 21 1 21 0 2 22 1 22 0 2 23 1 23 0 2 24 1 24 0 2 25 1 25 0 2 26 1 26 0 2 27 1 27...
result:
ok ok
Test #24:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
114691 598186
output:
55 4 2 1 39 1 38 1 40 1 1 3 0 1 4 0 2 5 1 37 0 1 6 0 1 7 0 2 8 1 34 0 1 9 0 1 10 0 1 11 0 1 12 0 1 13 0 2 14 1 28 0 1 15 0 2 16 1 26 0 1 17 0 2 18 1 24 0 1 19 0 2 20 1 22 0 1 21 0 0 2 21 1 21 0 2 22 1 22 0 2 23 1 23 0 2 24 1 24 0 2 25 1 25 0 2 26 1 26 0 2 27 1 27 0 2 28 1...
result:
ok ok
Test #25:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
234654 253129
output:
46 1 2 1 1 3 1 1 4 1 2 5 1 32 0 1 6 0 2 7 1 31 0 2 8 1 30 0 2 9 1 29 0 1 10 0 1 11 0 2 12 1 26 0 2 13 1 25 0 1 14 0 1 15 0 2 16 1 22 0 1 17 0 1 18 0 2 19 1 19 0 0 2 19 1 19 0 2 20 1 20 0 2 21 1 21 0 2 22 1 22 0 2 23 1 23 0 2 24 1 24 0 2 25 1 25 0 2 26 1 26 0 2 27 1 27 0 2...
result:
ok ok
Test #26:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
554090 608599
output:
52 1 2 1 1 3 0 1 4 0 2 5 1 36 0 1 6 0 2 7 1 35 0 1 8 0 1 9 0 2 10 1 32 0 1 11 0 1 12 0 2 13 1 29 0 1 14 0 2 15 1 27 0 1 16 0 2 17 1 25 0 1 18 0 2 19 1 23 0 2 20 1 22 0 2 21 1 21 0 0 2 21 1 21 0 2 22 1 22 0 2 23 1 23 0 2 24 1 24 0 2 25 1 25 0 2 26 1 26 0 2 27 1 27 0 2 28 1...
result:
ok ok
Extra Test:
score: 0
Extra Test Passed