当前位置: 首页 > news >正文

题解:AtCoder AT_awc0080_b Quality Inspection and Product Disposal

本文分享的必刷题目是从蓝桥云课洛谷AcWing等知名刷题平台精心挑选而来,并结合各平台提供的算法标签和难度等级进行了系统分类。题目涵盖了从基础到进阶的多种算法和数据结构,旨在为不同阶段的编程学习者提供一条清晰、平稳的学习提升路径。

欢迎大家订阅我的专栏:算法题解:C++与Python实现!

附上汇总贴:算法竞赛备考冲刺必刷题(C++) | 汇总


【题目来源】

AtCoder:B - Quality Inspection and Product Disposal

【题目描述】

Takahashi is the quality control manager of a factory. The factory has a system where manufactured products are periodically inspected for quality, and products that do not meet the standards are disposed of.

The factory currently hasN NNproducts, each numbered from1 11toN NN. The quality score of producti iiisA i A_iAi.

Takahashi performsQ QQquality inspections in order. In thej jj-th inspection( 1 ≤ j ≤ Q ) (1 \leq j \leq Q)(1jQ), a threshold valueT j T_jTjis set, andamong the products that have not yet been disposed of at that point, all products whose quality score isstrictly less thanT j T_jTjare disposed of. Once a product is disposed of, it is no longer subject to subsequent inspections. Note that the threshold valueT j T_jTjis determined independently for each inspection, so it may be smaller than the previous threshold. In that case, if the relevant products have already been disposed of in previous inspections, no new products are disposed of.

Immediately after each inspection, the number of products newly disposed of in that inspection is recorded. For allQ QQquality inspections, determine the number of products newly disposed of in each inspection.

高桥是工厂的质量控制经理。工厂有一个系统,定期检查产品的质量,不符合标准的产品会被销毁。

工厂目前有N NN个产品,编号从1 11N NN。产品i ii的质量得分为A i A_iAi

高桥按顺序执行Q QQ次质量检查。在第j jj次检查中(1 ≤ j ≤ Q 1 \leq j \leq Q1jQ),设定一个阈值T j T_jTj,并且在此时尚未销毁的产品中,所有质量得分严格小于T j T_jTj的产品将被销毁。一旦产品被销毁,它将不再受后续检查的影响。注意,每次检查的阈值T j T_jTj是独立确定的,因此它可能小于之前的阈值。在这种情况下,如果相关产品在之前的检查中已经被销毁,则不会再有新产品被销毁。

每次检查后,立即记录该次检查中新销毁的产品数量。对于所有Q QQ次质量检查,确定每次检查中新销毁的产品数量。

【输入】

N NNQ QQ
A 1 A_1A1A 2 A_2A2… \ldotsA N A_NAN
T 1 T_1T1
T 2 T_2T2
⋮ \vdots
T Q T_QTQ

  • The first line contains an integerN NNrepresenting the number of products and an integerQ QQrepresenting the number of quality inspections, separated by a space.
  • The second line contains integersA 1 , A 2 , … , A N A_1, A_2, \ldots, A_NA1,A2,,ANrepresenting the quality scores of each product, separated by spaces.
  • In the followingQ QQlines, thej jj-th line( 1 ≤ j ≤ Q ) (1 \leq j \leq Q)(1jQ)contains an integerT j T_jTjrepresenting the threshold value for thej jj-th inspection.

【输出】

OutputQ QQlines. Thej jj-th line( 1 ≤ j ≤ Q ) (1 \leq j \leq Q)(1jQ)should contain the number of products newly disposed of in thej jj-th inspection.

【输入样例】

5 3 3 1 4 1 5 2 4 3

【输出样例】

2 1 0

【算法标签】

#整数二分

【代码详解】

