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 ...
随机推荐
- 使用maven服务器插件 运行项目
使用jetty插件 部署运行 创建一个maven项目:去Maven仓库中寻找jetty插件 然后复制到pom.xml中 使用命令 运行程序: 然后控制台打印: 通过浏览器 访问: ----- ...
- [Asp.net]EF更新之后要 保存
数据库那边保存表 项目里保存模型
- POJ 2132
我早上调了一个早上,下午才发现把e=edge[e].next写成edge[e].next了... 这题直接DFS,一个剪枝是,当当前的最大质因数是最小公倍数的因数时,不用搜索 #include < ...
- 学习笔记一:关于directx sdk的安装于一些概念
关于directx sdk开发环境的安装: 在百度搜索了directx sdk,进入了微软的官网,下载了DXSDK_Jun10.exe 百度网盘:http://pan.baidu.com/s/1o6r ...
- 数据结构 - 归并排序(merging sort) 具体解释 及 代码
归并排序(merging sort) 具体解释 及 代码 本文地址: http://blog.csdn.net/caroline_wendy 归并排序(merging sort): 包括2-路归并排序 ...
- System.setProperty 与 System.getProperty
转自:https://www.cnblogs.com/woftlcj/p/8404451.html System可以有对标准输入,标准输出,错误输出流:对外部定义的属性和环境变量的访问:加载文件和库的 ...
- web前端简单布局
jquery实现的计算器
- 通过QEMU-GuestAgent实现从外部注入写文件到KVM虚拟机内部
本文将以宿主上直接写文件到VM内部为例讲解为何要注入以及如何实现 tag: qemu-ga, qemu guest agent, kvm, guest-file-write, inject 小慢哥的原 ...
- C#读出文本文件内容,遍历数组筛选出 含有汉字对应的拼音字符
情景描述:由于任务需要,现有一用户表数据,用户名 字段 在新增用户时,输入中文和拼音两种,先要区分同时含有中文和拼音字母的用户名.由于数据很多,可以通过一段代码完成查询: 前提:在阅读本文之前可以先了 ...
- golang sftp传输文件
之前有一篇介绍如何使用 golang 通过SSH协议来执行远程命令:golang执行远程命令 同样,通过SSH协议也可以使用 golang 来远程传输文件. 除了 SSH 的库,为了传输文件,还需要用 ...