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的更多相关文章

  1. Gym 100507C Zhenya moves from parents (线段树)

    Zhenya moves from parents 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/C Description Z ...

  2. ural2014 Zhenya moves from parents

    Zhenya moves from parents Time limit: 1.0 secondMemory limit: 64 MB Zhenya moved from his parents’ h ...

  3. ural 2014 Zhenya moves from parents

    2014. Zhenya moves from parents Time limit: 1.0 secondMemory limit: 64 MB Zhenya moved from his pare ...

  4. URAL 2014 Zhenya moves from parents --线段树

    题意:儿子身无分文出去玩,只带了一张他爸的信用卡,当他自己现金不足的时候就会用信用卡支付,然后儿子还会挣钱,挣到的钱都是现金,也就是说他如果有现金就会先花现金,但是有了现金他不会还信用卡的钱.他每花一 ...

  5. 【线段树】Gym - 100507C - Zhenya moves from parents

    线段树每个结点维护两个值,分别是这个区间的 负债 和 余钱. 按时间顺序从前往后看的时候,显然负债是单调不减的. 按时间顺序从后往前看的时候,显然余钱也是单调不减的,因为之前如果有余钱,可能会增加现在 ...

  6. Gym 100507D Zhenya moves from the dormitory (模拟)

    Zhenya moves from the dormitory 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/D Descrip ...

  7. 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 ...

  8. 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. ...

  9. NEERC 2014, Eastern subregional contest

    最近做的一场比赛,把自己负责过的题目记一下好了. Problem B URAL 2013 Neither shaken nor stirred 题意:一个有向图,每个结点一个非负值,可以转移到其他结点 ...

随机推荐

  1. .NET轻量级ORM框架Dapper入门精通

    一.课程介绍 本次分享课程包含两个部分<.NET轻量级ORM框架Dapper修炼手册>和<.NET轻量级ORM框架Dapper葵花宝典>,阿笨将带领大家一起领略轻量级ORM框架 ...

  2. HIVE开发总结

    基本数据类型 查看所有函数 搜索函数 搜索表 查看函数使用方法 关键字补全 显示表头 SET环境变量 查看建表语句.数据文件置 执行外部命令 NVL CONCAT IF CASE TRIM SUBST ...

  3. 安装Harbor

    一.安装Harbor 1. Harbor简介 Harbor是一个用于存储和分发Docker镜像的企业级Registry服务器,通过添加一些企业必需的功能特性,例如安全.标识和管理等,扩展了开源Dock ...

  4. List集合序列排序的两种方法

    首先讲一下Comparable接口和Comparator接口,以及他们之间的差异.有助于Collections.sort()方法的使用.请参考 1.Comparable自然规则排序//在自定义类Stu ...

  5. Eclipse和MyEclipse使用技巧--解决MyEclipse中的js报错的小方法

    今天,下了个模版,但是导进去的时候发现js会报错.看了下其他都没有错误.而有一个js报错误,请原谅我有点红色强迫症,不能留一点红色 . 错误如下:Syntax error on token " ...

  6. 通过__block的作用深入研究block

    block普通引用 默认情况下,在block中访问外部变量是通过复制一个变量来操作的,既可以读,但是写操作不对原变量生效,下面通过代码来举证 NSString *a = @"testa&qu ...

  7. Linux下清理内存和Cache方法见下文:

    暂时目前的环境处理方法比较简单: 在root用户下添加计划任务: */10 * * * * sync;echo 3 > /proc/sys/vm/drop_caches; 每十分钟执行一次,先将 ...

  8. 关于VC预定义常量_WIN32,WIN32,_WIN64

    VC2012 下写 Windows 程序时,有时需要判断编译环境.在之前的文章<判断程序是否运行在 Windows x64 系统下.>里说过如何在运行期间判断系统环境,但在编译时如何判断? ...

  9. SQL行转列(PIVOT)与列转行(UNPIVOT)简明方法

    原文地址:https://www.cnblogs.com/linJie1930906722/p/6036714.html 在做数据统计的时候,行转列,列转行是经常碰到的问题.case when方式太麻 ...

  10. [转]正则表达式的先行断言(lookahead)和后行断言(lookbehind)

    正则表达式的先行断言和后行断言一共有4种形式: (?=pattern) 零宽正向先行断言(zero-width positive lookahead assertion) (?!pattern) 零宽 ...