日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Lpl and Energy-saving Lamps 计蒜客多校

發(fā)布時(shí)間:2024/1/8 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Lpl and Energy-saving Lamps 计蒜客多校 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題意:給你n個(gè)房間,每個(gè)房間給你一個(gè)燈泡數(shù),再給你每天可以增加的新燈泡數(shù)m,你每次都要從左到右全都更新一遍,更新方法是:如果手中的燈泡個(gè)數(shù)大于等于房間的燈泡個(gè)數(shù)就更新這個(gè)房間,然后繼續(xù)向下,否則就跳過(guò),再繼續(xù)往下。然后給你q個(gè)詢問(wèn),問(wèn)你第幾天的情況:更新完的房間數(shù),手中剩余的燈泡數(shù)。

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.

樣例輸入復(fù)制

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

樣例輸出復(fù)制

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

思路:用線段樹來(lái)維護(hù)每個(gè)區(qū)間的最小值,如果某次更新完后房間內(nèi)的待更新燈泡數(shù)變?yōu)榱?#xff0c;那么不在考慮此房間,這樣每次查找符合條件的房間就只需要O(logn)的時(shí)間,還要注意如果可以要盡量從左兒子開始更新,因?yàn)轭}意是從左向右更新!

代碼:

#include <cstdio>
#include <algorithm>
using namespace std;
struct Node
{
? ? int l,r,rt,v;
}a[1008611];
struct Node1
{
? ? int l,r;
}b[1008611];
int ans1=0,ans2,cou;
void push_up(int rt)
{
? ? if(a[rt*2].v!=0&&a[rt*2+1].v!=0)
? ? ? ?a[rt].v=min(a[rt*2].v,a[rt*2+1].v);
? ? else if(a[rt*2].v==0&&a[rt*2+1].v!=0)
? ? {
? ? ? ? a[rt].v=a[rt*2+1].v;
? ? }
? ? else if(a[rt*2+1].v==0&&a[rt*2].v!=0)
? ? {
? ? ? ? a[rt].v=a[rt*2].v;
? ? }
? ? else if(a[rt*2+1].v==0&&a[rt*2].v==0)
? ? {
? ? ? ? a[rt].v=0;
? ? }
}
void build(int rt,int l,int r)
{
? ? a[rt].l=l;
? ? a[rt].r=r;
? ? int m=(l+r)/2;
? ? if(l==r)
? ? {
? ? ? ? scanf("%d",&a[rt].v);
? ? ? ? return;
? ? }
? ? build(rt*2,l,m);
? ? build(rt*2+1,m+1,r);
? ? push_up(rt);
}
void update(int rt)
{
? ? int m=(a[rt].l+a[rt].r)/2;
? ? if(a[rt].l==a[rt].r)
? ? {
? ? ? ? ans2-=a[rt].v;
? ? ? ? a[rt].v=0;
? ? ? ? cou++;
? ? ? ? ans1++;
? ? ? ? return;
? ? }
? ? if(ans2>=a[rt].v&&a[rt].v!=0)
? ? {
? ? ? ? if(ans2>=a[rt*2].v&&a[rt*2].v!=0)
? ? ? ? update(rt*2);
? ? ? ? else if(ans2>=a[rt*2+1].v)
? ? ? ? {
? ? ? ? ? ? update(rt*2+1);
? ? ? ? }
? ? ? ? push_up(rt);
? ? }
}
int main()
{
? ? int n,m;
? ? scanf("%d%d",&n,&m);
? ? ans2=m;
? ? int i,k=1;
? ? build(1,1,n);
? ? while(cou<n)
? ? {
? ? ? ? while(ans2>=a[1].v&&a[1].v!=0)
? ? ? ? {
? ? ? ? ? ? update(1);
? ? ? ? }
? ? ? ? if(ans2>=a[1].v)
? ? ? ? {
? ? ? ? ? ? ?b[k].l=ans1;
? ? ? ? ? ? ?b[k++].r=ans2;
? ? ? ? ? ? ?ans2+=m;
? ? ? ? }
? ? ? ? while(ans2<a[1].v)
? ? ? ? {
? ? ? ? ? ? b[k].l=ans1;
? ? ? ? ? ? b[k++].r=ans2;
? ? ? ? ? ? ans2+=m;
? ? ? ? }
? ? }
? ? int mm;
? ? scanf("%d",&mm);
? ? for(i=1;i<=mm;i++)
? ? {
? ? ? ? int t;
? ? ? ? scanf("%d",&t);
? ? ? ? if(t>=k)
? ? ? ? ? ? printf("%d %d\n",b[k-1].l,b[k-1].r);
? ? ? ? else
? ? ? ? ? ? printf("%d %d\n",b[t].l,b[t].r);
? ? }
? ? return 0;
}
線段樹能做的事還是很多的,一種很強(qiáng)大的數(shù)據(jù)結(jié)構(gòu)!似乎只要是對(duì)連續(xù)的區(qū)間進(jìn)行處理都有可能用到線段樹。

