acdream 1157Segments cdq分治
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <complex>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef complex <double> cmx;
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
const int maxn = 1e5+;
int v[maxn*], n, b[maxn], cnt, num, sum[maxn*], ans[maxn];
struct node
{
int l, r, id, val;
}a[maxn];
bool cmp1(const node& lhs, const node& rhs)
{
return lhs.id < rhs.id;
}
bool cmp2(const node& lhs, const node& rhs)
{
if(lhs.r != rhs.r)
return lhs.r > rhs.r;
if(lhs.l != rhs.l)
return lhs.l < rhs.l;
return lhs.id < rhs.id;
}
int lowbit(int x) {return x&(-x);}
void update(int x, int val)
{
while(x <= cnt) {
sum[x] += val;
x += lowbit(x);
}
}
int query(int x)
{
int ret = ;
while(x) {
ret += sum[x];
x -= lowbit(x);
}
return ret;
}
void cdq(int l, int r)
{
if(l == r) return ;
int m = l+r>>;
cdq(l, m);
cdq(m+, r);
sort(a+l, a++r, cmp2);
for(int i = l; i <= r; i++) {
if(a[i].id <= m && a[i].val)
update(a[i].l, a[i].val);
if(a[i].id > m && !a[i].val)
ans[a[i].id] += query(a[i].l);
}
for(int i = l; i <= r; i++)
if(a[i].id <= m && a[i].val)
update(a[i].l, -a[i].val); }
void solve()
{
mem(ans);
mem(sum);
sort(v, v+cnt);
cnt = unique(v, v+cnt)-v;
for(int i = ; i <= n; i++) {
a[i].l = lower_bound(v, v+cnt, a[i].l)-v+;
a[i].r = lower_bound(v, v+cnt, a[i].r)-v+;
}
cdq(, n);
sort(a+, a++n, cmp1);
for(int i = ; i <= n; i++) {
if(!a[i].val)
printf("%d\n", ans[i]);
}
}
int main()
{
int x;
while(~scanf("%d", &n)) {
cnt = num = ;
for(int i = ; i <= n; i++) {
char ch[];
scanf("%s", ch);
a[i].id = i;
if(ch[] == 'C') {
scanf("%d", &x);
a[i].l = a[b[x]].l;
a[i].r = a[b[x]].r;
a[i].val = -;
} else {
scanf("%d%d", &a[i].l, &a[i].r);
v[cnt++] = a[i].l;
v[cnt++] = a[i].r;
if(ch[] == 'D') {
b[++num] = i;
a[i].val = ;
} else {
a[i].val = ;
}
}
}
solve();
}
return ;
}
acdream 1157Segments cdq分治的更多相关文章
- 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 ...
- 【教程】简易CDQ分治教程&学习笔记
前言 辣鸡蒟蒻__stdcall终于会CDQ分治啦! CDQ分治是我们处理各类问题的重要武器.它的优势在于可以顶替复杂的高级数据结构,而且常数比较小:缺点在于必须离线操作. CDQ分治的基 ...
- BZOJ 2683 简单题 ——CDQ分治
[题目分析] 感觉CDQ分治和整体二分有着很本质的区别. 为什么还有许多人把他们放在一起,也许是因为代码很像吧. CDQ分治最重要的是加入了时间对答案的影响,x,y,t三个条件. 排序解决了x ,分治 ...
- HDU5618 & CDQ分治
Description: 三维数点 Solution: 第一道cdq分治...感觉还是很显然的虽然题目不能再傻逼了... Code: /*=============================== ...
- 初识CDQ分治
[BZOJ 1176:单点修改,查询子矩阵和]: 1176: [Balkan2007]Mokia Time Limit: 30 Sec Memory Limit: 162 MBSubmit: 200 ...
- HDU5322 Hope(DP + CDQ分治 + NTT)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5322 Description Hope is a good thing, which can ...
随机推荐
- 常用WebService收集
尊重原著作:本文转载自http://www.cnblogs.com/tianguook/archive/2010/09/29/1838469.html 天气预报Web服务,数据来源于中国气象局Endp ...
- 5.7.13mysql 无法登陆
话不多说 用的http://dev.mysql.com/downloads/mysql/下的ZIP Archive安装方式 下载 解压,然后吧bin目录添加到系统path环境变量下.然后将my-de ...
- DataTable中执行DataTable.Select("条件"),
我们在使用Sql ******这些数据库时,可以轻松的通过Sum.Aver.Count等统计出相关结果,那么,在已经把数据检索出来的DataSet(DataTable)中呢?特别是通过Web Serv ...
- 二.ubuntu14.04 3D特效设置
一.如果按照第一篇都设置好了(显卡驱动等都已经正常),然后 1.安装CCSM设置管理器 用鼠标点击屏幕左侧Unity程序启动栏中的“Ubuntu软件中心”(有“A”字形的公文包图标), 在弹出的“Ub ...
- IIS7.0 部署wcf 404或者配置MIME(转)
WCF部署在IIS下,报错如下: 应用程序“DEFAULT WEB SITE/IMF”中的服务器错误 Internet 信息服务 7.0 错误摘要 HTTP 错误 404.3 - Not Found由 ...
- Android Studio中如何创建AIDL
实现客户端添加Book,Service接收并打印出书籍信息 一.创建Book类 1.创建文件夹(本文命名为aidl) 2.创建Book类并继承Parcelable接口(原因:AIDL只能传送继承Par ...
- Python爬虫:常用浏览器的useragent
1,为什么需要修改UserAgent 在写python网络爬虫程序的时候,经常需要修改UserAgent,有很多原因,罗列几个如下: 不同Agent下看到的内容不一样,比如,京东网站上的手机版网页和p ...
- js返回当前时间的毫秒数
Date.now(); +new Date(); new Date().getTime();
- Keil MDK中使用pc-lint的详细方法
keil MDK版本:V4.03 PC-lint版本: V8.0 关于pc-lint的强大作用,网上有很多,这里不想再复述,只说一句:能通过pc-lint检验的程序不一定没有问题,但通过了pc-li ...
- 【第一篇章-android平台buffer播放探索】native media
在android平台,从4.0开始,提出了openmax架构,所以在DNK的R7版本中有了openmax AL层播放的DEMO即native media,这个DEMO就是读本地文件,然后把所读buff ...