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. FreeMarker 整合 springmvc

    一.添加 jar 包 <dependency> <groupId>org.freemarker</groupId> <artifactId>freema ...

  2. FreeMarker 语法 include 引用模板

    一.java 代码 @Test public void testFreeMarker() throws Exception { //1.创建一个模板文件 //2.创建一个Configuration对象 ...

  3. 第二篇:SpringBoot配置详解

    SpringBoot 是为了简化 Spring 应用的创建.运行.调试.部署等一系列问题而诞生的产物,自动装配的特性让我们可以更好的关注业务本身而不是外部的XML配置,我们只需遵循规范,引入相关的依赖 ...

  4. 第一篇、Android Supersu 权限管理定制,隐藏过滤权限,指定APP最高权限

    近期有个需求,在预装ROM的时候,须要权限,可是又不同意全部的应用都有权限,仅仅同意自己的应用有最高的权限(当然没有系统签名情况下). 所以.编译了CM 提取了supersu进行了二次定制,让他进行权 ...

  5. 学艺不精而惭愧--论C++模板类的使用

    自己断断续续地使用C++也有一段时间了.有些时候产生了自满的情绪.觉得自己对C++的语言特性已经知道的几乎相同了,在语法方面没有什么难倒我的地方了,如今所要做的是依据实际问题编敲代码,问题的难点在于算 ...

  6. java中字符串编码转换

    Java 正确的做字符串编码转换 字符串的内部表示? 字符串在java中统一用unicode表示( 即utf-16 LE) , 对于 String s = "你好哦!"; 如果源码 ...

  7. netty可靠性

    Netty的可靠性 首先,我们要从Netty的主要用途来分析它的可靠性,Netty目前的主流用法有三种: 1) 构建RPC调用的基础通信组件,提供跨节点的远程服务调用能力: 2) NIO通信框架,用于 ...

  8. Java中的作用域有哪些

    在Java语言中,变量的类型主要有3种:成员变量.静态变量和局部变量 首先说静态变量跟局部变量 静态变量不依赖于特定的实例,而是被所有实例共享,也就是说,只要一个类被加载,JVM就会给类的静态变量分配 ...

  9. js前台编码,asp.net后台解码 防止前台传值到后台为乱码

    js编码:     encodeURI() 后台解码:HttpUtility.UrlDecode()

  10. Java基础——GridBagLayout布局

    1.GridBagLayout布局管理器非常灵活,每个 GridBagLayout 对象维持一个动态的矩形单元网格: 2.需要和它的约束类(GridBagConstraints类)一起使用: 3.Gr ...