2018ACM/ICPC南京站网络赛G Lpl and Energy-saving Lamps(线段树)

2018 ACM-ICPC 南京网络赛题目 立即下载

2018ACM/ICPC南京站网络赛G Lpl and Energy-saving Lamps

During tea-drinking, princess, amongst other things, asked why has such a good-natured and cute Dragon imprisoned Lpl in the Castle? Dragon smiled enigmatically and answered that it is a big secret. After a pause, Dragon added:

— We have a contract. A rental agreement. He always works all day long. He likes silence. Besides that, there are many more advantages of living here in the Castle. Say, it is easy to justify a missed call: a phone ring can’t reach the other side of the Castle from where the phone has been left. So, the imprisonment is just a tale. Actually, he thinks about everything. He is smart. For instance, he started replacing incandescent lamps with energy-saving lamps in the whole Castle…

Lpl chose a model of energy-saving lamps and started the replacement as described below. He numbered all rooms in the Castle and counted how many lamps in each room he needs to replace.

At the beginning of each month, Lpl buys mmm energy-saving lamps and replaces lamps in rooms according to his list. He starts from the first room in his list. If the lamps in this room are not replaced yet and Lpl has enough energy-saving lamps to replace all lamps, then he replaces all ones and takes the room out from the list. Otherwise, he’ll just skip it and check the next room in his list. This process repeats until he has no energy-saving lamps or he has checked all rooms in his list. If he still has some energy-saving lamps after he has checked all rooms in his list, he’ll save the rest of energy-saving lamps for the next month.

As soon as all the work is done, he ceases buying new lamps. They are very high quality and have a very long-life cycle.

Your task is for a given number of month and descriptions of rooms to compute in how many rooms the old lamps will be replaced with energy-saving ones and how many energy-saving lamps will remain by the end of each month.
Input

Each input will consist of a single test case.

The first line contains integers nnn and m(1≤n≤100000,1≤m≤100)m (1 \le n \le 100000, 1 \le m \le 100)m(1≤n≤100000,1≤m≤100) — the number of rooms in the Castle and the number of energy-saving lamps, which Lpl buys monthly.

The second line contains nnn integers k1,k2,…,knk_1, k_2, …, k_nk1​,k2​,…,kn​
(1≤kj≤10000,j=1,2,…,n)(1 \le k_j \le 10000, j = 1, 2, …, n)(1≤kj​≤10000,j=1,2,…,n) — the number of lamps in the rooms of the Castle. The number in position jjj is the number of lamps in jjj-th room. Room numbers are given in accordance with Lpl’s list.

The third line contains one integer q(1≤q≤100000)q (1 \le q \le 100000)q(1≤q≤100000) — the number of queries.

The fourth line contains qqq integers d1,d2,…,dqd_1, d_2, …, d_qd1​,d2​,…,dq​
(1≤dp≤100000,p=1,2,…,q)(1 \le d_p \le 100000, p = 1, 2, …, q)(1≤dp​≤100000,p=1,2,…,q) — numbers of months, in which queries are formed.

Months are numbered starting with 111; at the beginning of the first month Lpl buys the first m energy-saving lamps.
Output

Print qqq lines.

Line ppp contains two integers — the number of rooms, in which all old lamps are replaced already, and the number of remaining energy-saving lamps by the end of dpd_pdp​ month.
Hint

Explanation for the sample:

In the first month, he bought 444 energy-saving lamps and he replaced the first room in his list and remove it. And then he had 111 energy-saving lamps and skipped all rooms next. So, the answer for the first month is 1,1−−−−−−11,1——11,1−−−−−−1 room’s lamps were replaced already, 111 energy-saving lamp remain.
样例输入

5 4
3 10 5 2 7
10
5 1 4 8 7 2 3 6 4 7

样例输出

4 0
1 1
3 6
5 1
5 1
2 0
3 2
4 4
3 6
5 1

题目来源

ACM-ICPC 2018 南京赛区网络预赛

题意:

