2014. Zhenya moves from parentstime limit: 1.0 second
Memory limit: 64 mbzhenya 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 has Ds only it, and when it is over he uses the credit card. every time he gets or vertex DS money, he sends a letter to his father, where he puts the following two things.
- The date when it took place
- The sum of earned or spent money
Every time processing ing 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. inputthe first line contains an integer
NWhich is the number of Zhenya's letters (1 ≤
N≤ 100 000). These letters are listed in the next
NLines. 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 specified ed them. outputafter each encrypted ed letter output What Zhenya's father thinks the amount of the debt on the credit card is. sample
| Input |
Output |
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 |
-1000-5000-500-500 |
This is indeed an interesting question.
If your child has insufficient cash, the child will use a credit card.
Then, every time the child makes money or spends money, he will send a message to his father.
Returns X with the time t.
It indicates that the child earned x yuan (X is positive) at t time, or spent X yuan.
However, the mail sending time is not the same as the arrival time.
Each time a father receives a letter, he wants to estimate the current liabilities of his credit card.
#include <bits/stdc++.h>using namespace std;typedef long long LL;const int N = 100010;#define lson l,mid,rt<<1#define rson mid+1,r,rt<<1|1#define lr rt<<1#define rr rt<<1|1#define root 1,n+100,1int n;LL date[N<<2] , lazy[N<<2] ;vector<int>tt;int t[N];LL v[N];void build( int l , int r , int rt ){ date[rt] = lazy[rt] = 0 ; if( l == r ) return ; int mid = (l+r) >> 1; build( lson ) ; build( rson ) ;}void Up(int rt){ date[rt] = min( date[lr] , date[rr]); }void Down( int rt ){ if( lazy[rt] ){ lazy[lr] += lazy[rt], lazy[rr]+=lazy[rt]; date[lr] += lazy[rt], date[rr] += lazy[rt]; lazy[rt] = 0 ; }}void update( int l , int r , int rt , int L , int R , LL val ){ if( L <= l && r <= R ){ lazy[rt] += val , date[rt] += val; return ; } Down(rt); int mid = (l + r) >> 1; if( L <= mid ) update(lson,L,R,val); if( R > mid ) update(rson,L,R,val); Up(rt);}int main(){ #ifdef LOCAL freopen("in","r",stdin); #endif int mon , day , hour , min ; while( scanf("%d",&n ) != EOF ){ tt.clear(); build(root); for( int i = 0 ; i < n ; ++i ){ scanf("%lld%d.%d%d:%d",&v[i],&day,&mon,&hour,&min); t[i] = ( ( mon * 31 + day ) * 24 + hour ) * 60 + min ; tt.push_back(t[i]); } sort( tt.begin() , tt.end() ); for( int i = 0 ; i < n ; ++i ) { int pos = lower_bound( tt.begin() , tt.end(), t[i] ) - tt.begin() + 1 ; update( root , pos , n , v[i] ) ; printf("%I64d\n",( date[1] >= 0 ? 0 : date[1]) ) ; } } return 0;}
Ural 2014 Zhenya moves from parents