首页 > 其他分享 >【模板】二维数点

【模板】二维数点

时间:2022-11-06 19:37:16浏览次数:74  
标签:树状 线段 数点 solution 二维 询问 模板

posted on 2022-10-23 13:50:24 | under 模板 | source

problem

给定一个二维平面,多次询问 \(x\in[l_x,r_x],y\in[l_y,r_y]\) 的点有多少个。

solution 1(静态+在线):可持久化线段树

将 \(x\in[1,l]\) 的点,放入第 \(l\) 棵线段树中,询问时就是在第 \(l_x-1,r_x\) 这两棵线段树上求区间和。显然可以用可持久化线段树维护。

solution 2(静态+离线):树状数组

将询问 \((l_x,r_x,l_y,r_y)\) 拆成 \((1,r_x,1,r_y)-(1,l_x-1,1,r_y)-(1,r_x,1,l_y-1)+(1,l_x-1,1,l_y-1)\)。

不需要维护每个前缀,而只需要扫描线过去即可。树状数组。

标签:树状,线段,数点,solution,二维,询问,模板
From: https://www.cnblogs.com/caijianhong/p/16863462.html

相关文章

  • 【模板】网络流
    postedon2022-08-1214:14:05|under模板|source感谢讲师LQS带来的网络流专题。本文非常不严谨,请不要把它当作入门博客。0xFF目录0x00网络流及求法0x01......
  • 【模板】多项式乘法 FFT
    postedon2022-08-0223:57:12|under模板|source涉世不深,不会卡常,恳求大佬指教typedefcomplex<double>comp;constdoublePI=acos(-1);template<intN>struct......
  • 【模板】对拍
    postedon2022-10-1813:30:17|under模板|sourceconstchar*name="bit";#include<cstdio>#include<cstring>#include<algorithm>usingnamespacestd;type......
  • 【模板】动态树 Link-Cut Tree
    postedon2022-08-1718:05:59|under模板|sourcetemplate<intN>structlctree{ intval[N+10],sum[N+10],fa[N+10],ch[N+10][2],rev[N+10]; boolgetson(intp)......
  • 【模板】点分治 Centroid Decomposition
    postedon2022-07-2018:59:16|under模板|source0x00模板(P3806)给定\(n,k\)和一棵树,计算\[\sum\limits_{i,j\leqn}[{\ttdist}(i,j)=k]\]即树上距离为\(k\)......
  • 【模板】并查集 DSU
    postedon2021-09-1215:49:52|under模板|source0x00模板并查集维护的是这样一个问题:\(n\)个点,初始时每个点自己一个集合。\({\ttmerge}(x,y)\):合并\(x,y\)......
  • 【模板】Z 函数(扩展 KMP)
    postedon2022-08-0823:29:53|under模板|source#include<cstdio>#include<cstring>#include<algorithm>usingnamespacestd;typedeflonglongLL;intn,......
  • 【模板】Tarjan
    postedon2022-07-0720:52:49|under模板|source0x00有向图缩点现有一有向图\(G=(V,E)\),称一个点集\(E'\inE\)为强连通分量,当且仅当\(E'\)的任意两点可以互......
  • 【模板】ST 表 Sparse Table
    postedon2022-07-2219:15:58|under模板|sourcetemplate<intN,classT=int,intlogN=20>structSTable{ inttot,lg[N+10];Tf[logN+1][N+10]; STable():tot(0......
  • 【模板】Splay
    postedon2022-07-2117:03:54|under模板|source(介绍等会补)调试:getpre、getsuf、find手写,常数不要乘以二。UB:getkth和getrnk叠起来的时候root会改!UB:getp......