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. 纯 CSS 实现高度与宽度成比例的效果

    http://zihua.li/2013/12/keep-height-relevant-to-width-using-css/

  2. IE环境表单提交不跳转页面

    <head> <base target="_self"></base> </head>

  3. Golang LicenseServer授权服务器的设计 与 RSA 密钥对的应用

    //TODO 待写文章 目录: 1.为什么要写授权服务器  LicenseServer 2.授权服务器的设计思路 3.授权服务器所使用到的加密技术 1.为什么要写授权服务器 为了防止别人拿到二进制后, ...

  4. C# Task 是什么?返回值如何实现? Wait如何实现

    关于Task的API太多了,网上的实例也很多,现在我们来说说Task究竟是个什么东西[task一般用于多线程,它一定与线程有关],还有它的返回值有事怎么搞的. 首先我们以一个最简单的API开始,Tas ...

  5. Javascript正则表达入参是null

    今天群友问了一个问题,如下的执行结果是什么? var reg = /^[a-z0-9\u4e00-\u9fa5]{0,15}$/; console.log(reg.test(null)); // tr ...

  6. 解决Maven项目总是回跳到jdk1.5的情况的方法

    一.在pom.xml中加入: <build> <plugins> <plugin> <groupId>org.apache.maven.plugins& ...

  7. VirtualBox虚拟机磁盘瘦身

    操作系统 : windows7_x64 VirtualBox 版本 : 4.3.28 原理: 使用0填充虚拟系统磁盘,然后删除填充文件,再使用VBoxManage进行压缩. Linux系统磁盘瘦身 一 ...

  8. JavaScript 同步异步示意图

  9. 【20170506】贝业新兄弟IT总监李济宏:第三方家居物流的IT架构探索

    5月6日,物流人的节日,这一天,全国的物流人汇聚中国上海嘉定,以“新时代.新物流”为主题的2017中国货运产业大会暨货运企业家高峰论坛如期召开,同时,首届嘉年华活动隆重开启,八大主题分享活动,精彩进行 ...

  10. 【Vegas原创】Excel中,日期和时间用&连接后格式不正确的解决方法

    =TEXT(B2+C2,"yyyy-mm-dd hh:mm:ss")