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 ...
随机推荐
- static类型autowired 注入失败
原代码:注入commonService对象失败 @Autowired private static CommonService commonService; public static List< ...
- Cache index coloring for virtual-address dynamic allocators
A method for managing a memory, including obtaining a number of indices and a cache line size of a c ...
- linux 下 The valid characters are defined in RFC 7230 and RFC 3986
换tomcat 8.0.38就ok . 下载地址: http://archive.apache.org/dist/tomcat/tomcat-8/v8.0.38/bin/apache-tomcat-8 ...
- 看云-git类的书籍写作
看云-git类的书籍写作 https://www.kancloud.cn/explore 测试一本:https://www.kancloud.cn/stono/b001/501901
- 使用Struts2和jQuery EasyUI实现简单CRUD系统(五)——jsp,json,EasyUI的结合
这部分比較复杂,之前看过自己的同学开发一个选课系统的时候用到了JSON,可是一直不知道有什么用.写东西也没用到.所以没去学他.然后如今以这样的怀着好奇心,这是做什么用的,这是怎么用的.这是怎么结合的心 ...
- 从C到C++(下)
继承 从一个类派生到另外一个类,使前者的所有特征在后者中自己主动可用. 他能够声明一些类型,这些类型能够共享部分或所有曾经所声明的类型.它也能够从超过一个的基类中共享一些特性. C++是支持多继承的. ...
- Jasperreport+ireport 实践操作及web应用
Jasperreport+ireport 实践操作及web应用 学习完jasperreports+ireport,给我感觉深刻,不仅掌握了报表开发技术,还掌握了怎样在web中生成pdf,xls,r ...
- UVA 10593 Kites DP
The season of flying kites is well ahead. So what? Let us make an inventory for kites. We are givena ...
- Win+X
Win+X 方便的快捷键,可以快速使用命令行和运行!
- 多年iOS开发经验总结(一)
总结了几个月的东西终于能和大家分享了,不多说,直接看东西! 1.禁止手机睡眠 1 [UIApplication sharedApplication].idleTimerDisabled = YES; ...