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 ...
随机推荐
- AjaxHelper学习,ajax,microsoft,mvc,asp.net
index.cshtml @using (Ajax.BeginForm("ContentAjax", new AjaxOptions { UpdateTargetId = &quo ...
- NSURLSessionDownloadTask 下载文件
-(void)RequestdataUI:(NSString*)ImageURL imageName:(NSString*)imageName{ NSURL *url = [NSURL URLWith ...
- C#高效分页代码(不用存储过程)
首先创建一张表(要求ID自动编号): create table redheadedfile ( id ,), filenames ), senduser ), primary key(id) ) 然后 ...
- strutr2运行流程
1. 请求发送给 StrutsPrepareAndExecuteFilter 2. StrutsPrepareAndExecuteFilter 询问 ActionMapper: 该请求是否是一个 St ...
- [string]Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...
- Service(Local Service)简介
一.Service的作用 主要用于在后台处理一些耗时的逻辑操作,或者去执行某些长期运行的操作. 二.Service的创建 1.主要方法 IBinder onBind(Intent intent):必须 ...
- css中element element和element>element选择器的区别
就是这样的选择器: 比如html中有这样一段布局: <div> <p>我是一个段落</p> </div> 这时你用div p{background:ye ...
- MacBook USB Type-C接口很美?其实是缩水的!
苹果终于推出了12寸的全新MacBook,拥有2304×1440的高分辨率.蝶式结构全尺寸键盘.新的触摸板.14nm Core M处理器和无风扇设计,以及新的USB 3.1 Type-C接口.可以预料 ...
- 没有产品,没有用户的,绝对不要浪费时间去联系风投——没有过home run的创业人,想办法先做出产品,找到少量用户,没有任何销售成本
著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处.作者:Kuan Huang链接:http://www.zhihu.com/question/19641135/answer/1353 ...
- 大型项目使用Automake/Autoconf完成编译配置
http://www.cnblogs.com/xf-linux-arm-java-android/p/3590770.htmlhttp://blog.csdn.net/zengraoli/articl ...