1738. 找出第 K 大的异或坐标值

1738. 找出第 K 大的异或坐标值


题目链接:1738. 找出第 K 大的异或坐标值

代码如下:

cpp 复制代码
//列前缀异或和
//参考链接:https://leetcode.cn/problems/find-kth-largest-xor-coordinate-value/solutions/2790359/liang-chong-fang-fa-er-wei-qian-zhui-yi-689bf
class Solution 
{
public:
    int kthLargestValue(vector<vector<int>>& matrix, int k) 
    {
        vector<int> res,col_sum(matrix[0].size());
        for(const auto& row:matrix)
        {
            int s=0;
            for(int j=0;j<row.size();j++)
            {
                col_sum[j]^=row[j];
                s^=col_sum[j];
                res.push_back(s);
            }
        }
        ranges::nth_element(res,res.end()-k);
        return res[res.size()-k];
    }
};
相关推荐
智践行5 分钟前
C++11 智能指针:`std::unique_ptr`、`std::shared_ptr`和`std::weak_ptr`
c++
智践行14 分钟前
C++11之后的 Lambda 表达式 以及 `std::function`和`std::bind`
c++
智践行17 分钟前
C++11移动语义‘偷梁换柱’实战
c++
祁同伟.1 小时前
【C++】模版(初阶)
c++
sTone873752 小时前
android studio之外使用NDK编译生成android指定架构的动态库
android·c++
卷卷卷土重来3 小时前
C++单例模式
javascript·c++·单例模式
yuyanjingtao3 小时前
CCF-GESP 等级考试 2025年6月认证C++二级真题解析
c++·青少年编程·gesp·csp-j/s
long_run5 小时前
C++之auto 关键字
c++
疯狂的代M夫5 小时前
C++对象的内存布局
开发语言·c++
重启的码农6 小时前
llama.cpp 分布式推理介绍(4) RPC 服务器 (rpc_server)
c++·人工智能·神经网络