力扣911.在线选举

力扣911.在线选举

  • 类似1818. 将每个时刻的候选人存储 在时间段上做二分

cpp 复制代码
  class TopVotedCandidate {
      vector<int> time,person;
  public:
      TopVotedCandidate(vector<int>& persons, vector<int>& times) {
              int n = persons.size();
              unordered_map<int,int> cnt;
              int ms = 0,mi = 0;
              time = times;
  
              for(int i=0;i<n;i++)
              {
                  if(++cnt[persons[i]] >= ms)
                  {
                      ms = cnt[persons[i]];
                      mi = persons[i];
                  }
                  person.push_back(mi);
              }
      }
      
      int q(int t) {
          int idx = ranges::upper_bound(time,t) - time.begin() - 1;
          return person[idx];
      }
  };
相关推荐
0+11110 小时前
算法 --链表
数据结构·算法·leetcode·链表
圣保罗的大教堂10 小时前
leetcode 2333. 最小差值平方和 中等
leetcode
aqiu11111110 小时前
【C++算法打怪专栏】C++ `unordered_set` 常用初始化与插入方法总结
开发语言·c++·算法
Terra.K10 小时前
高精度阶乘求和模板深度解析
开发语言·c++·算法
Peregrine911 小时前
C++ - > 类和对象
java·c++·算法
Gigavision12 小时前
DEAP数据集 2026最新Transformer算法 DEAP 数据集 下载
深度学习·算法·transformer
夜之眷属12 小时前
PriorityQueue:for-each 遍历和 poll 取出,顺序一样吗?
java·服务器·数据结构·后端·算法
地平线开发者13 小时前
不是线程越多越快:用 hrt_model_exec 在 征程6M 上给 YOLOv5x 建立性能基线
算法
姜鱼问生14 小时前
fail2ban 实战:从默认配置到生产可用
后端·算法·架构
垆边人似月.14 小时前
华为题:全排列
算法·深度优先·图论