题目大意:
  给你n个不同长度蚯蚓,每秒从里面取出最长的砍下u/v变成两只,又把剩下的加长q。
  问你在m之前的t,2t,3t...的时间上,砍的蚯蚓长度,
  以及m秒后剩下所有的蚯蚓长度。

思路:
  很容易想到用一个堆来解决,然而这样时间复杂度是O((m+n)log(m+n))的,过不去。
  所以复杂度得是线性的。
  考虑把原来的堆改成三个单调队列。
  每个蚯蚓切成两半总会有一个长的、一个短的。
  我们有q1维护原来的蚯蚓,q2维护砍下来长的一截蚯蚓,q3维护砍下来短的一截蚯蚓。
  不考虑蚯蚓的生长,我们只需要每次砍完蚯蚓扔进去就可以了。
  算长度只要把每个单位时间内增加的长度乘以时间加到蚯蚓上面就可以了。
  注意中间结果开long long,不然只有70分。

 #include<queue>
#include<cstdio>
#include<cctype>
#include<algorithm>
#include<functional>
typedef long long int64;
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'';
while(isdigit(ch=getchar())) x=(((x<<)+x)<<)+(ch^'');
return x;
}
const int N=;
int a[N];
std::queue<int> q1,q2,q3;
inline int getmax() {
if(q1.empty()&&q2.empty()) {
const int ret=q3.front();
q3.pop();
return ret;
}
if(q1.empty()&&q3.empty()) {
const int ret=q2.front();
q2.pop();
return ret;
}
if(q2.empty()&&q3.empty()) {
const int ret=q1.front();
q1.pop();
return ret;
}
if(q1.empty()) {
if(q2.front()>q3.front()) {
const int ret=q2.front();
q2.pop();
return ret;
}
const int ret=q3.front();
q3.pop();
return ret;
}
if(q2.empty()) {
if(q1.front()>q3.front()) {
const int ret=q1.front();
q1.pop();
return ret;
}
const int ret=q3.front();
q3.pop();
return ret;
}
if(q3.empty()) {
if(q1.front()>q2.front()) {
const int ret=q1.front();
q1.pop();
return ret;
}
const int ret=q2.front();
q2.pop();
return ret;
}
if(q1.front()>=q2.front()&&q1.front()>=q3.front()) {
const int ret=q1.front();
q1.pop();
return ret;
}
if(q2.front()>=q1.front()&&q2.front()>=q3.front()) {
const int ret=q2.front();
q2.pop();
return ret;
}
if(q3.front()>=q1.front()&&q3.front()>=q2.front()) {
const int ret=q3.front();
q3.pop();
return ret;
}
return ;
}
int main() {
int n=getint(),m=getint(),q=getint(),u=getint(),v=getint(),t=getint();
for(register int i=;i<n;i++) {
a[i]=getint();
}
std::sort(&a[],&a[n],std::greater<int>());
for(register int i=;i<n;i++) {
q1.push(a[i]);
}
for(register int i=;i<=m;i++) {
const int max=getmax()+q*(i-);
if(!(i%t)) printf("%d ",max);
q2.push(std::max((int64)max*u/v-q*i,(int64)max-(int64)max*u/v-(int64)q*i));
q3.push(std::min((int64)max*u/v-q*i,(int64)max-(int64)max*u/v-(int64)q*i));
}
putchar('\n');
for(register int i=;!q1.empty()||!q2.empty()||!q3.empty();i++) {
const int max=getmax();
if(!(i%t)) printf("%d ",max+q*m);
}
return ;
}

