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;
本届挑战赛亚军方案:基于大模型和多AGENT协同的运维 我们分别构建了异常检测基础模型,一旦系统接受到异常即会通知LLM主管Agent,主管Agent对异常问题进行决策与子领域Agent进行桥接,多个子领域Agent协同工作,实现运维故障自动诊断和多个任务模型的编排,提升运维效率。 阅读详情

相关推荐

CDO批量处理nc文件:5分钟搞定CMIP6数据双线性插值(附完整代码)

本文详细介绍了如何使用CDO工具链中的`remapbil`命令,快速实现CMIP6数据的批量双线性插值处理。通过环境配置、核心操作步骤、高级优化技巧及典型报错解决方案,帮助科研人员高效处理大规模nc文件,显著提升气象数据处理效率。

weixin_29267307的博客 292

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

手把手教你学Simulink——基于Simulink的轮毂电机独立驱动转矩矢量分配

阐述了轮毂电机独立驱动的核心价值与转矩分配的必要性在 Simulink 中实现了完整的“上层稳定控制 + 下层最优分配”架构对比了三种分配策略在极限工况下的性能差异提供了工程落地的关键考量特斯拉 Cybertruck(后轮双电机矢量控制)Rivian R1T(四电机坦克掉头)宝马 iX(精准牵引力控制)核心思想“以软件定义底盘,以算法驾驭动力;化四轮之独立,为整车之协同。—— 让汽车在极限边缘依然从容不迫。

MHD0815的博客 369

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

VerilogEval实战指南:从基准测试到模型微调的全流程解析

本文提供了VerilogEval实战指南,详细解析了从基准测试到模型微调的全流程。VerilogEval是一个自动化、标准化的测试框架,用于客观评估大语言模型生成Verilog硬件代码的能力。文章涵盖了环境搭建、核心机制解析、利用其生成合成数据进行模型微调的策略,以及如何将其工程化集成到自动化评估流程中,为硬件设计领域的AI应用提供了完整的方法论。

yy01234的博客 1005

centos7安装db2 version11.1

centos7安装db2 version11.1

AKA石头 1062

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

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

qq_36782366的博客 424

海康/大华设备如何接入GB28181平台?最新2022版互联避坑指南

本文详细解析了海康/大华设备接入GB28181平台的最新2022版互联避坑指南,涵盖参数配置、实时视音频点播协议交互及典型故障排查。重点介绍了GB/T28181-2022标准下的设备编码规范、SIP服务器配置及媒体流保活机制,帮助工程团队高效解决设备离线和媒体流中断等问题。

weixin_30733003的博客 686

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

嵌入式Zephyr RTOS面试题及参考答案

在Zephyr中,为自定义外设编写Devicetree绑定(Bindings)有助于内核理解设备树中自定义外设节点的含义和属性。首先,需要创建一个.yaml格式的绑定文件,通常存放在目录下对应的子目录中,文件名应能反映外设的类型和功能。绑定文件的开头要定义基本信息,包括字段,用于简要描述外设的功能和用途;compatible字段,它是一个字符串列表,用于匹配设备树中自定义外设节点的compatible属性,设备树节点和绑定文件通过这个字段关联起来。接下来,要定义外设节点的属性。使用properties。

大模型大数据攻城狮的专栏 986

开源项目-智能算法中台管理系统

智能算法中台管理系统,系统主要有样本中心,算法中心,模型中心等模块

u010479989的博客 2998

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

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

temp06的博客 465

在 SAP S/4HANA 的 BP 事务里做保存前校验:BDT 事件、BUPA_FURTHER_CHECKS 与 CVI 扩展 BAdI 一次讲透

SAP BP事务保存前校验机制解析 摘要:本文系统梳理了SAP BP事务保存前的校验机制,揭示了三种关键校验点的差异与适用场景: BDT框架DCHCK事件:最靠近UI层,适合屏幕字段级校验,但API调用时可能失效 Classic BAdI BUPA_FURTHER_CHECKS:全局拦截点,可阻断整个BP保存,适合核心业务规则 CVI扩展校验:仅管控供应商/客户段落,需注意可能产生"BP已保存但段落未保存"的情况 文章通过真实案例(如黑名单校验、付款冻结等)展示了各校验点的最佳实践,并特

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 310

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

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

qq_38515845的博客 550

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

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

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

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、付费专栏及课程。

余额充值