KDT,写了一个 build 函数如下:
inline int build(const int& l, const int& r, const int& t) {
if (l > r) return 0; int nd = newn(), md = (l + r) >> 1; sty = t;
nth_element(p + l, p + md, p + r + 1), re[nd].p = p[md];
re[nd].lc = build(l, md - 1, t ^ 1), re[nd].rc = build(md + 1, r, t ^ 1);
pup(nd); return nd;
}
然而死得很惨。最终,当我改成这样:
inline int build(int l, int r, int t) {
if (l > r) return 0; int nd = newn(), md = (l + r) >> 1; sty = t;
nth_element(p + l, p + md, p + r + 1), re[nd].p = p[md];
re[nd].lc = build(l, md - 1, t ^ 1), re[nd].rc = build(md + 1, r, t ^ 1);
pup(nd); return nd;
}
的时候,他就过了。
还是想请问一下,以上两份代码究竟有什么本质的不同?
一个是引用传参,但是有 const 修饰,理论上并未修改,另一个是正常的传参。