#include<bits/stdc++.h>usingnamespacestd;constintN=200005;intn,q,st;// n: 数组长度,q: 查询次数,st: 起始位置inta[N];// 存储数组intmain(){cin>>n>>q;// 输入数组长度和查询次数for(inti=1;i<=n;i++)// 输入数组元素cin>>a[i];sort(a+1,a+n+1);// 对数组进行升序排序st=1;// 初始化起始位置为1while(q--)// 处理每个查询{intt;// 查询值cin>>t;// 输入查询值intpos=upper_bound(a+1,a+n+1,t-1)-a;// 找到第一个大于t-1的位置if(pos<=st)// 如果位置小于等于起始位置cout<<0<<endl;// 输出0elsecout<<pos-st<<endl;// 输出区间长度st=max(st,pos);// 更新起始位置}return0;}

【运行结果】

5 3 3 1 4 1 5 2 2 4 1 3 0
http://www.zskr.cn/news/1443564.html

相关文章:

  • 2026年 高频焊接机/高频诱导焊接机/全自动高频焊接设备/铜产品焊接设备/制冰机焊接机厂家推荐榜:高精度与智能焊接技术实力全解析 - 企业推荐官【官方】
  • [Full Clock 技术复盘] 一、浏览器前端如何实现百毫秒级时间校准?时间 API 推荐、模拟 NTP 算法原理及局限
  • 华为韬(T)定律
  • Joy-Con Toolkit:Switch手柄终极定制与修复完整指南
  • GetQzonehistory:Python实现QQ空间历史说说完整备份指南
  • 零门槛3D打印智能火箭灯:免焊接编程的STEAM创客项目
  • AI驱动企业增长:七种实战策略与实施路线图
  • STC8H单片机GPIO模式选错,你的LED为啥不亮?准双向、推挽、开漏、高阻输入模式保姆级选择指南
  • ncmdumpGUI:高效音频格式转换的专业解决方案
  • 如何彻底告别Windows桌面混乱:免费开源神器NoFences终极指南
  • 揭秘智能APK管理工具:高效处理拆分文件的完整攻略
  • 连云港本地全域管道漏水检测优质靠谱商家-消防/自来水/热力管道测漏维修 地埋管道打压保压 地埋电缆故障检测 - 资讯热点
  • 别再死记硬背公式了!用Matlab手把手复现Capon算法,搞懂DOA估计的核心
  • 告别笨重模拟器:APK Installer让你在Windows电脑轻松运行安卓应用
  • 告别命令行:在香橙派上为wiringPi C程序写一个简单的Makefile
  • 系统变量与环境变量:CANoe中数据传递的核心机制
  • 2026年PDF拆分与合并免费工具全分享:按页、按书签、按大小随心处理 - 时时资讯
  • 从零搭建Arduino智能家居模型:光感照明与振动安防实战
  • 手把手教你配置深信服AC的SSL解密:从中间人解密到准入插件,一篇搞定
  • 绝绝子!输入关键词,这几款AI论文写作工具就能生成图文并茂的毕业论文
  • 基于ESP-NOW与IMU的手势控制机器人:从姿态感知到无线运动控制
  • 源代码论文分享|基于Java的小区物业智能卡管理的设计与实现!
  • Windows热键冲突检测终极指南:3步精准定位被占用快捷键
  • SMD手工焊接全攻略:从焊膏印刷到热风枪回流焊的桌面级工艺
  • 网盘直链下载助手完整教程:八大网盘一键获取真实下载链接
  • 2026湖州市防水补漏公司权威推荐:卫生间、阳台、屋顶、地下室、飘窗、外墙漏水,专业防水公司TOP5口碑榜+全维度测评(2026年6月最新深度行业资讯) - 防水百科
  • 3步搞定!Windows上快速安装安卓应用的终极指南
  • 2026桂林市防水补漏公司权威推荐:卫生间、阳台、屋顶、地下室、飘窗、外墙漏水,专业防水公司TOP5口碑榜+全维度测评(2026年6月最新深度行业资讯) - 防水百科
  • 2026宜昌市防水补漏公司权威推荐:卫生间、阳台、屋顶、地下室、飘窗、外墙漏水,专业防水公司TOP5口碑榜+全维度测评(2026年6月最新深度行业资讯) - 防水百科
  • 如何高效使用Illustrator智能填充工具:初学者快速入门指南