码迷,mamicode.com
首页 > 其他好文 > 详细

URAL 2014 Zhenya moves from parents

时间:2014-10-28 21:30:47      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   io   color   os   ar   使用   for   

2014. Zhenya moves from parents

Time limit: 1.0 second
Memory limit: 64 MB
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.
  1. The date when it took place
  2. The 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 nextn 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

inputoutput
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
-500
0
-500
-500

 

 

这个题目确实一条有趣的题目。

 

而当孩子现金不足的时候,孩子会使用信用卡 。

然后每次孩子挣到钱或者花了钱都会寄信告诉父亲。

给出一个值 x ,还有时间 t 。

表示孩子在 t 时间的时候挣了 x 元 ( x 为 正 ), 或者花了x元 。

但是信件发送的时间与到达的时间并非一致 。

而父亲每次收到信件想估计(用当前有的信息)信用卡现在的负债多少。

 

 

 

#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,1

int 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

标签:des   style   blog   io   color   os   ar   使用   for   

原文地址:http://www.cnblogs.com/hlmark/p/4057696.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!