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

分析:当前的盈亏始终对之后的盈亏有影响,且要维护整体最小值,所以用线段树解决;

   注意要用long long;

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=1e5+;
const int dis[][]={{,},{-,},{,-},{,}};
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p%mod;p=p*p%mod;q>>=;}return f;}
int n,m,k,t,c[maxn];
struct Node
{
ll Min, lazy;
} T[maxn<<];
void PushUp(int rt)
{
T[rt].Min = min(T[rt<<].Min, T[rt<<|].Min);
}
void PushDown(int L, int R, int rt)
{
int mid = (L + R) >> ;
ll t = T[rt].lazy;
T[rt<<].Min += t;
T[rt<<|].Min += t;
T[rt<<].lazy += t;
T[rt<<|].lazy += t;
T[rt].lazy = ;
}
void Update(int l, int r, int v, int L, int R, int rt)
{
if(l==L && r==R)
{
T[rt].lazy += v;
T[rt].Min += v;
return ;
}
int mid = (L + R) >> ;
if(T[rt].lazy) PushDown(L, R, rt);
if(r <= mid) Update(l, r, v, Lson);
else if(l > mid) Update(l, r, v, Rson);
else
{
Update(l, mid, v, Lson);
Update(mid+, r, v, Rson);
}
PushUp(rt);
}
ll Query(int l, int r, int L, int R, int rt)
{
if(l==L && r== R)
{ return T[rt].Min;
}
int mid = (L + R) >> ;
if(T[rt].lazy) PushDown(L, R, rt);
if(r <= mid) return Query(l, r, Lson);
else if(l > mid) return Query(l, r, Rson);
return min(Query(l, mid, Lson), Query(mid + , r, Rson));
}
struct node
{
int x,y;
}a[maxn];
int main()
{
int i,j;
scanf("%d",&n);
rep(i,,n)
{
int b,p,d,e;
scanf("%d",&a[i].x);
scanf("%d.%d %d:%d",&b,&p,&d,&e);
a[i].y=(b+p*)**+d*+e;
c[i]=a[i].y;
}
sort(c+,c+n+);
rep(i,,n)a[i].y=lower_bound(c+,c+n+,a[i].y)-c;
rep(i,,n)
{
Update(a[i].y,n,a[i].x,,n,);
printf("%lld\n",min(0LL,Query(,n,,n,)));
}
//system("pause");
return ;
}

ural2014 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. ural 2014 Zhenya moves from parents

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

  3. zhenya moves from parents

    Zhenya moved from his parents' home to study in other city. He didn't take any cash with him, he onl ...

  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. iPhone5s 等 64位真机 运行 带有百度地图等 仅支持32位系统API和SDK的问题

    将下图中画红色框的部分去掉,程序就不再支持64位了.iPhone5s 将使用它的32位兼容模式.(而不再是64位模式)百度地图也不会报错了.

  2. 运维命令rsync

    如果你是一位运维工程师,你很可能会面对几十台.几百台甚至上千台服务器,除了批量操作外,环境同步.数据同步也是必不可少的技能. 说到“同步”,不得不提的利器就是rsync,今天就来说说我从这个工具中看到 ...

  3. ECShop - 数据库操作类

    ECShop v2.7.2没有使用一些开源的数据库操作类,比如adodb或者PEAR,而是封装了自己的实现.这样做的好处是实现非常轻量,只有一个文件,27Kb,大大减小了分发包的文件大小.另外,当网站 ...

  4. Django CRM学员系统项目

    项目需求: 1.分讲师\学员\课程顾问角色,2.学员可以属于多个班级,学员成绩按课程分别统计3.每个班级至少包含一个或多个讲师4.一个学员要有状态转化的过程 ,比如未报名前,报名后,毕业老学员5.客户 ...

  5. cordova sqlite

    jar包在这里下载 https://github.com/litehelpers/Cordova-sqlite-storage 把SQLitePlugin 复制到自己工程目录 org.pgsqlite ...

  6. openCV(一)---将openCV框架导入iOS工程中

    开发环境: Xcode 6.4   openCV for iOS 3.0    配置openCV开发环境 在OpenCV官网中下载OpenCV开发包(官网地址:http://opencv.org/) ...

  7. oracle提高之索引学习

    一. 索引介绍 1.1  索引的创建 语法 : CREATE UNIUQE | BITMAP INDEX <schema>.<index_name> ON <schema ...

  8. 404、500、502等HTTP状态码介绍

    基本涵盖了所有问题HTTP 400 – 请求无效HTTP 401.1 – 未授权:登录失败HTTP 401.2 – 未授权:服务器配置问题导致登录失败HTTP 401.3 – ACL 禁止访问资源HT ...

  9. fpSpread1 简单用法

    //如果汇总的话直接可在模板里面填写公式,不过要有三行空行才行 比如SUM(A1,A2,A3) fpSpread1.Sheets[0].RowCount = 30; fpSpread1.Sheets[ ...

  10. Java中域 实例域 静态域

    1.java中的域 所谓的域,翻译成英文就是field, 也就是我们常说的字段,或者说是属性. 比如类的字段(属性),局部的,全局的.所谓域,其实是“field”的翻译 然后实例域,就是 实例(&qu ...