[CERC2017]Buffalo Barricades
这个题目,扫描线+玄学**
大概操作就是用个扫描线从上往下扫。
博主有点懒,就直接贴代码了,但是我还是给大家贴个比较详细的博客,除了代码都可以看wym的博客,我基本上就是按wym大佬的思路来的,当然,我的代码里也加了点注释,大家也请凑合着看吧。
Ps:
ycz:STL什么辣鸡,跑这么慢,你看手写splay多么快
wym:STL有啥不好啦,代码量短,如果手写splay还要各种操作,STL多简洁明了啊
/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline int read(){
int x=0,f=1;char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
return x*f;
}
inline void print(int x){
if (x>=10) print(x/10);
putchar(x%10+'0');
}
const int N=3e5;
int Ans[N+10],last[N+10],cnt[N+10];
struct S1{
int x,y,t;
void join(int i){x=read(),y=read(),t=i;}
bool operator <(const S1 &a)const{return y!=a.y?y>a.y:x<a.x;}
}A[N*2+10];
struct S2{
//splay的维护需要按照x坐标为第一关键字,时间为第二关键字来维护
#define ls(x) tree[x][0]
#define rs(x) tree[x][1]
#define T(x) (rs(f[x])==x)
struct S3{
int x,t;
void clear(){x=t=0;}
void join(int a,int b){x=a,t=b;}
bool operator <(const S3 &a)const{return x!=a.x?x<a.x:t<a.t;}
}val[N*4+10],tmp;
int f[N*4+10],tree[N*4+10][2];
int root,len;
void clear(int x){ls(x)=rs(x)=f[x]=0,val[x].clear();}
void move(int x){
int fa=f[x],son=tree[x][T(x)^1];
tree[x][T(x)^1]=fa;
tree[fa][T(x)]=son;
if (son) f[son]=fa;
f[x]=f[fa];
if (f[x]) tree[f[x]][T(fa)]=x;
f[fa]=x;
}
void splay(int x){
while (f[x]){
if (f[f[x]]) T(x)==T(f[x])?move(f[x]):move(x);
move(x);
}
root=x;
}
void insert(int x,int t){
val[++len].join(x,t);
if (!root){
root=len;
return;
}
int i=root;
while (true){
if (val[len]<val[i]){
if (!ls(i)){f[ls(i)=len]=i;break;}
i=ls(i);
}else{
if (!rs(i)){f[rs(i)=len]=i;break;}
i=rs(i);
}
}
splay(len);
}
int get_pre(){
int x=ls(root);
while (rs(x)) x=rs(x);
return x;
}
int get_suc(){
int x=rs(root);
while (ls(x)) x=ls(x);
return x;
}
void Delete(int x){
splay(x);
if (!(ls(x)&&rs(x))){
f[root=ls(x)+rs(x)]=0;
clear(x);
return;
}
//删除必须找后继节点,这样才能保证根不变
int i=get_suc();
splay(i);
f[ls(i)=ls(x)]=i;
clear(x);
}
}Splay;
struct S4{
int f[N+10];
int find(int x){return f[x]?f[x]=find(f[x]):x;}
void merge(int x,int y){
x=find(x),y=find(y);
if (x!=y) f[x]=y,cnt[y]+=cnt[x];
//merge有顺序
}
}F;
int main(){
int n=read();
for (int i=1;i<=n;i++){
A[i].join(0);
(A[i].x<<=1)--;
(A[i].y<<=1)--;
}
int m=read();
for (int i=1;i<=m;i++){
A[i+n].join(i);
A[i+n].x<<=1;
A[i+n].y<<=1;
}
//消去0.5的影响,所以位移一位
sort(A+1,A+1+n+m);
for (int i=1;i<=n+m;i++){
Splay.insert(A[i].x,A[i].t);
//因为if语句里两个都要insert,虽然用处不同,但是我懒
if (A[i].t){
int suc=Splay.get_suc();
if (suc) last[A[i].t]=Splay.val[suc].t;
//记录右边的第一个时间比其大的点,方便并查集维护
while (true){
//保证根不变,一个个删掉前驱节点,类似于单调栈
int pre=Splay.get_pre();
if (!pre||Splay.val[pre].t<A[i].t) break;
Splay.Delete(pre);
}
}else{
//insert之后才能找到其后继,但是这个点不能加进去,所以直接删掉
int T=Splay.get_suc();
Splay.Delete(Splay.root);
if (T) cnt[Splay.val[T].t]++;
//初步统计答案
}
}
for (int i=m;i;i--){
Ans[i]=cnt[F.find(i)];
if (last[i]) F.merge(i,last[i]);
//merge操作有顺序,如果说last[i]的时间大于i的时间,加不加没有任何影响,为了方便,都加
}
for (int i=1;i<=m;i++) printf("%d\n",Ans[i]);
return 0;
}
[CERC2017]Buffalo Barricades的更多相关文章
- 【做题】CERC2017B. Buffalo Barricades——时间倒流
原文链接 https://www.cnblogs.com/cly-none/p/CERC2017B.html 题意:在一个网格平面上,有\(n\)个点,其中第\(i\)个点在以\((x_i, y_i) ...
- 2017-2018 ACM-ICPC, Central Europe Regional Contest (CERC 17)
A. Assignment Algorithm 按题意模拟即可. #include<stdio.h> #include<iostream> #include<string ...
- 2017 CERC
2017 CERC Problem A:Assignment Algorithm 题目描述:按照规则安排在飞机上的座位. solution 模拟. 时间复杂度:\(O(nm)\) Problem B: ...
- Buffalo最佳实践
本文将介绍Buffalo AJAX的两种配置的最佳实践,这个AJAX框架还是中国大师开发的,用起来估计是最方便.最简单的一个 准备工作:官网下载buffalo-2.0-bin,也可以下载buffalo ...
- 史上最全面的Buffalo WHR-G300N CH v2 刷OpenWrt教程
Buffalo WHR-G300N CH v2 刷OpenWrt.有两种办法.一种是Windows下刷.一种是在linux下使用tftp刷.Buffalo WHR-G300N-CH v2的openwr ...
- [CERC2017]Intrinsic Interval——扫描线+转化思想+线段树
[CERC2017]Intrinsic Interval https://www.luogu.org/blog/ywycasm/solution-p4747# 这种“好的区间”,见得还是比较多的了. ...
- [BZOJ5197] [CERC2017]Gambling Guide
[BZOJ5197] [CERC2017]Gambling Guide 题目链接 https://www.lydsy.com/JudgeOnline/problem.php?id=5197 Solut ...
- BZOJ5259/洛谷P4747: [Cerc2017]区间
BZOJ5259/洛谷P4747: [Cerc2017]区间 2019.8.5 [HZOI]NOIP模拟测试13 C.优美序列 思维好题,然而当成NOIP模拟题↑真的好吗... 洛谷和BZOJ都有,就 ...
- [Buffalo]ASP.NET MVC路由映射
Asp.Net的路由系统旨在通过注册URl模版与物理文件之间的映射进而实现请求地址与文件路径之间的分离,但对于Asp.Net Mvc应用来说,请求的目标却是定义在某个Controller类型中的Act ...
随机推荐
- Eclipse移植项目时JDK版本不匹配Project facet Java version 1.7 is not supported
Eclipse移植项目时JDK版本不匹配Project facet Java version 1.7 is not supported 如果原有项目用的为JDK1.7,而自己的是低版本JDK,比如1. ...
- SAS学习笔记 - R的数据操作
1.对象 1.1 对象及其内在属性 R中的处理数据就是对象,每个对象可以包含多个元素.对象有两个内在属性:类型和长度.类型是对象元素的基本种类,共四种:数值型,字符型,复数型和逻辑型.对象的类型和长度 ...
- 解决Coldfusion连接MySQL数据库的问题
在连接MySQL时,出现了如下错误: Connections to MySQL Community Server are not supported. Please contact MySQL to ...
- 【深入探索c++对象模型】data语义学二
单一继承中,base class 和derived class的对象都是从相同的地址开始,其间差异只在于derived class比较大,用以容纳自己的nonstatic members. 若vptr ...
- No module named '_sqlite3'问题解决
Centos自带的python版本是2.7的,后面我自己装了3.5版本的,在创建应用的时候python manager.py startapp users 时,就会报No module named ' ...
- 什么是WPF? 秒懂 !
一開始听到WPF.认为非常陌生.在百度百科等地方看完简单介绍之后.感觉更深奥.各种不懂啊! 在简单做了几个页面之后,发现.原来如此! So Easy 但又So Magic. 为什么说它简单?由于它简直 ...
- 九度OJ1004 Median
题目描写叙述: Given an increasing sequence S of N integers, the median is the number at the middle positio ...
- 最简单实用的MongoDB安装教程:在CentOS中使用 yum 安装MongoDB及服务器端配置详解
一.准备工作: 运行yum命令查看MongoDB的包信息 [root@vm ~]# yum info mongo-10gen (提示没有相关匹配的信息,) 说明你的centos系统中的yum源不包含M ...
- 《modern operating system》 chapter 6 DEADLOCKS 笔记
DEADLOCKS Both processes are blocked and will remain so forever. This situation is called a deadlock ...
- 《coredump问题原理探究》Linux x86版7.9节list相关的iterator对象
这一节.看一下list的iterator对象在内存的布局 1 #include <list> 2 3 void init( std::list<int>& lst ) ...