传送门

解题思路

  首先一定不可能有\(-1\)的情况,因为新产生的黑点不会造成任何贡献,它的各个方面都是不优的。那么只需要统计一遍答案,首先要将横坐标相同的两个点看成一条竖线,纵坐标相同的点看成一条横线,然后从下往上扫描,遇到竖线的下端点时,在树状数组里\(+1\),遇到竖线上端点时,\(-1\),然后遇到横线时就统计答案。

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm> using namespace std;
const int N=100005; inline int rd(){
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)) f=ch=='-'?0:1,ch=getchar();
while(isdigit(ch)) x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
return f?x:-x;
} int n,a[N],ans,cnt,f[N],u; struct Node{
int x,y;
}node[N]; struct Data{
int x,y,k,z;
friend bool operator<(const Data A,const Data B){
return A.y==B.y?A.k>B.k:A.y<B.y;
}
}data[N<<2]; inline bool cmp1(Node A,Node B){
return A.x==B.x?A.y<B.y:A.x<B.x;
}
inline bool cmp2(Node A,Node B){
return A.y==B.y?A.x<B.x:A.y<B.y;
} inline void Insert(int x,int l,int r,int k){
if(!k) {data[++cnt].x=l; data[cnt].z=r; data[cnt].y=x;}
else {
data[++cnt].x=x; data[cnt].y=l; data[cnt].k=1;
data[++cnt].x=x; data[cnt].y=r; data[cnt].k=-1;
}
} inline void build(){
sort(node+1,node+1+n,cmp1);
for(int i=2;i<=n;i++)
if(node[i].x==node[i-1].x)
Insert(node[i].x,node[i-1].y,node[i].y,1);
sort(node+1,node+1+n,cmp2);
for(int i=2;i<=n;i++)
if(node[i].y==node[i-1].y)
Insert(node[i].y,node[i-1].x,node[i].x,0);
} inline void update(int x,int y){
for(;x<=u;x+=x&-x) f[x]+=y;
}
inline int query(int x){
int ret=0;
for(;x;x-=x&-x) ret+=f[x];
return ret;
} inline void work(){
sort(data+1,data+1+cnt);
for(int i=1;i<=cnt;i++){
if(!data[i].k) ans+=query(data[i].z-1)-query(data[i].x);
else update(data[i].x,data[i].k);
}
} int main(){
n=rd(); ans=n; int x,y;
for(int i=1;i<=n;i++){
x=rd(),y=rd(); a[i]=x;
node[i].x=x,node[i].y=y;
}
sort(a+1,a+1+n); u=unique(a+1,a+1+n)-a-1;
for(int i=1;i<=n;i++)
node[i].x=lower_bound(a+1,a+1+u,node[i].x)-a;
build(); work();
printf("%d\n",ans);
return 0;
}

BZOJ 1818: [Cqoi2010]内部白点(树状数组)的更多相关文章

  1. B1818 [Cqoi2010]内部白点 树状数组

    这个题的想法很好想,就是进行排序之后直接检查每个点的上下左右是否有黑点就行.但是直接枚举显然不行,那怎么办呢?我们就用树状数组维护扫描线,把每排左右点看成一条线覆盖,然后从下往上扫,遇到下加一,遇到上 ...

  2. BZOJ 1818: [Cqoi2010]内部白点 扫描线+树状数组

    问题转化为求每一个极长横线段与极长纵线段的交点个数. 这个东西用扫描线+树状数组维护一下就可以了. code: #include <cstdio> #include <algorit ...

  3. bzoj 1818: [Cqoi2010]内部白点

    #include<cstdio> #include<iostream> #include<algorithm> using namespace std; struc ...

  4. bzoj 1818 Cqoi2010 内部白点 扫描线

    [Cqoi2010]内部白点 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 1126  Solved: 530[Submit][Status][Disc ...

  5. BZOJ 1818: [Cqoi2010]内部白点 (BIT + 扫描线)

    就是求多条线段的交点数,直接BIT+扫描线就行了. 注意不要算重最初存在的点. CODE #include<bits/stdc++.h> using namespace std; char ...

  6. 【BZOJ】1818: [Cqoi2010]内部白点(树状数组+离散+特殊的技巧)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1818 这一题一开始我就看错了,bzoj的那个绝对值109简直坑人,应该是10^9,我直接写了个暴力. ...

  7. BZOJ 1901 Zju2112 Dynamic Rankings ——树状数组套主席树

    [题目分析] BZOJ这个题目抄的挺霸气. 主席树是第一时间想到的,但是修改又很麻烦. 看了别人的题解,原来还是可以用均摊的思想,用树状数组套主席树. 学到了新的姿势,2333o(* ̄▽ ̄*)ブ [代 ...

  8. [BZOJ 1901] Dynamic Rankings 【树状数组套线段树 || 线段树套线段树】

    题目链接:BZOJ - 1901 题目分析 树状数组套线段树或线段树套线段树都可以解决这道题. 第一层是区间,第二层是权值. 空间复杂度和时间复杂度均为 O(n log^2 n). 线段树比树状数组麻 ...

  9. BZOJ 2743: [HEOI2012]采花 [树状数组 | 主席树]

    题意: 查询区间中出现次数$>2$的颜色个数 一眼主席树,区间中$l \le last[i] \le r$的个数减去$l \le last[last[i]] \le r$的个数,搞两颗主席树来做 ...

随机推荐

  1. UGUI OnValueChanged 动态参数指定

    在选择方法的时候注意,选择最上面的动态参数的方法.

  2. Delphi 快速读取TXT 指定行的数据

    http://blog.csdn.net/MichaelJScofield/article/details/41869785 Delphi 快速读取TXT 指定行的数据 分类:Delphi个人挫品 ( ...

  3. 【ABAP系列】SAP ABAP中关于commit的一点解释

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP中关于commi ...

  4. Convolutional Neural Networks(2):Sparse Interactions, Receptive Field and Parameter Sharing

    Sparse Interactions, Receptive Field and Parameter Sharing是整个CNN深度网络的核心部分,我们用本文来具体分析其原理. 首先我们考虑Feedf ...

  5. webStom常用快捷键备忘

    Ctrl+W 选中代码,连续按会有其他效果 Ctrl+/ 或 Ctrl+Shift+/ 注释(// 或者/…/ ) Ctrl+X 删除行Ctrl+D 复制行 ctrl+shift+ 箭头 上下移动块代 ...

  6. vuejs基础-v-for用法

    Vue指令之v-for和key属性 迭代数组 <ul> <li v-for="(item, i) in list">索引:{{i}} --- 姓名:{{it ...

  7. linux mysql修改数据表结构语法

    MySQL修改表的语法=========================增加列[add 列名]=========================①alter table 表名 add 列名 列类型 列 ...

  8. html中head示例

    <!DOCTYPE html> <!-- #统一的规范--> <!--类似html这种 ,html标签<html>dasdasd</html>&g ...

  9. redis学习(二)

    简单了解一下 1.build.gradle中添加 依赖  org.springframework.boot:spring-boot-starter-data-redis //定义依赖:声明项目中需要哪 ...

  10. mpvue 微信小程序半屏弹框(half-screen-dialog)

    <template> <div> <a @click="isShow">half-screen-dialog</a> <!-- ...