Segments

Time Limit: 2000ms
Memory Limit: 10000KB

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

对于每个Q操作,输出一行,答案

 

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

 
解题:CDQ分治
 
 #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的更多相关文章

  1. ACdream 1157 Segments(CDQ分治)

    题目链接:http://acdream.info/problem?pid=1157 Problem Description 由3钟类型操作:1)D L R(1 <= L <= R < ...

  2. ACdream 1157 Segments CDQ分治

    题目链接:https://vjudge.net/problem/ACdream-1157 题意: Problem Description 由3钟类型操作: 1)D L R(1 <= L < ...

  3. 【ACdream】1157 Segments cdq分治

    Segments   Problem Description 由3钟类型操作:1)D L R(1 <= L <= R <= 1000000000) 增加一条线段[L,R]2)C i ...

  4. ACdream 1157 (cdq分治)

    题目链接 Segments Time Limit: 4000/2000MS (Java/Others)Memory Limit: 20000/10000KB (Java/Others) Problem ...

  5. [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 ...

  6. Greenplum记录(一):主体结构、master、segments节点、interconnect、performance monitor

    结构:Client--master host--interconnect--segment host 每个节点都是单独的PG数据库,要获得最佳的性能需要对每个节点进行独立优化. master上不包含任 ...

  7. Application package 'AndroidManifest.xml' must have a minimum of 2 segments.

    看了源码就是packagename里面必须包含一个. 源码在: ./sdk/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/id ...

  8. segments&cache

    Segments 执行效果 命令  在 sense 里边执行  GET /abcd/_segments  前边的是索引名称,后边是请求 段信息 说明  索引是面向分片的,是由于索引是由一个或多个分片( ...

  9. [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 ...

随机推荐

  1. HDU2188(巴什博奕)

    悼念512汶川大地震遇难同胞--选拔志愿者 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...

  2. crm2013使用图片字段

    在CRM2013能够加入图片字段(一个实体仅仅能加入一个图片字段) watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveV9mMTIz/font/5a6L5L2 ...

  3. hdu 5410 CRB and His Birthday 01背包和全然背包

    #include<stdio.h> #include<string.h> #include<vector> #include<queue> #inclu ...

  4. linux块设备的IO调度算法和回写机制

    ************************************************************************************** 參考: <Linux ...

  5. Hbase集群扩展

    当hbase集群节点不够用时,我们须要新增节点来对集群进行扩展.hbase集群的扩展是非常easy的,过程例如以下: 一.准备一台新机器作为扩展节点,这里是作为slaves15,该机子要先与maste ...

  6. 从HTTP 2.0想到的关于传输层协议的一些事

    0.HTTP协议的历史 我也不知道... 1.关于HTTP 2.0 收到了订阅的邮件,头版是说HTTP 2.0的内容,我本人不是非常关注HTTP这一块儿.可是闲得无聊时也会瞟两眼的.HTTP 2.0的 ...

  7. System.DirectoryServices Namespace

    https://docs.microsoft.com/en-us/dotnet/api/system.directoryservices?view=netframework-4.7 The Syste ...

  8. HDU 5863 cjj's string game (矩阵乘法优化递推)

    题目大意:用k种字符构建两个长度为n的字符串(每种字符有无限多个),要求对应位置字符相同的连续子串最长长度为m,问方法数. 其中k,n,m是输入,n(1<=n<=1000000000), ...

  9. 解决Highcharts指针偏离的问题

    Highcharts 在初始化3D柱状图 时 (注意:3D图形会发生偏移,2D显示正常) 如果加入 shared: true,属性,则可能会导致柱 状图 toolTip提示框偏移,解决方法是去掉或注释 ...

  10. BZOJ 3105 线性基 高斯消元

    思路: 按照从大到小排个序 维护两个数组 一个是消元后的 另一个是 按照消元的位置排的 不断 维护从大到小 (呃具体见代码) //By SiriusRen #include <cstdio> ...