<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Codeforces Round #594 (Div. 1) C. Queue in the Train 模擬

      C. Queue in the Train

      There are ?? seats in the train's car and there is exactly one passenger occupying every seat. The seats are numbered from 1 to ?? from left to right. The trip is long, so each passenger will become hungry at some moment of time and will go to take boiled water for his noodles. The person at seat ?? (1≤??≤??) will decide to go for boiled water at minute ????.

      Tank with a boiled water is located to the left of the 1-st seat. In case too many passengers will go for boiled water simultaneously, they will form a queue, since there can be only one passenger using the tank at each particular moment of time. Each passenger uses the tank for exactly ?? minutes. We assume that the time it takes passengers to go from their seat to the tank is negligibly small.

      Nobody likes to stand in a queue. So when the passenger occupying the ??-th seat wants to go for a boiled water, he will first take a look on all seats from 1 to ???1. In case at least one of those seats is empty, he assumes that those people are standing in a queue right now, so he would be better seating for the time being. However, at the very first moment he observes that all seats with numbers smaller than ?? are busy, he will go to the tank.

      There is an unspoken rule, that in case at some moment several people can go to the tank, than only the leftmost of them (that is, seating on the seat with smallest number) will go to the tank, while all others will wait for the next moment.

      Your goal is to find for each passenger, when he will receive the boiled water for his noodles.

      Input

      The first line contains integers ?? and ?? (1≤??≤100000, 1≤??≤109) — the number of people and the amount of time one person uses the tank.

      The second line contains ?? integers ??1,??2,…,???? (0≤????≤109) — the moments when the corresponding passenger will go for the boiled water.

      Output

      Print ?? integers, where ??-th of them is the time moment the passenger on ??-th seat will receive his boiled water.

      Example

      input
      5 314
      0 310 942 628 0
      output
      314 628 1256 942 1570

      Note

      Consider the example.

      At the 0-th minute there were two passengers willing to go for a water, passenger 1 and 5, so the first passenger has gone first, and returned at the 314-th minute. At this moment the passenger 2 was already willing to go for the water, so the passenger 2 has gone next, and so on. In the end, 5-th passenger was last to receive the boiled water.

      題意

      火車上面一共有n個(gè)人要打水,每個(gè)人會(huì)選擇在t[i]的時(shí)間去打水,每次打水需要花費(fèi)p的代價(jià)。每個(gè)人都不喜歡排隊(duì),如果這個(gè)人發(fā)現(xiàn)他前面有人沒在座位上,他就不會(huì)去打水;如果有多個(gè)人同時(shí)去打水,序號(hào)小的會(huì)優(yōu)先去排隊(duì);排隊(duì)按照先后順序打水。

      題解

      純模擬題,維護(hù)一個(gè)打水的優(yōu)先隊(duì)列,維護(hù)一個(gè)排隊(duì)的隊(duì)列,維護(hù)一個(gè)等待序列。

      然后模擬模擬就好了。 那么問題來了,這道題真的值div1 C的難度嗎

      代碼

      #include<bits/stdc++.h>
      using namespace std;
      priority_queue<pair<long long,int> >Q1;
      priority_queue<int> Q2;
      set<int> EmptyQueue;
      queue<int>Q3;
      const int maxn = 1e5+7;
      int n;
      long long p;
      long long ans[maxn];
      int main(){
      	scanf("%d%lld",&n,&p);
      	for(int i=0;i<n;i++){
      		long long t;
      		scanf("%lld",&t);
      		Q1.push(make_pair(-t,-i));
      	}
      	long long now = 0;
      	while(!Q1.empty()||!Q2.empty()||!Q3.empty()){
      		if(Q3.empty()&&Q2.empty()){
      			now = max(now,-Q1.top().first);
      		}
      		while(!Q1.empty()&& -Q1.top().first<=now+p){
      			if(EmptyQueue.empty()||(*EmptyQueue.begin()>-Q1.top().second)){
      				Q3.push(-Q1.top().second);
      				EmptyQueue.insert(-Q1.top().second);
      			} else {
      				Q2.push(Q1.top().second);
      			}
      			Q1.pop();
      		}
      		if(!Q3.empty()){
      			ans[Q3.front()]=now+p;
      			now=now+p;
      			EmptyQueue.erase(Q3.front());
      			Q3.pop();
      		}
      		if(!Q2.empty()&&Q3.empty()){
      			Q3.push(-Q2.top());
      			EmptyQueue.insert(-Q2.top());
      			Q2.pop();
      		}
      	}
      	for(int i=0;i<n;i++)
      		cout<<ans[i]<<" ";
      	cout<<endl;
      }
      
      posted @ 2019-11-13 11:47  qscqesze  閱讀(410)  評(píng)論(1)    收藏  舉報(bào)
      主站蜘蛛池模板: 国产精品白丝一区二区三区| 日本xxxx色视频在线播放| 国产综合视频精品一区二区| 国产亚洲第一精品| 黄又色又污又爽又高潮| 精品国产乱码久久久久app下载| 日韩国产中文字幕精品| 久久婷婷国产精品香蕉| 亚洲一区久久蜜臀av| 在线看av一区二区三区| 成人午夜电影福利免费| 极品美女扒开粉嫩小泬图片 | 久色伊人激情文学你懂的| 国产中文字幕在线一区| 日本无遮挡吸乳呻吟视频| 亚洲人成色99999在线观看| 国产精品不卡一区二区在线| 国产18禁黄网站禁片免费视频| 少妇被粗大的猛烈进出动视频| 国产91精品一区二区蜜臀| 国产精品中文字幕二区| 欧美三级a做爰在线观看| 久久这里只精品热免费99| 午夜精品极品粉嫩国产尤物| 中文字幕在线日韩一区| 亚洲国产长腿丝袜av天堂| 亚洲一二三区精品与老人| 天天躁日日躁狠狠躁2018| 蜜臀av午夜精品福利| 国产精品无码久久久久AV| 日韩精品成人区中文字幕| 色噜噜久久综合伊人一本| 亚洲精品宾馆在线精品酒店| 色综合色综合久久综合频道| 国产精品大全中文字幕| 国产精品爽黄69天堂a| 天天爽天天摸天天碰| 亚洲偷自拍另类一区二区| 亚洲欧洲日产国码久在线| 国产亚洲av夜间福利香蕉149 | 午夜在线不卡|