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;
}