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];
    }
};
相关推荐
XiaoCCCcCCccCcccC16 分钟前
多路复用 select -- select 的介绍,select 的优缺点,select 版本的 TCP 回显服务器
服务器·c++
XiaoCCCcCCccCcccC18 分钟前
多路复用 poll -- poll 的介绍,poll 的优缺点,poll 版本的 TCP 回显服务器
服务器·网络·c++
小π军1 小时前
STL利器:upper_bound与lower_bound的使用
c++
Zx623652 小时前
13.泛型编程 STL技术
java·开发语言·c++
The Last.H2 小时前
Educational Codeforces Round 185 (Rated for Div. 2)A-C
c语言·c++·算法
caron42 小时前
C++ 推箱子游戏
开发语言·c++·游戏
路过君_P3 小时前
C++ 算法题解:迷宫寻路
c++·算法·深度优先
止观止3 小时前
告别“祖传C++”:开启你的现代C++之旅
c++·c++11·c++20·编程思想·现代c++
罗湖老棍子3 小时前
二维vector完全指南1:从定义到增删改查
数据结构·c++·算法·stl