力扣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];
      }
  };
相关推荐
To_OC4 小时前
LC 1 两数之和:面试第一道必考题,暴力解法直接被面试官 pass
javascript·算法·leetcode
鱼鱼不愚与9 小时前
《原来如此 | 第01期:为什么导航软件能预测红绿灯倒计时?》
算法
复杂网络13 小时前
论最小 Agent 计算机的形态
算法
kisshyshy1 天前
🍦 雪糕、食堂、火车厢:三幅漫画吃透栈、队列与链表
javascript·算法
猿人谷1 天前
不只是 CPU 阈值:STAR 如何用 GAT + Transformer 做容器级自动扩缩容?
人工智能·算法
复杂网络2 天前
Stable Diffusion 视觉大模型微调技术深度调研
算法
复杂网络2 天前
基于 Stable Diffusion 架构的视觉大模型代表性工作与原理深度解析
算法
MrZhao4002 天前
Agent Loop 如何用 Hook 扩展:权限、日志与工具拦截
算法
MrZhao4002 天前
Agent 为什么需要 Skills:别把所有知识都塞进 system prompt
算法