思路:主席树搞一搞。

#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 主席树的更多相关文章

  1. bzoj 1901 主席树+树状数组

    修改+查询第k小值 单纯主席树修改会打乱所有,所以再套一个树状数组维护前缀和使得修改,查询都是log 对了,bzoj上不需要读入组数,蜜汁re.. #include<cstdio> #in ...

  2. BZOJ 2588 主席树

    思路: 主席树 做完BZOJ 3123 觉得这是道水啊-- 然后狂RE 狂MLE 要来数据 忘把deep[1]设成1了----------. 啊wocccccccccccccccc //By Siri ...

  3. BZOJ 4771 主席树+倍增+set

    思路: 因为有深度的限制,并且我们是在线段树上维护权值,所以我们把点按照dep排序,然后一个一个修改...主席树的下标就是dfs序,子树的查询就是区间查询... 但是发现这样怎么去维护LCA呢...因 ...

  4. BZOJ 3674/BZOJ 3673 主席树

    思路: 主席树维护可持久化数组 剩下的就是普通的并查集了- //By SiriusRen #include <cstdio> #include <cstring> #inclu ...

  5. BZOJ 3123 主席树 启发式合并

    思路: 主席树 搞树上的k大 x+y-lca(x,y)-fa(lca(x,y)) 按照size小树往大树上插 启发式合并 n*log^2n的 搞定~ //By SiriusRen #include & ...

  6. BZOJ 4448 主席树+树链剖分(在线)

    为什么题解都是离线的-- (抄都没法抄) 搞一棵主席树 1 操作 新树上的当前节点设成1 2 操作 查max(i-xx-1,0)那棵树上这条路径上有多少个点是1 让你找经过了多少个点 查的时候用dee ...

  7. BZOJ 3524主席树裸题 (雾)

    思路: 按权值建一棵主席树 (但是这好像不是正解 空间复杂度是不对的--.) //By SiriusRen #include <cstdio> #include <cstring&g ...

  8. BZOJ 3524 - 主席树

    传送门 题目分析 标准主席树,按照位置插入每个数,对于询问l, r, 在l-1,r两树上按照线段树搜索次数大于(r - l + 1) / 2的数. code #include<bits/stdc ...

  9. BZOJ 3932 - 主席树

    传送门 题目分析 在只打会主席树模板的情况下做了这道题,也算是深有体会. 首先任务可以差分:一个任务是(s, e, p), 则在s处+1, 在e+1处-1,符合前缀.但是我们要查询指定时间的前k任务之 ...

随机推荐

  1. Tensorflow实现学习率衰减

    Tensorflow实现学习率衰减 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 Deeplearning AI Andrew Ng Tensorflow1.2 API 学习率衰减 ...

  2. js获取本周、上周的开始结束时间

    这两天在做一个报表体统,其中涉及到了一个根据本周,上周,本月,上月的时间来进行查询的问题,在这个我就教一下大家怎么实现,大家如果有更好的实现方法的,我也希望大家能说出来,我们交流交流. 首先呢,我写了 ...

  3. 比较时间的大小("HH:MM")格式

    function compareStrTime( timeStart , timeEnd ) { var dateA = new Date("2018/10/11 " + time ...

  4. UVA-10779 Collectors Problem

    https://vjudge.net/problem/UVA-10779 题意:n个人,m种贴纸,每个人开始有一些贴纸 第一个人可以跟任何人交换任何贴纸 其余人只能用重复的贴纸 跟第一个人交换他们没有 ...

  5. CF821 D. Okabe and City 图 最短路

    Link 题意:给出$n*m$大小的地图,已有$k$盏灯亮,人从左上角出发,右下角结束,期间必须走路灯点亮的地方,他可以在任意时刻消耗一枚硬币点亮一行或一列灯,他最多同时点亮一行或一列灯,要想点亮别的 ...

  6. CodeForces 990C

    Description A bracket sequence is a string containing only characters "(" and ")" ...

  7. 基于bootstrap物资管理系统后台模板——后台

    链接:http://pan.baidu.com/s/1geKwVMN 密码:0utl

  8. oracle 归档模式、补充日志

    1.归档模式: Oracle数据库有联机重做日志,这个日志是记录对数据库所做的修改,比如插入,删除,更新数据等,对这些操作都会记录在联机重做日志里.一般数据库至少要有2个联机重做日志组.当一个联机重做 ...

  9. Git远程操作详解【转】

    转自:http://www.ruanyifeng.com/blog/2014/06/git_remote.html 作者: 阮一峰 日期: 2014年6月12日 Git是目前最流行的版本管理系统,学会 ...

  10. C#:Excel上传服务器后导入数据库