力扣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];
      }
  };
相关推荐
xiaokcehui1 小时前
地球物理大地测量学计算系列之十七局部重力场SRBF逼近及其性能指标测评
人工智能·算法·机器学习
Navigator_Z1 小时前
LeetCode //C - 1221. Split a String in Balanced Strings
c语言·算法·leetcode
天疆说2 小时前
庞特里亚金极小值原理的详细推导
算法
余俊晖2 小时前
Self-OPD:去掉教师机的流匹配模型 On-Policy 蒸馏
人工智能·算法·机器学习
手写码匠2 小时前
华为云Flexus+DeepSeek征文|华为云MaaS DeepSeek推理服务 × Flexus云服务器 × Dify一键部署:性能评测实战
人工智能·深度学习·算法·aigc
啥都想学点的研究生3 小时前
一篇文章讲清楚:逻辑回归
算法·机器学习·逻辑回归
货拉拉技术4 小时前
Agent 场景下 Token 成本优化的实战技巧
算法
hahaha60164 小时前
HLS高层次综合设计技巧--循环merge和循环split
人工智能·算法·计算机视觉
JAI科研4 小时前
Deepseek Agent Harness教程(七) | Deepseek Harness不是一个内核加一堆插件
开发语言·人工智能·深度学习·算法·自然语言处理·transformer·vllm
集思广益的灰太狼4 小时前
变频器启动致PLC数据异常?西门子G120配合滤波器EMC抑制方案
人工智能·算法·工控·emc·电磁兼容·变频器·西门子