[NOIp2016提高组]蚯蚓的更多相关文章

  1. Noip2016 提高组 蚯蚓

    刚看到这道题:这题直接用堆+模拟不就可以了(并没有认真算时间复杂度) 于是用priority_queue水到了85分-- (STL大法好) 天真的我还以为是常数问题,于是疯狂卡常--(我是ZZ) 直到 ...

  2. Luogu P2827 [NOIp2016提高组]蚯蚓 | 神奇的队列

    题目链接 80分思路: 弄一个优先队列,不停地模拟,切蚯蚓时就将最长的那一条出队,然后一分为二入队,简单模拟即可.还要弄一个标记,表示从开始到当前时间每一条蚯蚓应该加上的长度,操作时就加上,入队时就减 ...

  3. 洛谷P2827 [NOIP2016 提高组] 蚯蚓 (二叉堆/队列)

    容易想到的是用二叉堆来解决,切断一条蚯蚓,其他的都要加上一个值,不妨用一个表示偏移量的delta. 1.取出最大的x,x+=delta: 2.算出切断后的两个新长度,都减去delta和q: 3.del ...

  4. 【题解】NOIP2016提高组 复赛

    [题解]NOIP2016提高组 复赛 传送门: 玩具谜题 \(\text{[P1563]}\) 天天爱跑步 \(\text{[P1600]}\) 换教室 \(\text{[P1850]}\) 组合数问 ...

  5. 【题解】NOIP2016 提高组 简要题解

    [题解]NOIP2016 提高组 简要题解 玩具迷题(送分) 用异或实现 //@winlere #include<iostream> #include<cstdio> #inc ...

  6. NOIP2016提高组解题报告

    NOIP2016提高组解题报告 更正:NOIP day1 T2天天爱跑步 解题思路见代码. NOIP2016代码整合

  7. [日记&做题记录]-Noip2016提高组复赛 倒数十天

    写这篇博客的时候有点激动 为了让自己不颓 还是写写日记 存存模板 Nov.8 2016 今天早上买了两个蛋挞 吃了一个 然后就做数论(前天晚上还是想放弃数论 但是昨天被数论虐了 woc noip模拟赛 ...

  8. 【NOIP2016提高组day2】蚯蚓

    那么我们开三个不上升队列, 第一个记录原来的蚯蚓, 第二个记录乘以p的蚯蚓 第三个记录乘以(1-p)的蚯蚓, 在记录每条就要入队列的时间,就可以求出增加的长度 每次比较三个队列的队首,取最大的值x的切 ...

  9. 【NOIP2016提高组】 Day2 T2 蚯蚓

    题目传送门:https://www.luogu.org/problemnew/show/P2827 自测时被题面所误导...,题面中说逢t的倍数才输出答案,以为有什么玄妙的方法直接将m次操作变成了m/ ...

随机推荐

  1. hdu 1556(线段树之扫描线)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1556 Color the ball Time Limit: 9000/3000 MS (Java/Ot ...

  2. ipython notebook环境搭建

    默认已经装好python基本环境,再进行下面步骤: 1. 下载安装IPython:  c:>pip.exe install ipython 系统就会去网上寻找ipython的包, 进行下载及安装 ...

  3. 网络应用框架Netty快速入门

    一 初遇Netty Netty是什么? Netty 是一个提供 asynchronous event-driven (异步事件驱动)的网络应用框架,是一个用以快速开发高性能.可扩展协议的服务器和客户端 ...

  4. JDBC+Servlet+JSP实现基本的增删改查(简易通讯录)

    前言: 最近学习JavaWeb的过程中,自己实践练手了几个小项目,目前已经上传到我的Github上https://github.com/Snailclimb/JavaWebProject.目前只上传了 ...

  5. bzoj 1179 Atm

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1179 题解: 一道比较综合的图论题 直接讲正解: 如果这个图G中存在某个强连通分量,那么这 ...

  6. C#杂七杂八记录

     1. 日期格式表示 DateTime.Now.ToString("yyyy-MM-dd")  2. div跟屏幕的高度一样高,自适应 <style> html, bo ...

  7. expose a port on a living Docker container

    if you have a container that with something running on its port 8000, you can run wget http://contai ...

  8. scrapy框架搭建与第一个实例

    scrapy是python的一个网络爬虫框架,关于它的介绍有很多资料,这里不做过多介绍(好吧我承认我还不是很懂...).我现在还在摸索阶段,因为用scrapy爬取的第一个网站非常简单,不涉及登陆.验证 ...

  9. mysql 服务器配置

    Windows: 1.在bin目录下执行mysqld.exe --install-manual安装服务(删除命令是mysqld.exe --remove) 2.执行net start mysql启动服 ...

  10. hdu 2955(概率转化,01背包)

    Hot~~招聘——巴卡斯(杭州),壹晨仟阳(杭州),英雄互娱(杭州) (包括2016级新生)除了校赛,还有什么途径可以申请加入ACM校队? Robberies Time Limit: 2000/100 ...