求一个严谨的复杂度证明
查看原帖
求一个严谨的复杂度证明
832472
yishanyi楼主2024/12/15 16:41

蒟蒻怎么感觉二分+setset+双指针的写法是O(n2)O(n^2)的呢?

inline bool check(int now) {

    multiset<Node> s{};
    head = 0, tail = -1, cnt = 0;

    for (int i = 1; i <= n; i++) {
        while (tail >= head && p[i].x - now > p[q[head]].x) s.erase(s.find({p[q[head]].x, p[q[head]].y})), head++;
        auto pos = s.lower_bound({0, p[i].y - now});
        while (pos != s.end() && p[i].y + now >= (*pos).y) {
            res[++cnt] = max(abs(p[i].x - (*pos).x), abs(p[i].y - (*pos).y)), ++pos;
            if (cnt >= k)
                return true;
        }
        q[++tail] = i, s.insert({p[i].x, p[i].y});
    }

    return false;
}

这个checkcheck的复杂度是多少啊?

2024/12/15 16:41
加载中...