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 题意:一个有向图,每个结点一个非负值,可以转移到其他结点 ...
随机推荐
- 解决Xcode 9.2系统真机测试时出现 could not find developer disk image问题
解决Xcode在ipad/iphone 9.2 系统真机测试时出现could not find developer disk image问题 第一种方法:拷贝这个文件(http://download. ...
- Eclipse报错 due to restriction on required library C:/Java/jdk1.7.51/jre/lib/rt.jar 解决方案
Eclipse报错 due to restriction on required library C:/Java/jdk1.6.0_10/jre/lib/rt.jar 解决方案 Eclipse 编译时 ...
- QProcess 进程类—调用外部程序
http://blog.csdn.net/newbee520/article/details/8279101 启动一个新的进程的操作非常简单,只需要将待启动的程序名称和启动参数传递给start() ...
- masonry使用问题
2015年11月3日 coreData的学习练习中复习使用masonry自动布局 masonry自动布局发现问题: 两个控件的相对布局: 如果被参考对象用这个带anchor的属性,就会报这样一个错误: ...
- Git中的merge命令实现中出现问题及其解决
Git中的merge命令实现和工作方式 2015年8月17日星期一 丹丹 git代码在合并两个分支的时候总是会出现一下的错误提示,不能正常的完成合并分支,错误提示如图所示: 但是在其他的终端是可以完成 ...
- ado vb6
http://www.cnblogs.com/ywb-lv/articles/2343444.html http://stackoverflow.com/questions/3334102/use-t ...
- 使用Spring 3的@value简化配置文件的读取 (转)
Spring 3支持@value注解的方式获取properties文件中的配置值,大简化了读取配置文件的代码. 1.在applicationContext.xml文件中配置properties文件 & ...
- NSIndexPath 延伸
转载自:http://my.oschina.net/u/2560887/blog/602095?fromerr=Dy4vj5Jd 这个类的实例描述了一个嵌套数组中特定节点的路径,一般叫做索引路径.1. ...
- Loadrunner VuGen实战---基本组成、录制流程、协议、脚本优化、参数化(三)
一.3大基本组件:VuGen.Controller.Analysis 1.VuGen:录制.编写脚本. 2.Controller:性能测试场景设计以及监控的地方. 3.Analysis:生成图表报告的 ...
- MVC工作流程
1 浏览者 => 调用控制器,对它发出指令 2 控制器 => 按照指令选取一个合适的模型 3 模型 => 按控制器指令取出相应的数据 4 控制器 => 按指令选取 ...