博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ZOJ 2706 Thermal Death of the Universe
阅读量:5907 次
发布时间:2019-06-19

本文共 4082 字,大约阅读时间需要 13 分钟。

 

Thermal Death of the Universe

Time Limit: 10 Seconds                                    
Memory Limit: 32768 KB                            

Johnie has recently learned about the thermal death concept.  Given that the Global Entropy always increases, it will end in the  thermal death of the Universe. The idea has impressed him extremely.  Johnie does not want the universe to die this way. 

So he decided to emulate the process to check how soon the thermal death can occur. He has created the mathematical model of the process in the following way. The universe is represented as an array of n integer numbers. The life of the universe is represented as the sequence of the following entropy operations: take elements from ith to jth and replace them with their average value. Since their average is not necessarily integer, it is rounded. 

To keep balance, rounding is performed either up, or down depending on the current sum of all elements of the array. If their sum is less or equal to the sum of the original array, the rounding is  performed up, in the other case --- down.

Given the initial array and the sequence of the entropy operations, find the contents of the resulting array.

Input

There are mutiple cases in the input file.

The first line of each case contains n and m --- the size of the array and the number of operations respectively (1 <= m, n <= 30,000 ). The second line contains n integer numbers --- the initial contents of the array, they do not exceed 109 by their absolute value. The following m lines contain two integer numbers each and describe entropy operations.

There is an empty line after each case.

Output

Output n integer numbers --- the contents of the array after all operations.

There should be am empty line after each case.

Sample Input

6 41 2 3 4 5 61 22 55 64 6

Sample Output

2 3 3 5 5 5

 

赤裸裸的一条线段树,然后需要延时更新~~注意细节就是求值的时候要强转换成(LL)(r-l +1)*v

 

#include 
#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define lr rt<<1#define rr rt<<1|1using namespace std;typedef long long LL;const int N = 30005;LL osum;int n,q;struct ST{ int l,r; LL lazy,date; int mid(){ return (l+r)>>1; }}st[N<<2];void push_down(int rt){ if( st[rt].lazy ) { st[lr].lazy = st[rr].lazy = st[rt].lazy; st[lr].date = (LL)( st[lr].r - st[lr].l +1 ) * st[lr].lazy; st[rr].date = (LL)( st[rr].r - st[rr].l +1 ) * st[rr].lazy; st[rt].lazy=0; }}void build(int l,int r,int rt){ st[rt].l=l,st[rt].r=r; st[rt].lazy=0; if(l==r) { scanf("%lld",&st[rt].date); osum += st[rt].date; return ; } int m=st[rt].mid(); build(lson); build(rson); st[rt].date = st[rr].date + st[lr].date;}void update(int l,int r,int rt,LL v){ if( l == st[rt].l && st[rt].r == r ) { st[rt].date= (LL) ( r - l + 1 ) * v ; st[rt].lazy=v; return; } push_down(rt); int m=st[rt].mid(); if( l > m ) update(l,r,rr,v); else if(r <= m) update(l,r,lr,v); else{ update(lson,v); update(rson,v); } st[rt].date = st[rr].date + st[lr].date;}LL query(int l,int r,int rt){ if( l==st[rt].l && r==st[rt].r ) { return st[rt].date; } push_down(rt); int m=st[rt].mid(); if(l > m) return query(l,r,rr); else if( r <= m) return query(l,r,lr); else return query(lson)+query(rson);}void show(int rt){ if(st[rt].l == st[rt].r) { printf("%lld",st[rt].date); if(st[rt].r != n)printf(" "); else printf("\n"); return; } int m=st[rt].mid(); push_down(rt); show(lr); show(rr);}int main(){ int x,y; // freopen("in.txt","r",stdin); while(~scanf("%d%d",&n,&q)){ osum=0; build(1,n,1); while(q--) { scanf("%d%d",&x,&y); if(x>y)swap(x,y); LL tmp = query(x,y,1); double ave = (long double)tmp/(y-x+1); if( st[1].date <= osum ) update(x, y,1,(LL)ceil(ave)); else update( x, y, 1,(LL)floor(ave) ); } show(1); puts(""); } return 0;}

 

转载于:https://www.cnblogs.com/hlmark/p/3916092.html

你可能感兴趣的文章
Exchange Server邮箱管理
查看>>
在Android(OPhone)模拟器中加载和使用SDCard卡
查看>>
Windows Server 2008 显示隐藏文件 扩展名 和隐藏的文件
查看>>
linux(虚拟机中)与windows共享文件两种方法
查看>>
Exchange 2013信息权限保护之ADRMS安装
查看>>
在图书馆里寻找清静的自我
查看>>
X5平方速算法的证明
查看>>
面试题解(2):loop相关
查看>>
之关于单一职责原则
查看>>
【笔记5】用pandas实现矩阵数据格式的推荐算法 (基于物品的协同)
查看>>
iOS设置拍照retake和use按钮为中文简体
查看>>
Android--通知之Toast
查看>>
【HoorayOS】开源的Web桌面应用框架(第三版 v120421)
查看>>
webview同步cookies
查看>>
lucene LZ4 会将doc存储在一个chunk里进行Lz4压缩 ES的_source便如此
查看>>
[sql] like in 实现参数化查询的问题
查看>>
Spark 架构和组件集的简要概述
查看>>
全局替换字体,开源库更方便!!!
查看>>
使用即时文件初始化提高SQL Server性能
查看>>
MF前传——探索者一号简介
查看>>