已知n个房间,每个房间需要有ai个灯,主角在给所有房间都装好节能灯之前,会每个月购买m个节能灯,同时每个月按房间编号从小到大依次给能完全满足需求的房间装节能灯,剩下的节能灯留到下个月用。接下来q个查询,询问第bi个月后已经装好灯的房间数和该月最后剩下的节能灯数。

分析:

可以使用线段树维护区间最小值,查询的时候查询最靠左的小于等于要求数的位置,然后更新成inf表示已经更新,因为查询的月份最多1e5,因此可以先求出每个月的结果存到数组里,之后O(1)查询即可。

code:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100005;
const int INF = 0x3f3f3f3f;
int sum[N<<2],a[N],ans1[N],ans2[N];

void build(int rt,int l,int r){
    if(l == r){
        sum[rt] = a[l];
        return;
    }
    int mid = l + r >> 1;
    build(rt<<1,l,mid);
    build(rt<<1|1,mid+1,r);
    sum[rt] = min(sum[rt<<1],sum[rt<<1|1]);
}

void update(int rt,int l,int r,int x){//将位置x更新成inf
    if(l == r){
        sum[rt] = INF;
        return;
    }
    int mid = l + r >> 1;
    if(x <= mid) update(rt<<1,l,mid,x);
    else update(rt<<1|1,mid+1,r,x);
    sum[rt] = min(sum[rt<<1],sum[rt<<1|1]);
}

