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. Ubuntu14.04 安装CUDA7.5 + Caffe + cuDNN

    本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50961542 花了一天时间,在电脑上安 ...

  2. File System Design Case Studies

    SRC=http://www.cs.rutgers.edu/~pxk/416/notes/13-fs-studies.html Paul Krzyzanowski April 24, 2014 Int ...

  3. BA-传感器

    01.室内温度传感器 壁装,西门子,QAA2061D 1.默认范围:温度0-50℃,湿度0-100% 2.供电方式:24vac 3.穿线方式:4芯屏蔽线 02.风管温度传感器 西门子,QAM2120. ...

  4. POJ 3177--Redundant Paths【无向图添加最少的边成为边双连通图 &amp;&amp; tarjan求ebc &amp;&amp; 缩点构造缩点树】

    Redundant Paths Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10798   Accepted: 4626 ...

  5. substring类型题目的解题模板

    https://discuss.leetcode.com/topic/30941/here-is-a-10-line-template-that-can-solve-most-substring-pr ...

  6. HDU 2817 EASY题

    #include <iostream> #include <cstdio> using namespace std; const __int64 MOD=200907; __i ...

  7. 一个关于Class的小点

    public 是公有 private 是私有 没有写就是private

  8. 怎样在Java中运行Hive命令或HiveQL

    这里所说的在Java中运行Hive命令或HiveQL并非指Hive Client通过JDBC的方式连接HiveServer(or HiveServer2)运行查询,而是简单的在部署了HiveServe ...

  9. 单机 &amp; 弱联网手游 防破解、金币改动 简单措施

    手游经常使用破解方法 对于一个弱联网或者单机游戏,能够从下面方面去破解: 1.找得到存档文件的,直接破解改动存档文件. 2.找不到存档文件,就在游戏执行时借助一些软件来改动数值,比方用各种改动器手游助 ...

  10. 通过PowerShell卸载全部的SharePoint 2010 解决方式

    通过PowerShell卸载全部的SharePoint 2010 解决方式         为了演示.我常常须要拆毁再重建SharePoint 2010 环境.         我常常须要用到的操作就 ...