题目大意:
  给你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. Windows下基于python3使用word2vec训练中文维基百科语料(二)

    在上一篇对中文维基百科语料处理将其转换成.txt的文本文档的基础上,我们要将为文本转换成向量,首先都要对文本进行预处理 步骤四:由于得到的中文维基百科中有许多繁体字,所以我们现在就是将繁体字转换成简体 ...

  2. 特征工程(Feature Engineering)

    一.什么是特征工程? "Feature engineering is the process of transforming raw data into features that bett ...

  3. 定制LFS镜像及安装过程

    定制LFS镜像及安装过程 http://blog.csdn.net/decload/article/details/7407698 一.定制LFS镜像        定制LFS镜像的思想是在已构建完成 ...

  4. Shell脚本中引用、调用另一个脚本文件的2种方法

    Shell脚本中引用.调用另一个脚本文件的2种方法 http://www.jb51.net/article/67903.htm

  5. SqlServer存储过程中使用事务,示例

    create proc pro_GetProTrans @GoodsId int, @Number int, @StockPrice money, @SupplierId int, @EmpId in ...

  6. HTML 知识点总结

    HTML基本语法 HTML标签 单标签 <标签名>或<标签名 /> 双标签 <标签名>内容</标签名> 跟标签也叫元素(根元素) 属性 属性属于标签 一 ...

  7. FineReport——登录不到决策系统

    在不断的测试过程中,可能会造成缓存数据的累积,所以在登录过程中可能会出现登录不到决策系统,而是跳转到某一模板页面 解决方法就是清理缓存或者换一个浏览器测试.

  8. 在Redis集群中使用pipeline批量插入

    在Redis集群中使用pipeline批量插入 由于项目中需要使用批量插入功能, 所以在网上查找到了Redis 批量插入可以使用pipeline来高效的插入, 示例代码如下: Pipeline p = ...

  9. 【hdoj_1398】SquareCoins(母函数)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1398 此题采用母函数的知识求解,套用母函数模板即可: http://blog.csdn.net/ten_s ...

  10. sql server2000存储过程sp_password

    create procedure sp_password @old sysname = NULL, -- the old (current) password @new sysname, -- the ...