zhenya moves from parents
Zhenya moved from his parents’ home to study in other city. He didn’t take any cash with him, he only took his father’s credit card with zero balance on it. Zhenya succeeds in studies at the University and sometimes makes a little
money on the side as a Maths tutor. As he makes his own money he spends only it, and when it is over he uses the credit card. Every time he gets or spends money, he sends a letter to his father, where he puts the following two things.
The date when it took placeThe sum of earned or spent money
Every time receiving a letter from Zhenya, his father calculates the debt on the credit card at the moment. But here a problem arises. The point is that Russian Post delivers letters in an order different to the one they were
sent in.
For example, in the first Zhenya’s letter the father read that on September 10 Zhenya spent one thousand rubles. He thought that his son had used the credit card, and now the debt is one thousand rubles. However the next day
came a letter with the information that on September 9 Zhenya earned five hundred rubles. It means that half of the money he spent on September 10 was his own, and the debt on the credit card is just five hundred rubles.
Help Zhenya’s father with his account management.
Input
The first line contains an integer n which is the number of Zhenya’s letters (1 ≤ n ≤ 100 000). These letters are listed in the next n lines. Description of each letter consists of the amount of money
Zhenya spent or earned (in the form -c or +c accordingly, where c is an integer, 1 ≤ c ≤ 50 000) followed by both date and time when it took place (in the form of dd.MM hh:mm). All dates belong to the same year, which is not leap (i. e. there are
365 days in it). Any two letters contain either different dates or different time. The letters are listed in the order the father received them.
Output
After each received letter output what Zhenya’s father thinks the amount of the debt on the credit card is.
Sample Input
input
5
-1000 10.09 21:00
+500 09.09 14:00
+1000 02.09 00:00
-1000 17.09 21:00
+500 18.09 13:00
output
-1000
-500
0
-500
-500
题目大意就是,儿子拿父亲的信用卡去花,父亲会受到儿子的来信 ,说他花了多少钱,赚了多少钱,但是儿子不会还信用卡的,而且要是儿子手里有钱就先用手里的钱,不够了在用信用卡;
做的时候不知道,比赛完才知道是线段树+离散化,就是按时间排开,输出最低的钱数就是信用卡的欠债,要是大于0就输出0
对线段树离散化进一步掌握了,不亏
#include<bits/stdc++.h>
#define sf scanf
#define scf(x) scanf("%d",&x)
#define pf printf
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define mm(x,b) memset((x),(b),sizeof(x))
#define ls l,mid,i<<1
#define rs mid+1,r,i<<1|1
#define ll long long
using namespace std;
const int N=1e5+100;
struct tree
{
int l,r;
ll lazy,ans;
}tr[N<<4];
void built_tree(int l,int r,int i)
{
tr[i].l =l;tr[i].r =r;
tr[i].lazy =0;
if(l==r)
{
tr[i].ans=0;
return ;
}
int mid=(l+r)>>1;
built_tree(ls);
built_tree(rs);
tr[i].ans =min(tr[i<<1].ans ,tr[i<<1|1].ans);
}
void pushdown(int i)
{
if(tr[i].lazy)
{
tr[i<<1].lazy +=tr[i].lazy;
tr[i<<1|1].lazy +=tr[i].lazy;
tr[i<<1].ans +=tr[i].lazy;
tr[i<<1|1].ans +=tr[i].lazy;
tr[i].lazy =0;
}
}
void update(int l,int r,ll k,int i)
{
if(l<=tr[i].l&&tr[i].r<=r)
{
tr[i].ans +=k;
tr[i].lazy+=k;
return;
}
pushdown(i);
int mid=(tr[i].l+tr[i].r)>>1;
if(r<=mid)
update(l,r,k,i<<1);
else if(l>mid)
update(l,r,k,i<<1|1);
else
{
update(l,r,k,i<<1);
update(l,r,k,i<<1|1);
}
tr[i].ans=min(tr[i<<1].ans,tr[i<<1|1].ans);
}
ll query(int l,int r,int i)
{
if(tr[i].l ==l&&tr[i].r==r)
return tr[i].ans;
pushdown(i);
int mid=(tr[i].l+tr[i].r)>>1;
if(r<=mid)
return query(l,r,i<<1);
else if(l>mid)
return query(l,r,i<<1|1);
else return min(query(l,r,i<<1),query(l,r,i<<1|1));
}
int mon[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
struct Time
{
ll t,id,bits,k;
}T[N];
bool cmp1(Time a,Time b)
{
return a.t <b.t ;
}
bool cmp2(Time a,Time b)
{
return a.id <b.id ;
}
int main()
{
rep(i,1,13)
mon[i]+=mon[i-1];
int n;
ll k,d,m,s,f;
scf(n);
rep(i,0,n)
{
sf("%lld %lld.%lld %lld:%lld",&k,&d,&m,&s,&f);
ll bit=(mon[m-1]+d)*24*60+s*60+f;
T[i].t=bit;
T[i].id =i;
T[i].k =k;
}
built_tree(0,n,1);
sort(T,T+n,cmp1);
rep(i,0,n)
T[i].bits =i;
sort(T,T+n,cmp2);
rep(i,0,n)
{
update(T[i].bits ,n,T[i].k ,1);
ll ans=tr[1].ans;
if(ans>=0)
pf("0\n");
else pf("%lld\n",ans);
}
return 0;
}
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 ...
- ural2014 Zhenya moves from parents
Zhenya moves from parents Time limit: 1.0 secondMemory limit: 64 MB Zhenya moved from his parents’ h ...
- ural 2014 Zhenya moves from parents
2014. Zhenya moves from parents Time limit: 1.0 secondMemory limit: 64 MB Zhenya moved from his pare ...
- 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 题意:一个有向图,每个结点一个非负值,可以转移到其他结点 ...
随机推荐
- Python常用的软件包
下面是Python开发常用的软件包. 名称 用途 安装命令 opengl sudo pip3 install PyOpenGL pyqtgraph GUI图形库 sudo pip3 instal ...
- 柳青(Jean)英文演讲集合
1.Didi Chuxing's Jean Liu on The Future of Cities https://www.youtube.com/watch?v=G9uPGoN0dvQ 2.Did ...
- 【问题与解决】怎么删除TFS云端上的项目
最近使用了Visual Stuidio提供的网络项目管理,感觉跟visual stuido结合起来还是很好用的,新建项目很简单,但是在删除项目的时候就没有那么简单了,直接通过VS的团队管理删除还会报错 ...
- iOS 渐变提示。错误弹出提示 几秒自动消失
//事例 CGRect alertFarm = CGRectMake(,,,); [self noticeAlert:_bgView withNoticeStr:@"登录成功" w ...
- IDEA 设置 TOMCAT 虚拟路径
今天在使用 IDEA 配置 TOMCAT 虚拟路径时一直报错,最终解决方式整理如下: 一.使用 Tomcat 自己的虚拟路径 1.在 Tomcat9\conf 目录下找到 server.xml 文件, ...
- String类源码解析
1. String是使用char[]数组来存储的,并且String值在创建之后就不可以改变了.char[]数组的定义为: /** The value is used for character sto ...
- php urlencode vs java URLEncoder.encode
结论:urlencode 先比URLEncoder.encode多编码 “ * ” 符号,其他都保持一致 php urlencode phpversion()>=5.3 will compli ...
- windows10开启wst子系统
需求描述: 在玩docker发现需要linux运行玩转,直接在vmware虚拟机上跑 ,性能有损耗.想直接在windows下运行docker 问题解决: windows10的wst子系统可以安装lin ...
- Windows平台下nginx跨域配置
1)下载地址: http://nginx.org 2)启动 解压至d:\nginx,运行nginx.exe(即nginx -c conf\nginx.conf),默认使用80端口,日志见文件夹D:\n ...
- TableView 无数据时展示占位视图
UITableView+NoDataView.m #import "UITableView+NoDataView.h" #import "NoDataView.h&quo ...