xjb 写的,成为了给队伍的最大贡献。唉。
竟然是 EI 题,哦哦?
ILLusion 14:01:33 我的思路是,把 T 拆成一些 1 的个数长度为 2^k 的区间
ILLusion 14:01:44 然后按照 k 倒序加
ILLusion 14:01:59 对于每个和为 2^k 区间的初始元素,启发式合并
ILLusion 14:02:08 感觉可能是运气好,出题人没卡这个东西
ILLusion 14:02:10 感恩了
ILLusion 14:09:36
int main() {
int N; std::string S; std::cin >> N >> S;
lg[1] = 0; for (int i = 2; i <= N; ++i) lg[i] = lg[i >> 1] + 1;
for (int i = 1, j = 1, k, now; i <= N; j = i = ++j) if (S[i - 1] == '1') {
while (j < N && S[j] == '1') ++j; now = i;
while (now <= j) k = lg[j - now + 1], v[k].push_back(now), now += (1 << k);
}
int x = 0;
for (int k = 20; ~k; --k) {
if (x > 0) {
t.push_back(Node(3, x, 1 << k)), ++cnt;
t.push_back(Node(2, x, cnt)), ++cnt;
x = cnt;
}
if (v[k].empty()) continue;
int o = merge(v[k]);
if (x == 0) x = o; else t.push_back(Node(2, x, o)), x = ++cnt;
}
print<int>(t.size(), '\n');
for (Node u : t) {
printf("%d %d ", u.a, u.b);
if (u.a > 1) print<int>(u.c, '\n'); else puts("");
}
return 0;
}ILLusion 14:09:41 merge() 是启发式合并