?

總結(jié)

以上是生活随笔為你收集整理的Lpl and Energy-saving Lamps 计蒜客多校的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 午夜精品久久久久久久久久 | 天天澡天天狠天天天做 | 极品久久久久 | 久久午夜夜伦鲁鲁片 | 亚洲精品在线中文字幕 | 亚洲福利电影网 | 国产区精品视频 | 一区高清| 成人夜间视频 | 超碰免费97 | 日日射射| 久久久美女视频 | 挪威xxxx性hd极品 | 夜噜噜| 色欧美片视频在线观看 | 亚洲欧美日韩一区 | 色婷婷精品久久二区二区密 | 裸体一区二区三区 | 男女啪啪国产 | 五月婷婷六月合 | 综合色播 | 欧美日韩精品久久久免费观看 | 丁香花电影免费播放在线观看 | 久久久久久亚洲av毛片大全 | 精品免费一区二区三区 | 视频一二区 | 夜夜操夜夜摸 | 亚洲av无码一区二区三区人 | 亚洲自拍偷拍一区 | 小珊的性放荡羞辱日记 | 91看大片 | 少妇高潮一区二区三区 | 亚洲精品观看 | 久久久久亚洲精品 | 日韩3区 | 小毛片 | 三级在线网站 | 操校花视频 | 精品黑人一区二区三区 | 成年人视频免费看 | 色就是色亚洲色图 | 五月天看片 | 国产a国产片国产 | 免费看黄色片子 | 椎名由奈av一区二区三区 | 99er精品视频 | 亚洲第一色在线 | 大乳村妇的性需求 | 色老头网址 | 污视频网站免费看 | 美女隐私无遮挡 | 国产精品一区二区入口九绯色 | 男女激情大尺度做爰视频 | 男人天堂网在线视频 | 在线观看国产91 | 精品久久久久中文慕人妻 | 91色视频在线观看 | 九热视频在线观看 | 日韩欧美一级 | 亚洲av综合色区无码一二三区 | 欧美日韩中文字幕一区 | 78日本xxxxxxxxx59 亚洲图片小说视频 | 日韩怡红院 | 国自产拍偷拍精品啪啪一区二区 | 中文字幕一二三四 | 超碰在线超碰 | 亚洲欧美日韩专区 | 欧美一级性生活视频 | 人与动物2免费观看完整版电影高清 | 国产精品一区二区三区不卡 | 日本激情视频一区二区三区 | 久草手机在线 | 久久av喷吹av高潮av萌白 | 骚虎视频最新网址 | 九七影院在线观看免费观看电视 | 永久免费看黄网站 | 国产美女免费观看 | 91中文在线 | 精品视频一区二区三区四区五区 | 狠狠做深爱婷婷综合一区 | 日韩精品视频一区二区在线观看 | 人禽l交视频在线播放 视频 | 国产精品成av人在线视午夜片 | a无一区二区三区 | 亚洲福利视频网 | 国产影视一区 | 大桥未久恸哭の女教师 | 欧美粉嫩videosex极品 | 欧美日韩在线一区二区 | 天天谢天天干 | 中文字幕无码日韩专区免费 | 极品蜜桃臀肥臀-x88av | 激情爱爱网 | 精品国产亚洲AV | 日韩熟妇一区二区三区 | 午夜精华| 贝利弗山的秘密1985版免费观看 | 日韩欧美亚洲精品 | 麻豆精品一区二区 |