ACdream 1157 Segments
Segments
This problem will be judged on ACdream. Original ID: 1157
64-bit integer IO format: %lld Java class name: (No Java Yet)
由3钟类型操作:
1)D L R(1 <= L <= R <= 1000000000) 增加一条线段[L,R]
2)C i (1-base) 删除第i条增加的线段,保证每条插入线段最多插入一次,且这次删除操作一定合法
3) Q L R(1 <= L <= R <= 1000000000) 查询目前存在的线段中有多少条线段完全包含[L,R]这个线段,线段X被线段Y完全包含即LY <= LX
<= RX <= RY)
给出N,接下来N行,每行是3种类型之一
Input
多组数据,每组数据N
接下来N行,每行是三种操作之一(1 <= N <= 10^5)
Output
Sample Input
6
D 1 100
D 3 8
D 4 10
Q 3 8
C 1
Q 3 8
Sample Output
2
1
Hint
注意,删除第i条增加的线段,不是说第i行,而是说第i次增加。
比如
D 1 10
Q 1 10
D 2 3
D 3 4
Q 5 6
D 5 6
C 2是删除D 2 3
C 4是删除D 5 6
Source
#include <bits/stdc++.h>
using namespace std;
const int maxn = ;
struct QU{
int l,r,id,v;
bool operator<(const QU &t) const{
if(r != t.r) return r > t.r;
if(l != t.l) return l < t.l;
return id < t.id;
}
bool operator>(const QU &t) const{
return id < t.id;
}
}Q[maxn];
int bit[maxn],Li[maxn],ans[maxn],tot,n;
void update(int i,int val){
for(; i <= tot; i += i&(-i))
bit[i] += val;
}
int sum(int i,int ret = ){
for(; i > ; i -= i&(-i))
ret += bit[i];
return ret;
}
int d[maxn],cnt;
void cdq(int L,int R){
if(R <= L) return;
int mid = (L + R)>>;
cdq(L,mid);
cdq(mid+,R);
sort(Q+L,Q+R+);
for(int i = L; i <= R; ++i){
if(Q[i].id <= mid && Q[i].v) update(Q[i].l,Q[i].v);
if(Q[i].id > mid && !Q[i].v) ans[Q[i].id] += sum(Q[i].l);
}
for(int i = L; i <= R; ++i)
if(Q[i].id <= mid && Q[i].v) update(Q[i].l,-Q[i].v);
}
int main(){
char op[];
while(~scanf("%d",&n)){
memset(bit,,sizeof bit);
memset(ans,,sizeof ans);
for(int i = cnt = tot = ; i < n; ++i){
scanf("%s",op);
Q[i].id = i;
if(op[] == 'D'){
scanf("%d%d",&Q[i].l,&Q[i].r);
d[cnt++] = i;
Q[i].v = ;
Li[tot++] = Q[i].l;
Li[tot++] = Q[i].r;
}else if(op[] == 'Q'){
scanf("%d%d",&Q[i].l,&Q[i].r);
Q[i].v = ;
Li[tot++] = Q[i].l;
Li[tot++] = Q[i].r;
}else{
scanf("%d",&Q[i].l);
Q[i].r = Q[d[Q[i].l-]].r;
Q[i].l = Q[d[Q[i].l-]].l;
Q[i].v = -;
}
}
sort(Li,Li + tot);
tot = unique(Li, Li + tot) - Li;
for(int i = ; i < n; ++i){
Q[i].l = lower_bound(Li, Li + tot,Q[i].l) - Li + ;
Q[i].r = lower_bound(Li, Li + tot,Q[i].r) - Li + ;
}
cdq(,n-);
sort(Q,Q+n,greater<QU>());
for(int i = ; i < n; ++i)
if(!Q[i].v) printf("%d\n",ans[Q[i].id]);
}
return ;
}
ACdream 1157 Segments的更多相关文章
- ACdream 1157 Segments(CDQ分治)
题目链接:http://acdream.info/problem?pid=1157 Problem Description 由3钟类型操作:1)D L R(1 <= L <= R < ...
- ACdream 1157 Segments CDQ分治
题目链接:https://vjudge.net/problem/ACdream-1157 题意: Problem Description 由3钟类型操作: 1)D L R(1 <= L < ...
- 【ACdream】1157 Segments cdq分治
Segments Problem Description 由3钟类型操作:1)D L R(1 <= L <= R <= 1000000000) 增加一条线段[L,R]2)C i ...
- ACdream 1157 (cdq分治)
题目链接 Segments Time Limit: 4000/2000MS (Java/Others)Memory Limit: 20000/10000KB (Java/Others) Problem ...
- [LeetCode] Number of Segments in a String 字符串中的分段数量
Count the number of segments in a string, where a segment is defined to be a contiguous sequence of ...
- Greenplum记录(一):主体结构、master、segments节点、interconnect、performance monitor
结构:Client--master host--interconnect--segment host 每个节点都是单独的PG数据库,要获得最佳的性能需要对每个节点进行独立优化. master上不包含任 ...
- Application package 'AndroidManifest.xml' must have a minimum of 2 segments.
看了源码就是packagename里面必须包含一个. 源码在: ./sdk/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/id ...
- segments&cache
Segments 执行效果 命令 在 sense 里边执行 GET /abcd/_segments 前边的是索引名称,后边是请求 段信息 说明 索引是面向分片的,是由于索引是由一个或多个分片( ...
- [UCSD白板题] Points and Segments
Problem Introduction The goal in this problem is given a set of segments on a line and a set of poin ...
随机推荐
- Redis,Memcache的区别和具体应用场景
1. Memcached简介 Memcached是以LiveJurnal旗下Danga Interactive公司的Bard Fitzpatric为首开发的高性能分布式内存缓存服务器.其本质上就是一个 ...
- 洛谷—— P1126 机器人搬重物
https://www.luogu.org/problem/show?pid=1126 题目描述 机器人移动学会(RMI)现在正尝试用机器人搬运物品.机器人的形状是一个直径1.6米的球.在试验阶段,机 ...
- [SharePoint2010开发入门经典]SPS2010列表编程
本章概要: 1.理解SPS2010列表的结构和功能 2.使用客户端和服务器端对象模型,web service,wcf和RESTful service进行列表编程. 3.理解方法的使用 4.类表编程
- WinSCP介绍、安装、使用
前言 如果说XManager通过Xshell.Xftp可以很方便的进行远程管理,那么PuTTY显然不能满足我们的需求,所以这也是今天要介绍的另外一个工具-WinSCP. 简介 WinSCP是一个Win ...
- add Admob with Cocos2d-x on iOS
add Admob with Cocos2d-x on iOS (2013-02-27 14:12:00) 转载▼ 标签: c=blog&q=it&by=tag" targe ...
- BAT常问问题总结以及回答(问题汇总篇)
几个大厂的面试题目目录: java基础(40题)https://www.cnblogs.com/television/p/9397968.html 多线程(51题) 设计模式(8点) JVM(12题) ...
- 【leetcode 字符串处理】Compare Version Numbers
[leetcode 字符串处理]Compare Version Numbers @author:wepon @blog:http://blog.csdn.net/u012162613 1.题目 Com ...
- 为代码减负之<三>视图(SQL)
在设计数据库时为了降低数据冗余.一般都会依照三范式去设计,但有时我们在查询时须要通过一字段获取跟这 个字段相关联的好几个字段.可是他们又分布在不同的表中,这时候假设依照正常途径走的话须要同一时候查询好 ...
- java 中的静态(static)代码块
类字面常量 final 静态域不会触发类的初始化操作 非 final static 静态域(以及构造器其实是一种隐式的静态方法) Class.forName():会自动的初始化: 使用 .class来 ...
- java多线程 interrupt(), interrupted(), isInterrupted()方法区别
interrupt()方法: 作用是中断线程. 本线程中断自身是被允许的,且"中断标记"设置为true 其它线程调用本线程的interrupt()方法时,会通过checkAcces ...