Segment Game

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 446    Accepted Submission(s): 95

Problem Description
Lillian is a clever girl so that she has lots of fans and often receives gifts from her fans.

One day Lillian gets some segments from her fans Lawson with lengths of 1,2,3... and she intends to display them by adding them to a number line.At the i-th add operation,she will put the segment with length of i on the number line.Every time she put the segment on the line,she will count how many entire segments on that segment.During the operation ,she may delete some segments on the line.(Segments are mutually independent)

 
Input
There are multiple test cases.

The first line of each case contains a integer n — the number of operations(1<=n<=2∗105,∑n<=7∗105)

Next n lines contain the descriptions of the operatons,one operation per line.Each operation contains two integers a , b.

if a is 0,it means add operation that Lilian put a segment on the position b(|b|<109) of the line.
(For the i-th add operation,she will put the segment on [b,b+i] of the line, with length of i.)

if a is 1,it means delete operation that Lilian will delete the segment which was added at the b-th add operation.

 
Output
For i-th case,the first line output the test case number.

Then for each add operation,ouput how many entire segments on the segment which Lillian newly adds.

 
Sample Input
3
0 0
0 3
0 1
5
0 1
0 0
1 1
0 1
0 0
 
Sample Output
Case #1:
0
0
0
Case #2:
0
1
0
2

 
Hint

For the second case in the sample:

At the first add operation,Lillian adds a segment [1,2] on the line.

At the second add operation,Lillian adds a segment [0,2] on the line.

At the delete operation,Lillian deletes a segment which added at the first add operation.

At the third add operation,Lillian adds a segment [1,4] on the line.

At the fourth add operation,Lillian adds a segment [0,4] on the line

 
Source
 
解题:树状数组,神奇。。。哎。。这么简单怎么当场没想到
 
 #include <bits/stdc++.h>
using namespace std;
const int maxn = ;
int op[maxn],L[maxn],R[maxn],n;
int C[][maxn],Li[maxn];
inline int lowbit(int x) {
return x&(-x);
}
void update(int i,int val,int o) {
for(; i < maxn; i += lowbit(i))
C[o][i] += val;
}
int calc(int i,int o) {
int sum = ;
for(; i; i -= lowbit(i))
sum += C[o][i];
return sum;
}
int main() {
int add,tot,cnt,cs = ;
while(~scanf("%d",&n)) {
memset(C,,sizeof C);
for(int i = add = tot = cnt = ; i < n; ++i) {
scanf("%d%d",op+i,L+i);
if(op[i] == ) {
R[i] = L[i] + (++add);
Li[tot++] = L[i];
Li[tot++] = R[i];
}
}
sort(Li,Li + tot);
tot = unique(Li,Li + tot) - Li;
printf("Case #%d:\n",cs++);
for(int i = ; i < n; ++i) {
if(!op[i]) {
int LL = lower_bound(Li,Li + tot,L[i]) - Li + ;
int RR = lower_bound(Li,Li + tot,R[i]) - Li + ;
printf("%d\n",calc(RR,) - calc(LL-,));
L[cnt] = LL;
R[cnt++] = RR;
update(LL,,);
update(RR,,);
} else {
update(L[L[i]-],-,);
update(R[L[i]-],-,);
}
}
}
return ;
}

2015 Multi-University Training Contest 7 hdu 5372 Segment Game的更多相关文章

  1. HDU 5372 Segment Game

    /** 多校联合2015-muti7-1004 <a target=_blank href="http://acm.hdu.edu.cn/showproblem.php?pid=537 ...

  2. 2015 Multi-University Training Contest 8 hdu 5390 tree

    tree Time Limit: 8000ms Memory Limit: 262144KB This problem will be judged on HDU. Original ID: 5390 ...

  3. 2015 Multi-University Training Contest 8 hdu 5383 Yu-Gi-Oh!

    Yu-Gi-Oh! Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID:  ...

  4. 2015 Multi-University Training Contest 8 hdu 5385 The path

    The path Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: 5 ...

  5. 2015 Multi-University Training Contest 3 hdu 5324 Boring Class

    Boring Class Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  6. 2015 Multi-University Training Contest 3 hdu 5317 RGCDQ

    RGCDQ Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  7. 2015 Multi-University Training Contest 10 hdu 5406 CRB and Apple

    CRB and Apple Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  8. 2015 Multi-University Training Contest 10 hdu 5412 CRB and Queries

    CRB and Queries Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

  9. 2015 Multi-University Training Contest 6 hdu 5362 Just A String

    Just A String Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

随机推荐

  1. C#中的string驻留池

    刚开始学习C#的时候,就听说CLR对于String类有一种特别的内存管理机制:有时候,明明声明了两个String类的对象,但是他们偏偏却指向同一个实例.如下: String s1 = "He ...

  2. 数据库连接池dataesoruce pool深入理解

    8.数据库连接池的connection都是长连接的,以方便多次调用,多人连续使用.dataSourcePool9.数据库连接池中的连接,是在你用完之后,返回给数据库连接池的,并不是close()掉,而 ...

  3. [Node.js] Proxy Requests for Local and Remote Service Parity

    High availability apps require that no distinction be made between local and remote services. Attach ...

  4. java 正则表达式语法

    java 正则表达式语法 标签: 正则表达式javawindowsvbscriptscripting电话 2012-05-20 10:11 6705人阅读 评论(1) 收藏 举报  分类: javaS ...

  5. 浅析Context Class Loader

    浅析Context Class Loader 2010-05-11 16:58:49 分类: Java 转载自 薛笛的专栏http://blog.csdn.net/kabini/archive/200 ...

  6. Android开发之大位图压缩水印处理

    我们在发微博或者csdn博文的时候都能够给图片加上一个水印.一个独立的标识,那是怎么实现的呢?先封装一个BitmapTools封装类.该类要解决的问题是一将突破存储至sdcard中,二给图片加上水印. ...

  7. tomat遇到的一些错误

    资料链接:启动tomcat一闪而过的问题

  8. c2

    #include <stdio.h> int main() { // 整型常量 ; // 实型常量(小数) // 单精度float / 双精度double // 注意: 默认情况下编写的小 ...

  9. php实现邮箱激活功能

    php实现邮箱激活功能 一.样例 二.文件结构 其中swiftmailer-master是第三方插件,用来发验证邮件 三.核心代码 doAction.php 响应页面 <?php header( ...

  10. extjs 与html相结合 自定义

    http://skirtlesden.com/articles/html-and-extjs-components