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 题意:一个有向图,每个结点一个非负值,可以转移到其他结点 ...
随机推荐
- Servlet(11)—客户端跳转和服务端跳转
客户端跳转: 1.链接跳转:< a href="">< /a > 2.表单提交< form>< /form> 3.Response. ...
- idea+maven+springboot+mybatis
确认maven环境,安装maven在这里就不赘述了. 在idea新建maven项目 下图中填上你Maven安装的目录 打开pom文件,导入jar包(手动敲入/拷贝) 下面是配置之后的pom文件内容 & ...
- 表型数据(Phenotype Data)基本概念
表型(英语:Phenotype),又称表现型,对于一个生物而言,表示它某一特定的物理外观或成分.一个人是否有耳珠.植物的高度.人的血型.蛾的颜色等等,都是表型的例子. 表型主要受生物的基因型和环境影响 ...
- DBS:CUPhone
ylbtech-DBS:CUPhone 1.返回顶部 1. USE master GO -- Drop the database if it already exists IF EXISTS ( SE ...
- python读取excel(xlrd)
一.安装xlrd模块: 1.mac下打开终端输入命令: pip install xlrd 2.验证安装是否成功: 在mac终端输入 python 进入python环境 然后输入 import xl ...
- DockerSwarm获取Token与常用命令
一.Token相关 Join tokens是允许一个节点加入集群的密钥.有两种可用的不同的join tokens,一个是用作worker角色,另一个是用作manager角色.在执行swarm join ...
- 招中高级web开发工程师
>>招中高级web开发工程师
- [.NET] 一个获取随机数的新方式
private Random GetRandomSeed() { byte[] bytes = new byte[4]; RNGCryptoServiceProvider rng = new RNGC ...
- webstorm11.0下载地址和webstorm11.0破解程序patcher.exe下载使用方法说明 前端IDE工具的利器
20160107以下亲测可行. webstorm11.0下载地址:http://www.fxxz.com/soft/109234.html webstorm11.0下载安装破解使用说明: 下载完Web ...
- 深入理解linux系统下proc文件系统内容
深入理解linux系统下proc文件系统内容 内容摘要:Linux系统上的/proc目录是一种文件系统,即proc文件系统. Linux系统上的/proc目录是一种文件系统,即proc文件系统.与其它 ...