int query(int rt,int l,int r,int x){//查找到满足小于等于x的最靠左的位置
    if(l == r){
        return l;
    }
    int mid = l + r >> 1;
    if(sum[rt<<1] <= x) return query(rt<<1,l,mid,x);//先往左找,满足条件继续往左,若能找到就直接返回了
    if(sum[rt<<1|1] <= x) return query(rt<<1|1,mid+1,r,x);//找不到在往右侧找
    return -1;//还找不到说明没有返回-1
}
int n,m,q;
int main(){
    while(~scanf("%d%d",&n,&m)){
        for(int i = 1; i <= n; i++) scanf("%d",&a[i]);
        build(1,1,n);
        int ansa = 0,ansb = 0;
        for(int i = 1; i <= 100000; i++){//打表预处理出所有月份的答案
            if(ansa < n){//如果还有没有更换的房间
                ansb += m;//现在手里有的灯泡为上个月剩下的ansb+新买的m
                while(1){//连续更新
                    int pos = query(1,1,n,ansb);//查询符合条件的最靠左的位置
                    if(pos != -1){
                        ansb -= a[pos];
                        ansa++;
                        update(1,1,n,pos);//将已经更换灯泡的房间变成inf
                    }
                    else break;//找不到满足条件的房间了就退出进入下一个月

                }
            }
            ans1[i] = ansa;
            ans2[i] = ansb;
        }
        scanf("%d",&q);
        while(q--){
            int d;
            scanf("%d",&d);
            printf("%d %d\n",ans1[d],ans2[d]);
        }
    }
    return 0;
自研半导体Fab缺陷分析系统:从Klarf解析到Defect Map可视化的实战替代方案 本文分享了自研半导体Fab缺陷分析系统的实战经验,重点解析了Klarf文件格式与坐标系转换的核心技术,并详细介绍了从数据解析到Defect Map可视化的完整实现路径。该系统旨在为成本敏感或追求技术自主的团队提供一套功能完备的Klarity Defect平替方案,有效降低对昂贵商业软件的依赖,实现缺陷数据的自主分析与可视化。 阅读详情

相关推荐

MeshLab新手必看:5分钟搞定泊松表面重建(附完整点云处理流程)

本文详细介绍了如何使用MeshLab进行泊松表面重建,从点云数据导入、预处理到核心参数设置,再到后处理与模型优化,提供了完整的3D重建流程指南。特别适合计算机视觉和3D重建领域的新手快速掌握泊松重建技术,提升工作效率。

kafka6courier的博客 230

2018 ACM-ICPC南京网络赛 Lpl and Energy-saving Lamps(线段树)

During tea-drinking, princess, amongst other things, asked why has such a good-natured and cute Dragon imprisoned Lpl in the Castle? Dragon smiled enigmatically and answered that it is a big secret. A...

GYH0730的博客 470

ROS2 -Jazzy 一步一步(第一步_工作空间以及编译)

文件夹作用特点是否需要手动创建/维护src存放自己写的 ROS 2 包一个 workspace 可以有多个包需要手动创建build保存编译过程中的中间文件每个包生成对应子目录自动生成,可删除install保存编译完成后的功能包每个包有独立子目录,含可执行文件自动生成,可删除log保存编译日志用于查看错误原因、调试自动生成,不需修改colcon是 ROS 2 推荐使用的构建工具自动处理功能包的依赖和编译顺序一条命令就能编译整个工作空间。

jerrykorea的博客 1380

ACM-ICPC 2018 南京赛区网络预赛 E AC Challenge(状压dp)

Dlsj is competing in a contest with n (0 &lt; n \le 20)n(0&lt;n≤20) problems. And he knows the answer of all of these problems. However, he can submit ii-th problem if and only if he has submitted (a...

LSD20164388的博客 561

brother的PT-9800PCN标签打印机二次开发

本来想通过esc/p指令打印标签,但是无奈能找到的资料太少,而且打电话给客服,也没有sample可以提供参考,后来客服说使用template功能的话,打印很方便。于是下载手册学习了一下, 先下载P-touch Editor软件,制作标签模板。 制作的模板就是普通的标签,不需要连接数据库之类的,模板里有3个object,分别是文本1,文本2,条形码3。这个很关键,后面的代码传送数据,就是按这...

3563

泛微E10 eBuilder低代码平台避坑指南:新手最容易犯的5个错误及解决方案

本文针对泛微E10 eBuilder低代码平台的新手开发者,总结了5个最常见错误及解决方案,包括表单联动配置、流程设计权限、动作流时序、数据加工类型转换和权限管理过度配置等问题。通过实战经验和代码示例,帮助开发者避开常见陷阱,提升开发效率。

weixin_30919429的博客 540

ACM-ICPC 2018 南京赛区网络预赛 G Lpl and Energy-saving Lamps(线段树)

链接:https://nanti.jisuanke.com/t/30996 题意:有n个房间,每个房间有a[i]个灯泡需要被替换。工作人员一开始有m个替换灯泡,并且每个月再增加m个。 有q组询问,问每个月已经替换完成的房间数和灯泡剩余的量。 注意:只有替换灯泡数大于房间内的灯泡数才可以替换,每次从左到右替换、当所有房间都被替换完之后或者这个月的灯泡数不够了即结束。 思路:我们可以直接用线段...

qq_36782366的博客 424

【图像超分】论文复现:Pytorch实现SRCNN!保姆级复现教程!提供完整代码和最优权重模型(x2、x3、x4)!科研级论文曲线图!计算平均PSNR和SSIM!代码Windows和Linux都可用!

由于很多同学反应没用过jupyter notebook,更习惯用pycharm项目的形式跑代码。于是,本文将用pycharm项目的形式,重新复现SRCNN!【图像超分】论文复现:新手入门!Pytorch实现SRCNN,数据预处理、模型训练、测试、评估全流程详解,注释详细,简单修改就可以训练你自己的图像数据,有训练好的模型下载地址,随取随用。

主要更新底层视觉(去噪、超分等)相关的科研内容,形式为【论文精读】+【论文复现】 4703

ACM-ICPC 2018 南京赛区网络预赛-J_sum

A square-free integer is an integer which is indivisible by any square number except 11. For example, 6 = 2 \cdot 36=2⋅3 is square-free, but 12 = 2^2 \cdot 312=22⋅3 is not, because 2^222 is a square n...

这里RevolIA,_(:з」∠)_ 2188

近五年体内微/纳米机器人赋能肿瘤精准治疗综述:以 GBM 为重点

摘要 微/纳米机器人在实体瘤治疗领域展现出突破性潜力,通过主动运动能力解决传统纳米药物递送效率低、渗透不足等核心问题。2021-2025年间形成三条技术路线:1) 磁驱、声驱等运动增强递送实现深层渗透;2) 与免疫治疗融合实现原位免疫唤醒;3) 针对胶质母细胞瘤开发跨屏障递送系统。研究重点从单一运动性能转向"运动-分布-疗效"的系统评价,需建立标准化指标评估运动学参数、肿瘤分布均匀性和安全性。未来挑战在于临床转化的可制造性、闭环操控及生物相容性优化,特别是对血脑屏障穿透等复杂场景的系统集

