bzoj 1818 主席树
思路:主席树搞一搞。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PII pair<int, int>
#define y1 skldjfskldjg
#define y2 skldfjsklejg
using namespace std; const int N = 1e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = ; int hs1[N], hs2[N], mnX[N], mxX[N], mnY[N], mxY[N], tot1, tot2, n;
int root[][N]; struct Point {
int x, y;
Point(int _x = , int _y = ) {
x = _x; y = _y;
}
} a[N]; struct Chairman_tree {
int tot;
struct node {
int sum, l, r;
} a[N * ];
void update(int p, int l, int r, int &x, int y) {
x = ++tot; a[x] = a[y]; a[x].sum++;
if(l == r) return;
int mid = l + r >> ;
if(p <= mid) update(p, l, mid, a[x].l, a[y].l);
else update(p, mid + , r, a[x].r, a[y].r);
}
int query(int L, int R, int l, int r, int x, int y) {
if(L > R) return ;
if(l >= L && r <= R) return a[x].sum - a[y].sum;
int mid = l + r >> , ans = ;
if(L <= mid) ans += query(L, R, l, mid, a[x].l, a[y].l);
if(R > mid) ans += query(L, R, mid + , r, a[x].r, a[y].r);
return ans;
}
} ct[]; int main() {
ct[].tot = ct[].tot = ;
memset(mnX, inf, sizeof(mnX));
memset(mnY, inf, sizeof(mnY));
memset(mxX, , sizeof(mxX));
memset(mxY, , sizeof(mxY));
scanf("%d", &n);
for(int i = ; i <= n; i++) {
scanf("%d%d", &a[i].x, &a[i].y);
hs1[++tot1] = a[i].x;
hs2[++tot2] = a[i].y;
}
sort(hs1 + , hs1 + + tot1);
sort(hs2 + , hs2 + + tot2);
tot1 = unique(hs1 + , hs1 + + tot1) - hs1 - ;
tot2 = unique(hs2 + , hs2 + + tot2) - hs2 - ; for(int i = ; i <= n; i++) {
a[i].x = lower_bound(hs1 + , hs1 + + tot1, a[i].x) - hs1;
a[i].y = lower_bound(hs2 + , hs2 + + tot2, a[i].y) - hs2;
mnX[a[i].x] = min(mnX[a[i].x], a[i].y);
mxX[a[i].x] = max(mxX[a[i].x], a[i].y);
mnY[a[i].y] = min(mnY[a[i].y], a[i].x);
mxY[a[i].y] = max(mxY[a[i].y], a[i].x);
} for(int i = ; i <= tot2; i++) {
ct[].update(mnY[i], , tot1, root[][i], root[][i - ]);
ct[].update(mxY[i], , tot1, root[][i], root[][i - ]);
} LL ans = ; for(int i = ; i <= tot1; i++) {
ans += mxX[i] - mnX[i] + ;
ans -= ct[].query(i + , tot1, , tot1, root[][mxX[i]], root[][mnX[i]-]);
ans -= ct[].query(, i - , , tot1, root[][mxX[i]], root[][mnX[i]-]);
} printf("%lld\n", ans);
return ;
}
bzoj 1818 主席树的更多相关文章
- bzoj 1901 主席树+树状数组
修改+查询第k小值 单纯主席树修改会打乱所有,所以再套一个树状数组维护前缀和使得修改,查询都是log 对了,bzoj上不需要读入组数,蜜汁re.. #include<cstdio> #in ...
- BZOJ 2588 主席树
思路: 主席树 做完BZOJ 3123 觉得这是道水啊-- 然后狂RE 狂MLE 要来数据 忘把deep[1]设成1了----------. 啊wocccccccccccccccc //By Siri ...
- BZOJ 4771 主席树+倍增+set
思路: 因为有深度的限制,并且我们是在线段树上维护权值,所以我们把点按照dep排序,然后一个一个修改...主席树的下标就是dfs序,子树的查询就是区间查询... 但是发现这样怎么去维护LCA呢...因 ...
- BZOJ 3674/BZOJ 3673 主席树
思路: 主席树维护可持久化数组 剩下的就是普通的并查集了- //By SiriusRen #include <cstdio> #include <cstring> #inclu ...
- BZOJ 3123 主席树 启发式合并
思路: 主席树 搞树上的k大 x+y-lca(x,y)-fa(lca(x,y)) 按照size小树往大树上插 启发式合并 n*log^2n的 搞定~ //By SiriusRen #include & ...
- BZOJ 4448 主席树+树链剖分(在线)
为什么题解都是离线的-- (抄都没法抄) 搞一棵主席树 1 操作 新树上的当前节点设成1 2 操作 查max(i-xx-1,0)那棵树上这条路径上有多少个点是1 让你找经过了多少个点 查的时候用dee ...
- BZOJ 3524主席树裸题 (雾)
思路: 按权值建一棵主席树 (但是这好像不是正解 空间复杂度是不对的--.) //By SiriusRen #include <cstdio> #include <cstring&g ...
- BZOJ 3524 - 主席树
传送门 题目分析 标准主席树,按照位置插入每个数,对于询问l, r, 在l-1,r两树上按照线段树搜索次数大于(r - l + 1) / 2的数. code #include<bits/stdc ...
- BZOJ 3932 - 主席树
传送门 题目分析 在只打会主席树模板的情况下做了这道题,也算是深有体会. 首先任务可以差分:一个任务是(s, e, p), 则在s处+1, 在e+1处-1,符合前缀.但是我们要查询指定时间的前k任务之 ...
随机推荐
- git 从新的git 库中拉取---变换git地址用;
2.先删后加 git remote rm origin git remote add origin [url]----- example : git remote add origin http: ...
- 驱动学习5: zynq实现点亮led
驱动代码: #include <linux/module.h> #include <linux/kernel.h> #include <linux/fs.h> #i ...
- 使用tqdm组件构造程序进度条
使用tqdm组件构造程序进度条 觉得有用的话,欢迎一起讨论相互学习~Follow Me 主要代码 import tqdm # 引用tqdm组件 TRAIN_STEPS = N for i in tqd ...
- C/C++预处理宏的总结
1.定义顺序的无关性 #define PI 3.14 #define TWO_PI 2*PI 这两句谁前谁后无所谓,因为预处理器不断迭代来实现宏替换,直到源文件中没有宏了才停止. 2. 宏变量变成字 ...
- swift开发常用代码片段
// 绑定事件 cell.privacySwitch.addTarget(self, action: #selector(RSMeSettingPrivacyViewController.switch ...
- LeetCode-Evaluate Reverse Polish Notation[AC源码]
package com.lw.leet2; /** * @ClassName:Solution * @Description: * Evaluate the value of an arithmeti ...
- ubuntu学习命令
1.双系统下挂载windows硬盘 检测ntfs-3g是否安装:locate ntfs-3g 没有则安装: sudo apt-get install ntfs-3g 查看硬盘信息: sudo fdis ...
- Let's Encrypt 免费通配 https 签名证书 安装方法2 ,安卓签名无法认证!
Let's Encrypt 免费通配 https 签名证书 安装方法 按照上文 配置完毕后你会发现 在pc浏览器中正常访问,在手机浏览器中无法认证 你只需要安装一个或多个中级证书 1.查看Nginx ...
- 详解H5中的history单页面,手动实现单页面开发,细说h5单页面原理
就目前来看,前端的单页面开发占了很大一部分,一方面无刷新的切换增强了体验,并且浏览器记录依然存在,前进后退都没问题,在之前我们通地址栏中的hash改变来触发onhashchange方法来实现单页面应用 ...
- 大聊PYthon----生成器
再说迭代器与生成器之前,先说一说列表生成式 列表生成式 什么是列表生成式呢? 这个非常简单! 先看看普通青年版的! >>> a [0, 1, 2, 3, 4, 5, 6, 7, 8, ...