voidSolve(){ ll N, M; cin >> N >> M; vector<ll> diff_ls(N + 2); vector<ll> parent(N + 2); for (int i = 1; i <= N - 1; ++i) { parent[i] = i + 1; } for (int i = 1; i <= M; ++i) { ll u, v; cin >> u >> v; parent[u] = max(parent[u], v); } vector<vector<ll> > g(N + 2); for (int i = 1; i <= N - 1; ++i) { g[i].push_back(parent[i]); g[parent[i]].push_back(i); } vector<ll> size_ls(N + 2, 1), heavy_son(N + 2), mx_dep_ls(N+2);
auto dfs1 = [&](auto &&self, ll u, ll p) -> ll { for (auto to: g[u]) { if (to == p) { continue; } size_ls[u] += self(self, to, u); if (size_ls[to] >= size_ls[heavy_son[u]]) { heavy_son[u] = to; } } return size_ls[u]; }; dfs1(dfs1, N, -1); // 我们想要计算的就是,当我们已经知道 一个点 v,在其他 // 所有树上,比他的深度浅或者同样深度的所有点,贡献 dep(u)-dep(lca(u,v)) // 不过只有其他
// dsu on tree vector<map<ll,ll> > node_dep_cnt_mtx(N + 2); ll ans=0; auto dfs2 = [&](auto &&self, ll u, ll p,ll dep) -> void { for (auto to: g[u]) { if (to == p) continue; if (to != heavy_son[u]) continue; self(self, to, u, dep+1); // 复用重儿子的空间,避免 mle。 swap(node_dep_cnt_mtx[u], node_dep_cnt_mtx[to]); break; } ll sum_node=size_ls[heavy_son[u]]; for (auto to: g[u]) { if (to == p) continue; if (to == heavy_son[u]) continue; // 我们先写的 naive 一点 self(self,to,u,dep+1); // 其实只要我们合并的方法只和轻儿子的子树相关性质有关系 // 比如说深度, ll mx_dep=node_dep_cnt_mtx[to].rbegin()->first; // 虽然说比他的深度浅或者同样深度的所有点,贡献 dep(u)-dep(lca(u,v)) // 但比他深度深的节点,也会贡献,因为已经在重儿子中的深度深的节点 // 合并进来的时候还没有这样一个节点,贡献的就是 dep(v)-dep(lca(u,v))
You are given two non-negative integers x, y. Find two non-negative integers p and q such that p&q=0, and ∣x−p∣+∣y−q∣ is minimized. Here, & denotes the bitwise AND operation.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The only line of each test case contains two non-negative integers x and y (0≤x,y<230).
Output
For each test case, output two non-negative integers p and q you found. If there are multiple pairs of p and q satisfying the conditions, you may output any of them.
It can be proven that under the constraints of the problem, any valid solution satisfies max(p,q)<231.
1 2 3 4 5 6 7 8
7 00 11 36 711 44 123321 10737418231073741822
1 2 3 4 5 6 7
00 21 38 69 43 128321 10737418241073741822
Note
In the first test case, one valid pair would be p=0 and q=0, as 0&0=0 and ∣x−p∣+∣y−q∣=∣0−0∣+∣0−0∣=0 is the minimum over all pairs of p and q.
In the third test case, one valid pair would be p=3 and q=8, as 3&8=0 and ∣x−p∣+∣y−q∣=∣3−3∣+∣8−6∣=2 is the minimum over all pairs of p and q. Note that (p,q)=(3,4) is also a valid pair.