AllenLV的博客 5125

I2C 协议在 Camera Sensor 驱动中的典型配置方式与实战应用

在 Linux Camera 系统中,Sensor 与主控之间的控制信令几乎都依赖于 I2C 总线完成。I2C 协议不仅承载了 Sensor 初始化、模式切换、AE/AF 等关键功能的指令传输,也是构建 v4l2\_subdev 驱动框架的核心基础。本文将围绕 Sensor 驱动中的 I2C 通信机制展开分析,从设备树节点声明到驱动代码中的传输接口调用,结合主流平台工程实战经验,详解如何构建稳定、高效、可维护的 I2C 控制路径。

努力分享一些人工智能、计算机视觉、影像等相关的知识干货! 1713

ACM-ICPC 2018 南京赛区网络赛 G题 Lpl and Energy-saving Lamps

       题目大意:有n个房间,第i个房间内有ki盏白炽灯。现在准备将这些白炽灯全部换成节能灯。管家每个月购买m盏节能灯,之后会按照房间列表一间一间地查看是否需要更换。当管家遇见一个尚未更换节能灯的房间,并且他手上有足够多的节能灯时,他会将房间内的所有白炽灯全部替换为节能灯。不管他路过这个房间后是否换了灯,他都会继续前往下一个房间。如果他走过所有房间之后手中仍有多余的节能灯,他将会把这些节能灯...

temp06的博客 465

最强AI插件Augment,适配idea、vscode,对标cursor!

Augment是一款新兴的AI辅助编码工具,能够无缝集成到IDEA和VS Code等主流IDE中,直接对标专业AI编码工具Cursor。其核心优势包括多IDE适配、无缝集成、代码理解与生成以及对话式编程体验。Augment通过插件形式保留原IDE功能和快捷键习惯,降低学习成本,同时提供深度理解项目上下文和生成高质量代码的能力。此外,Augment还具备审查变更、检查点、代理与代理自动等核心功能,支持从简单配置更改到复杂功能实现的各种开发任务。Augment代表了AI辅助编程工具的新方向,通过增强开发者熟悉的

todoitbo的博客 1万+

2018ACM/ICPC南京站网络赛G Lpl and Energy-saving Lamps(补题)

题目链接 题意:已知n个房间,每个房间需要有ai个灯,主角在给所有房间都装好节能灯之前,会每个月购买m个节能灯,同时每个月按房间编号从小到大依次给能完全满足需求的房间装节能灯,剩下的节能灯留到下个月用。接下来q个查询,询问第bi个月后已经装好灯的房间数和该月最后剩下的节能灯数。 由题可知,每次更换节能灯需要得到节能灯需求数目小于拥有数目的房间编号,那么我们可以通过线段树维护区间最小值,查询的时...

qq_38515845的博客 550

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

ACM-ICPC 2018 南京赛区网络预赛 G. Lpl and Energy-saving Lamps 经典线段树

During tea-drinking, princess, amongst other things, asked why has such a good-natured and cute Dragon imprisoned Lpl in the Castle? Dragon smiled enigmatically and answered that it is a big secret. A...

人生如戏 242

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

ccpc2018网络赛 1009

链接 http://acm.hdu.edu.cn/showproblem.php?pid=6446 题意 给你一棵树 树的边有权值 节点一开始没有序号 你用1-n的全排列给他们编号 编号n!次 对于每次编号 计算 tmp=dist[1][2]+dist[2][3]+dist[3][4]+...+dist[n-1][n]; 最后计算sigma(tmp); 题解 先上公式 计算出树...

WJHKDGHP的博客 566

ACM-ICPC 2018 南京赛区网络预赛 J. Sum 【筛法】

