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 4
1 2 3 4 5 6
1 2
2 5
5 6
4 6

Sample Output

2 3 3 5 5 5

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

#include <bits/stdc++.h>

#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lr rt<<1
#define rr rt<<1|1 using namespace std; typedef long long LL;
const int N = ; LL osum;
int n,q; struct ST
{
int l,r;
LL lazy,date;
int mid(){
return (l+r)>>;
}
}st[N<<]; 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 + ) * st[lr].lazy;
st[rr].date = (LL)( st[rr].r - st[rr].l + ) * st[rr].lazy;
st[rt].lazy=;
}
} void build(int l,int r,int rt)
{
st[rt].l=l,st[rt].r=r;
st[rt].lazy=;
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 + ) * 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=;
build(,n,);
while(q--)
{
scanf("%d%d",&x,&y);
if(x>y)swap(x,y);
LL tmp = query(x,y,);
double ave = (long double)tmp/(y-x+);
if( st[].date <= osum ) update(x, y,,(LL)ceil(ave));
else update( x, y, ,(LL)floor(ave) );
}
show();
puts("");
}
return ;
}

ZOJ 2706 Thermal Death of the Universe的更多相关文章

  1. ZOJ 2706 Thermal Death of the Universe (线段树)

    题目链接:ZOJ 2706 Thermal Death of the Universe (线段树) 题意:n个数.m个操作. 每一个操作(a,b)表示(a,b)全部值更新为这个区间的平均数:1.当前的 ...

  2. zoj 2706 线段树

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1706 trick:关于正数和负数的整除问题,正数整除是自动向下取整的 ...

  3. Soj题目分类

    -----------------------------最优化问题------------------------------------- ----------------------常规动态规划 ...

  4. [转]Hooked on DTrace

    source link: 1.http://blog.bignerdranch.com/1907-hooked-on-dtrace-part-1/ 2.http://blog.bignerdranch ...

  5. HDU 3689 Infinite monkey theorem [KMP DP]

    Infinite monkey theorem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...

  6. hdu 3689 杭州 10 现场 J - Infinite monkey theorem 概率dp kmp 难度:1

    J - Infinite monkey theorem Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d &am ...

  7. hdu 3689 Infinite monkey theorem

    Infinite monkey theorem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

  8. HDU 3689 Infinite monkey theorem(DP+trie+自动机)(2010 Asia Hangzhou Regional Contest)

    Description Could you imaging a monkey writing computer programs? Surely monkeys are smart among ani ...

  9. HUD3689 Infinite monkey theorem

    Infinite monkey theorem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

随机推荐

  1. JS合并两个函数

    /** * 合并两个函数 * @param functionA 先执行 * @param functionB 执行完 functionA 后返回 * @returns {*} */ function ...

  2. 线程工具类 - Semaphore(信号量)

    Semaphore官方文档 一.使用信号量实现线程间的通信 /** * Demo:使用信号量实现线程间通信*/ public class SemaphoreDemo { public static v ...

  3. MyBatis(五)

    MyBatis Generator CMyBatis代码生成器,简称 MBG)

  4. ELK Stack

    原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11488404.html ELK workflow log -> filebeat -> l ...

  5. python每日练习0730

    """ 1. 现有面包.热狗.番茄酱.芥末酱以及洋葱,数字显 示有多少种订购组合, 其中面包必订,0 不订,1 订,比如 10000,表示只订购面包 "&quo ...

  6. python学习笔记(七)模块

    一个python文件就是一个模块 1.标准模块 python自带的,不需要你安装的 2.第三方模块 需要安装,别人提供的,例:pip install radis 如果提示没有pip,把python下s ...

  7. dubbo-go 中的 TPS Limit 设计与实现

    前言 Apache Dubbo 是由阿里开源的一个RPC框架,除了基本的 RPC 功能以外,还提供了一整套的服务治理相关功能.目前它已经是 Apache 基金会下的顶级项目. 而 dubbo-go 则 ...

  8. 5G即将到来!我们需要一部怎样的手机呢?

    随着5G技术研发试验即将于年底宣告完成,也就意味着2019年起,5G商用将会宣布启动,现在OPPO.vivo.小米.华为.一加等众多手机厂商也宣布启动5G计划,这时5G势必会掀起一股新鲜的血液,5G手 ...

  9. [USACO16JAN]愤怒的奶牛Angry Cows (单调队列优化dp)

    题目链接 Solution 应该可以用二分拿部分分,时间 \(O(n^2logn)\) . 然后可以考虑 \(n^2\) \(dp\) ,令 \(f_i\) 代表 \(i\) 点被激活,然后激活 \( ...

  10. HY 的惩罚 (Trie 树,博弈论)

    [问题描述] hy 抄题解又被老师抓住了,现在老师把他叫到了办公室. 老师要 hy 和他玩一个游 戏.如果 hy 输了,老师就要把他开除信息组; 游戏分为 k 轮.在游戏开始之前,老师会将 n 个由英 ...