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 ...
随机推荐
- javascript 里找元素操作元素
javascript 一.找到元素. var d = document.getElementById("") var d = document.getElementsByNa ...
- 【grunt整合版】 30分钟学会使用grunt打包前端代码
grunt 是一套前端自动化工具,一个基于nodeJs的命令行工具,一般用于:① 压缩文件② 合并文件③ 简单语法检查 对于其他用法,我还不太清楚,我们这里简单介绍下grunt的压缩.合并文件,初学, ...
- jQuery插入节点的方法
注:摘自<锋利的jQuery(第二版)> append() 向每个匹配的元素内部追加内容: HTML代码:<p>我想说:</p>jQuery代码:$(" ...
- ListFragment和ListActivity的setOnItemClickListener不起作用
在使用ListFragment时,发现一个奇怪的问题,就是getListView().setOnItemClickListener(new OnItemClickListener...)不起作用.在s ...
- jdk7和8的一些新特性介绍
jdk7和8的一些新特性介绍 本文是我学习了解了jdk7和jdk8的一些新特性的一些资料,有兴趣的大家可以浏览下下面的内容. 官方文档:http://www.oracle.com/technetwor ...
- java的几个版本以及jre,jdk等概念——【转载】JDK、Java SE、Java EE、Java ME我该选
我们平时使用的一些软件,有一部分需要Java环境的支持,但是SUN那么多的产品,让人眼花缭乱的版本号,前看后看都差不多的缩写,让我们选择起来的时候常常望而却步,只好跟着感觉走.所以下面我要介绍的就是那 ...
- 04737_C++程序设计_第3章_函数和函数模板
例3.1 传对象不会改变原来对象数据成员值的例子. #define _SCL_SECURE_NO_WARNINGS #include <iostream> #include <str ...
- jquery实现文字选择器
$( "div:contains('John')" ).css( "text-decoration", "underline" );
- ios 常用宏(copy)
分享一下我现在用的 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 3 ...
- P酱的冒险旅途(思维)
P酱的冒险旅途 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit S ...