BZOJ 3689: 异或之
2017-11-07 19:52
363 查看
二次联通门 : BZOJ 3689: 异或之
/* BZOJ 3689: 异或之 zz题 */ #include <cstdio> #include <iostream> #include <queue> #define rg register struct IO { static const int BUF = 12323233; char p[BUF], *s, *t, e[BUF]; int a[25]; IO () : s (p), t (e) { fread (s, 1, BUF, stdin); } ~IO () { fwrite (e, 1, t - e, stdout); } operator int () { rg int j = 1, v = 0; for (; *s < 48; j = *s ++ ^ 45); do v = v * 10 + *s ++ - 48; while (*s >= 48); return j ? v : -v; } void pt (int v) { static int *q = a; if (!v) *t ++ = 48; else { if (v < 0) *t ++ = 45, v *= -1; for (; v; *q ++ = v % 10 + 48, v /= 10); for (; q != a; *t ++ = *-- q); } *t ++ = ' '; } } ip; #define Max 200203 int tr[Max * 20][2], TC, s[Max * 20]; void In (int key) { int n = 0; for (rg int t, i = 30; i >= 0; -- i) { t = (key >> i) & 1; if (!tr [t]) tr [t] = ++ TC; n = tr [t], ++ s ; } } int Ask (int key, int k) { int res = 0, n = 0; for (rg int i = 30, t; i >= 0; -- i) { t = (key >> i) & 1; if (s[tr [t]] >= k) n = tr [t]; else k -= s[tr [t]], n = tr [t ^ 1], res += (1 << i); } return res; } struct D { int key, rk, x; D (int a = 0, int b = 0, int c = 0) : key (a), rk (b), x (c) {} bool operator < (const D &rhs) const { return x > rhs.x; } }; int a[Max]; std :: priority_queue <D> Q; int main (int argc, char *argv[]) { int N = ip, K = ip; rg int i; D n; for (i = 1; i <= N; ++ i) a[i] = ip, In (a[i]); for (i = 1; i <= N; ++ i) Q.push (D (a[i], 2, Ask (a[i], 2))); for (i = 1; i < (K << 1); ++ i) { n = Q.top (), Q.pop (); if (i & 1) ip.pt (n.x); ++ n.rk, n.x = Ask (n.key, n.rk), Q.push (n); } return 0; }
相关文章推荐
- BZOJ3689: 异或之
- 异或之(bzoj 3689)
- 【bzoj3689】【异或之】【trie树+堆】
- BZOJ[3689] 异或之 Trie树+堆
- BZOJ 3689 异或 Trie木+堆
- bzoj 3689: 异或之 字典树+堆
- BZOJ 3689 异或之 Trie树+堆
- 【bzoj3689】异或之 可持久化Trie树+堆
- bzoj 3689 异或之
- [Trie树] BZOJ3689: 异或之
- 【BZOJ3689】异或之 堆+可持久化Trie树
- BZOJ 3689: 异或之 字典树 优先队列
- 【bzoj3689】异或之 trie+堆
- BZOJ 3689 异或之
- BZOJ3689 异或之
- BZOJ_3689_异或之_可持久化Trie+堆
- [乱搞 || 可持久化字典树 堆] BZOJ3689 异或之
- bzoj 3689: 异或之 Trie+堆
- bzoj 3689: 异或之
- [BZOJ 3689]异或之