2015 Multi-University Training Contest 7 hdu 5372 Segment Game
Segment Game
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 446 Accepted Submission(s): 95
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)
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.
Then for each add operation,ouput how many entire segments on the segment which Lillian newly adds.
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
#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的更多相关文章
- HDU 5372 Segment Game
/** 多校联合2015-muti7-1004 <a target=_blank href="http://acm.hdu.edu.cn/showproblem.php?pid=537 ...
- 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 ...
- 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: ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- yii 表单小部件使用
首先创建model层 因为要使用表单小部件 所以要加载相应的组件 这里需要的组件有 yii\widgets\ActiveForm 和 yii\helpers\Html 接下来在model定义的clas ...
- ASP.NET--Razor-model-compare属性用法
学习使用model中的compare属性来判断两个密码之间是否相同 [Required] [StringLength(100, ErrorMessage = "The {0} must be ...
- 第二篇:SpringBoot配置详解
SpringBoot 是为了简化 Spring 应用的创建.运行.调试.部署等一系列问题而诞生的产物,自动装配的特性让我们可以更好的关注业务本身而不是外部的XML配置,我们只需遵循规范,引入相关的依赖 ...
- 鸟书shell 学习笔记(二) shell中正則表達式相关
通配符与正則表達式的差别 通配符是bash原生支持的语法,正則表達式是处理字符串的一种表示方式, 正則表達式须要支持的工具支持才干够 语系设置 : export LANG=C grep alias 设 ...
- iframe是否缓存页面探究
近期手里有个项目须要用iframe来调用每天都会变化的页面,后来想到iframe会不会缓存页面呢.于是写了个demo论证了下,结果例如以下: iframe的src假设是静态页面,就有可能会缓存.由于静 ...
- CentOS 6 安装最新的 Redis 2.8 ,安装 TCMalloc
1,遇到的问题就是 redis 2.8 版本号依赖 Google 的 TCMalloc TCMalloc(Thread-Caching Malloc)是google开发的开源工具──"goo ...
- bzoj1924: [Sdoi2010]所驼门王的宝藏
陈年老题又来水一发啊啊啊 构图狗了一点,然后其实强连通缩点dij找最长路就没了. 没调出来有点气,直接打了第9个点的表.... 来逛blog的你教教我呗 #include<cstdio> ...
- EOJ 3213 向右看齐
题目描述 N 头奶牛被紧急动员起来了,它们排成了一条长列.从左向右看,排在第 i 个位置的奶牛身高为 Hi.约翰一声令下,所有奶牛向右看齐.假设每头奶牛只能看到比自己高的牛.请问它们各自看到的最近的一 ...
- Ubuntu下安装tim/QQ/微信
一.安装deepin-wine环境: 上https://github.com/wszqkzqk/deepin-wine-ubuntu页面下载zip包(或用git方式克隆),在“下载”目录下原地解压即可 ...
- BZOJ 3238 后缀数组+单调栈
单调栈跑两遍求出来 ht[i]为最小值的那段区间 //By SiriusRen #include <cstdio> #include <cstring> #include &l ...