先二分答案转化成判定问题。

考虑拿一根扫描线从 \(x=0\) 扫到 \(x=n\),每次移动扫描线更新每个位置它上面的点数和下面的点数,这样可以确定在当前的扫描线上哪些位置对于 \(y\) 轴方向是合法的。对于 \(x\) 轴方向合法的点应该处的范围可以直接算出来,树状数组维护。

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int n, uu, vv, siz[100005], upp[100005], loo[100005], ans1, ans2, c[100005];
vector<int> vx[100005];
int lb(int x){
return x&-x;
}
void add(int pos, int val){
if(pos==0) c[0]+=val,pos=n+n;
for(int i=pos; i<=n; i+=lb(i)) c[i] += val;
}
int query(int pos){
int re=0;
for(int i=pos; i; i-=lb(i)) re += c[i];
return re+c[0];
}
bool check(int k){
int num=0, l, r;
for(int i=0; i<=n; i++) upp[i] = 0, loo[i] = siz[i], c[i]=0;
for(int i=1; i<=n; i++){
int qwqq=vx[i-1].size();
for(int j=0; j<qwqq; j++){
int t=vx[i-1][j];
bool isok=(upp[t]>=k)&&(loo[t]>=k);
upp[t]++;
if(!isok && upp[t]>=k && loo[t]>=k) add(t, 1);
}
qwqq=vx[i].size();
bool flag=qwqq>=2*k;
if(flag) l=vx[i][k-1]+1, r=vx[i][vx[i].size()-k]-1;
for(int j=0; j<qwqq; j++){
int t=vx[i][j];
bool isok=(upp[t]>=k)&&(loo[t]>=k);
loo[t]--;
if(isok && !(upp[t]>=k && loo[t]>=k)) add(t, -1);
if(isok && flag && t>=l && t<=r) num--;
}
if(!flag || l>r) continue;
num += query(r) - query(l-1);
}
if(!num) return false;
ans1 = k; ans2 = num;
return true;
}
int main(){
cin>>n;
for(int i=1; i<=n; i++){
scanf("%d %d", &uu, &vv);
vx[uu].push_back(vv);
siz[vv]++;
}
for(int i=0; i<=n; i++) sort(vx[i].begin(), vx[i].end());
int l=0, r=n, mid;
while(l<=r){
mid = (l + r) >> 1;
if(check(mid)) l = mid + 1;
else r = mid - 1;
}
cout<<ans1<<endl<<ans2<<endl;
return 0;
}

luogu3415 祭坛的更多相关文章

  1. BZOJ2934 : [Poi1999]祭坛问题

    对于每个祭坛,算出每条线段阻碍它的角度区间,然后排序求并看看是否有空位即可,时间复杂度$O(n^2\log n)$. 这题在Main上官方时限是0.2S,因此需要几个常数优化: $1.$为了避免用at ...

  2. luoguP3415 祭坛

    https://www.luogu.org/problemnew/show/P3415 考虑二分结界层数,将 n 个点按 x 大小依次加入答案,一行一行的做,用树状数组维护当前这一行中[0, x - ...

  3. luogu 3415 祭坛

    题目大意: 在平面上,有 n 个水晶柱,每个水晶柱可以用一个点表示 如果 4 个水晶柱依次相连可以构成一个四边形,满足其两条对角线分别平行于 x 轴和 y 轴,并且对角线的交点位于四边形内部(不包括边 ...

  4. Introduction to neural network —— 该“神经网络” 下拉“祭坛”

    Introduction to neural network 不能自欺欺人. 实干兴邦,空谈误国. -------------------------------------------------- ...

  5. 手机wifi密码的保存位置

    subjects:  adj. 受制于...的, 被统治的; n. 主题,学科, 国民 the subjects had to kneel down before the king. kneel -& ...

  6. 3563: DZY Loves Chinese - BZOJ

    Description神校XJ之学霸兮,Dzy皇考曰JC.摄提贞于孟陬兮,惟庚寅Dzy以降.纷Dzy既有此内美兮,又重之以修能.遂降临于OI界,欲以神力而凌♂辱众生. 今Dzy有一魞歄图,其上有N座祭 ...

  7. BZOJ 3569 DZY Loves Chinese II

    Description 神校XJ之学霸兮,Dzy皇考曰JC. 摄提贞于孟陬兮,惟庚寅Dzy以降. 纷Dzy既有此内美兮,又重之以修能. 遂降临于OI界,欲以神力而凌♂辱众生. 今Dzy有一魞歄图,其上 ...

  8. BZOJ 3563 DZY Loves Chinese

    Description 神校XJ之学霸兮,Dzy皇考曰JC. 摄提贞于孟陬兮,惟庚寅Dzy以降. 纷Dzy既有此内美兮,又重之以修能. 遂降临于OI界,欲以神力而凌♂辱众生. 今Dzy有一魞歄图,其上 ...

  9. html.ex.day02

    1.同一个目录内页面跳转 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http: ...

随机推荐

  1. AtCoder Regular Contest 083 E - Bichrome Tree

    题目传送门:https://arc083.contest.atcoder.jp/tasks/arc083_c 题目大意: 给定一棵树,你可以给这些点任意黑白染色,并且赋上权值,现给定一个序列\(X_i ...

  2. Minimal string CodeForces - 797C

    Minimal string CodeForces - 797C 题意:有一个字符串s和空串t和u,每次操作可以将s的第一个字符取出并删除然后放到t的最后,或者将t的最后一个字符取出并删除然后放到u的 ...

  3. 水题 Codeforces Round #299 (Div. 2) A. Tavas and Nafas

    题目传送门 /* 很简单的水题,晚上累了,刷刷水题开心一下:) */ #include <bits/stdc++.h> using namespace std; ][] = {" ...

  4. 数组Reduce的应用

    数组Reduce的应用 参考 简单应用 var arr = [1,2,3,4,5] var sum = arr.reduce(function (prev, cur, index, arr) { co ...

  5. 转 做了两款数据库监控工具(mysql and nosql),打算在近期开源

    http://www.cnblogs.com/leefreeman/p/7297549.html 监控指标:https://www.linuxidc.com/Linux/2015-08/122009. ...

  6. 牛客网Java刷题知识点之自动拆装箱

    不多说,直接上干货! https://www.nowcoder.com/ta/review-java/review?query=&asc=true&order=&page=5 ...

  7. A*算法、导航网格、路径点寻路对比(A-Star VS NavMesh VS WayPoint)

    在Unity3d中,我们一般常用的寻路算法:   1.A*算法插件   与贪婪算法不一样,贪婪算法适合动态规划,寻找局部最优解,不保证最优解.A*是静态网格中求解最短路最有效的方法.也是耗时的算法,不 ...

  8. AJPFX总结List的三个子类的特点

    ArrayList:                        底层数据结构是数组,查询快,增删慢.                        线程不安全,效率高.              ...

  9. CF779B(round 402 div.2 B) Weird Rounding

    题意: Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k. In the ...

  10. 【HEVC简介】Inter Prediction Tools

    参考文献:见<High Efficiency Video Coding (HEVC)>Inter-Picture Prediction in HEVC章节 <HEVC标准介绍.HEV ...