ural2014 Zhenya moves from parents
Zhenya moves from parents
Memory limit: 64 MB
- The date when it took place
- The sum of earned or spent money
Input
Output
Sample
input | output |
---|---|
5 |
-1000 |
分析:当前的盈亏始终对之后的盈亏有影响,且要维护整体最小值,所以用线段树解决;
注意要用long long;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=1e5+;
const int dis[][]={{,},{-,},{,-},{,}};
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p%mod;p=p*p%mod;q>>=;}return f;}
int n,m,k,t,c[maxn];
struct Node
{
ll Min, lazy;
} T[maxn<<];
void PushUp(int rt)
{
T[rt].Min = min(T[rt<<].Min, T[rt<<|].Min);
}
void PushDown(int L, int R, int rt)
{
int mid = (L + R) >> ;
ll t = T[rt].lazy;
T[rt<<].Min += t;
T[rt<<|].Min += t;
T[rt<<].lazy += t;
T[rt<<|].lazy += t;
T[rt].lazy = ;
}
void Update(int l, int r, int v, int L, int R, int rt)
{
if(l==L && r==R)
{
T[rt].lazy += v;
T[rt].Min += v;
return ;
}
int mid = (L + R) >> ;
if(T[rt].lazy) PushDown(L, R, rt);
if(r <= mid) Update(l, r, v, Lson);
else if(l > mid) Update(l, r, v, Rson);
else
{
Update(l, mid, v, Lson);
Update(mid+, r, v, Rson);
}
PushUp(rt);
}
ll Query(int l, int r, int L, int R, int rt)
{
if(l==L && r== R)
{ return T[rt].Min;
}
int mid = (L + R) >> ;
if(T[rt].lazy) PushDown(L, R, rt);
if(r <= mid) return Query(l, r, Lson);
else if(l > mid) return Query(l, r, Rson);
return min(Query(l, mid, Lson), Query(mid + , r, Rson));
}
struct node
{
int x,y;
}a[maxn];
int main()
{
int i,j;
scanf("%d",&n);
rep(i,,n)
{
int b,p,d,e;
scanf("%d",&a[i].x);
scanf("%d.%d %d:%d",&b,&p,&d,&e);
a[i].y=(b+p*)**+d*+e;
c[i]=a[i].y;
}
sort(c+,c+n+);
rep(i,,n)a[i].y=lower_bound(c+,c+n+,a[i].y)-c;
rep(i,,n)
{
Update(a[i].y,n,a[i].x,,n,);
printf("%lld\n",min(0LL,Query(,n,,n,)));
}
//system("pause");
return ;
}
ural2014 Zhenya moves from parents的更多相关文章
- Gym 100507C Zhenya moves from parents (线段树)
Zhenya moves from parents 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/C Description Z ...
- ural 2014 Zhenya moves from parents
2014. Zhenya moves from parents Time limit: 1.0 secondMemory limit: 64 MB Zhenya moved from his pare ...
- zhenya moves from parents
Zhenya moved from his parents' home to study in other city. He didn't take any cash with him, he onl ...
- URAL 2014 Zhenya moves from parents --线段树
题意:儿子身无分文出去玩,只带了一张他爸的信用卡,当他自己现金不足的时候就会用信用卡支付,然后儿子还会挣钱,挣到的钱都是现金,也就是说他如果有现金就会先花现金,但是有了现金他不会还信用卡的钱.他每花一 ...
- 【线段树】Gym - 100507C - Zhenya moves from parents
线段树每个结点维护两个值,分别是这个区间的 负债 和 余钱. 按时间顺序从前往后看的时候,显然负债是单调不减的. 按时间顺序从后往前看的时候,显然余钱也是单调不减的,因为之前如果有余钱,可能会增加现在 ...
- Gym 100507D Zhenya moves from the dormitory (模拟)
Zhenya moves from the dormitory 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/D Descrip ...
- ural 2015 Zhenya moves from the dormitory(模拟)
2015. Zhenya moves from the dormitory Time limit: 1.0 secondMemory limit: 64 MB After moving from hi ...
- D - Zhenya moves from the dormitory URAL - 2015
After moving from his parents’ place Zhenya has been living in the University dormitory for a month. ...
- NEERC 2014, Eastern subregional contest
最近做的一场比赛,把自己负责过的题目记一下好了. Problem B URAL 2013 Neither shaken nor stirred 题意:一个有向图,每个结点一个非负值,可以转移到其他结点 ...
随机推荐
- 避免IE执行AJAX时,返回JSON出现下载文件
<bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.conv ...
- shell查看进程
用shell脚本监控进程是否存在 不存在则启动的实例,先上代码干货: #!/bin/shps -fe|grep processString |grep -v grepif [ $? -ne 0 ]th ...
- wpf 类似TextBlock外观的Button的样式
<Style x:Key="noborderbtnStyle" TargetType="{x:Type Button}"> <Setter P ...
- windows MySQL 安装
MySQL安装文件分为两种,一种是msi格式的,一种是zip格式的.如果是msi格式的可以直接点击安装,按照它给出的安装提示进行安装(相信大家的英文可以看懂英文提示),一般MySQL将会安装在C:\P ...
- hdu5269 ZYB loves Xor I
分治法和字典树都可以,都是递归,但字典树耗内存 从第一bit开始,若相同则xor为0,分到同一部分,不相同则统计,且此时lowbit为这一bit,最后结果要乘以2 /*分治法*/ #include&l ...
- js 关键字 in
对于数组 ,迭代出来的是数组元 素,对于对象 ,迭代出来的是对象的属性: var x var mycars = new Array() mycars[0] = "Saab" myc ...
- sessionStorage用于分页,瀑布流和存储用户数据等
在手机网页开发中,会用到分页和瀑布流来分量显示数据.这里会遇到一个问题.当点击某条数据进入详情后,再按手机的返回键会到上一个页面,该页面是重新加载的. 本人在微信里用内置的qq浏览器打开页面,wind ...
- HBase Coprocessor 剖析与编程实践(转载http://www.cnblogs.com/ventlam/archive/2012/10/30/2747024.html)
HBase Coprocessor 剖析与编程实践 1.起因(Why HBase Coprocessor) HBase作为列族数据库最经常被人诟病的特性包括:无法轻易建立“二级索引”,难以执行求和. ...
- crontab使用和格式
什么是crontab crontab命令常见于Unix和类Unix的操作系统之中,用于设置周期性被执行的指令.具体的用法见下图: 关于crontab的格式: crontab的格式是分为6列:f1 f2 ...
- hashmap源码
Java里各种基础容器的实现都是链表外加引用的形式.So,hashmap也不例外. 那小考虑下:hashmap是怎么产生的呢? 常用的两种数据结构数组和链表各有优劣,数组寻址容易,插入和删除困难:而链 ...