题目大意: f(n) 表示 n =a*b (a,b 都为非 平方倍数) ,a,b不同时的对数 计算 f(1)+f(2)+…+f(n) 题目分析:我们分析一下在和当中每个数的贡献度 举例 当 n = 8时 1的 贡献度 有 1*1 (1*2 ,1*3, 1*5,1*6,1*7 ) 后面这一部分要*2 1+5*2=11 2的贡献度 有 ...

beckyUp的博客 757

[Acwing面向模型编程]dfs

题目1:AcWing 1118. 分成互质组 分析: 枚举每个组,对于当前的组,如果枚举到的数能够放进去,那么就一定放进去(不需要另外开一个新的组),如果当前组无法再放数,则新开辟组。 一开始用的vector,一直t。看来搜索慎用stl 代码: #include <bits/stdc++.h> using namespace std; typedef long long ll;//三年竞赛一场空,不开long long见祖宗 //typedef __int128 lll; #define

玛珈山大萌新 320

ACM-ICPC 2018 南京赛区网络预赛(A.B.E.G.J.L)

A. An Olympian Math Problem 遇事不决先打表,然后发现规律, #pragma GCC optimize(2) #include <bits/stdc++.h> using namespace std; #define clr(a) memset(a,0,sizeof(a)) #define line cout<<"--------------...

辞树 1027

ACM-ICPC 2018 南京赛区网络预赛

菜鸡就过了四道题,其中一道是改的板子,一道是大佬抬了一手,一道是水题,就一道线段树是我自己写的Orz、菜哭。大佬队友又不在,慌得一批,写的自闭。 先把过了的题记录一下吧,题以后再补,心态有点崩我怎么这么菜。  A. An Olympian Math Problem Alice, a student of grade 66, is thinking about an Olympian Math...

叶子心情你不懂 768

2018 icpc 南京网络赛

题目:链接 A. An Olympian Math Problem 输出n-1即可(女朋友猜的)。 #include&lt;bits/stdc++.h&gt; using namespace std; #define ll long long ll fac[103]; int main() { ll n,T;cin&gt;&gt;T; while(T--) { ...

albertluf的博客 2357

无法拯救我的菜----南京网络赛 G. Lpl and Energy-saving Lamps

地址:https://nanti.jisuanke.com/t/30996 就是一个模拟题,n^2会超时,需要用维护一个最小值线段树,复杂度变成了nlog(n) 注意:被坑的要命的地方,一定要好好理解题意,一次可能会有多个房间的灯泡被换掉, 不是一次一个,有时不要被样例给迷惑了 先预处理1~100000月的值,然后按照询问输出 #include&lt;bits/stdc++.h&gt; ...

qq_36386435的博客 232

2018ACM/ICPC南京站网络赛J Sum

题目链接 大意是定义f(x)为满足x==a*b且a和b均不能被除1以外的平方数整除的数对(a,b)的个数,给定n,输出x从1到n的f(x)的和。 比赛中这道题从看题,到写完,再到写个暴力对拍小数据也只花了二十五分钟而已,然后一发入魂。。。(虽然这题后就陷入了漫长的卡题) 我的解题思路的产生:首先看到数据范围2e7,虽然查询很少,但一般这个范围会让我联想到线性筛;其次,大致看下样例就能知道素数...

qq_38515845的博客 1016

ACM-ICPC 2018 南京赛区网络预赛-E AC Challenge(状压DP)

Dlsj is competing in a contest with n (0 &lt; n \le 20)n(0&lt;n≤20) problems. And he knows the answer of all of these problems. However, he can submit ii-th problem if and only if he has submitted (a...

Dog_dream的博客 405

ACM-ICPC 2018 南京赛区网络预赛---总结

ACM-ICPC 2018 南京赛区网络预赛 总结 与dq队差距 4题 A 水题 B pair卡常 补题链接:https://blog.youkuaiyun.com/axuhongbo/article/details/82289535 E 裸状压dp http://www.cnblogs.com/dilthey/p/9570205.html my_code #includ...

axuhongbo的博客 2182
上一篇: 飞行路线 HYSBZ - 2763(分层图最短路)
下一篇: Count the Colors ZOJ - 1610(线段树)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值