2018.10.29 bzoj3718: [PA2014]Parking(树状数组)
传送门
显然只用判断两个会相交的车会不会卡住就行了。
直接树状数组维护后缀最大值就行了。
代码:
#include<bits/stdc++.h>
using namespace std;
const int N=5e4+5;
struct Matrix{int x1,x2,w,id;}a1[N],a2[N];
int n,T,W,pos[N],bit[N];
inline int lowbit(int x){return x&-x;}
inline void update(int x,int v){for(int i=x;i;i-=lowbit(i))bit[i]=max(bit[i],v);}
inline int query(int x){int ret=0;for(int i=x;i<=n;i+=lowbit(i))ret=max(ret,bit[i]);return ret;}
inline bool cmp(const Matrix&a,const Matrix&b){return a.x1==b.x1?a.x2<b.x2:a.x1<b.x1;}
const int RLEN=1<<18;
inline char nc() {
static char ibuf[RLEN],*ib,*ob;
(ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ib==ob) ? -1 : *ib++;
}
inline int read() {
char ch=nc(); int i=0,f=1;
while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
while(isdigit(ch)) {i=(i<<1)+(i<<3)+(ch^48); ch=nc();}
return i*f;
}
int main(){
T=read();
while(T--){
n=read(),W=read();
for(int i=1,y1,y2;i<=n;++i){
a1[i].x1=read(),y1=read(),a1[i].x2=read(),y2=read(),a1[i].id=i;
if(a1[i].x1>a1[i].x2)swap(a1[i].x1,a1[i].x2);
a1[i].w=abs(y1-y2);
}
for(int i=1,y1,y2;i<=n;++i){
a2[i].x1=read(),y1=read(),a2[i].x2=read(),y2=read(),a2[i].id=i;
if(a2[i].x1>a2[i].x2)swap(a2[i].x1,a2[i].x2);
a2[i].w=abs(y1-y2);
}
bool f=1;
sort(a1+1,a1+n+1,cmp),sort(a2+1,a2+n+1,cmp);
for(int i=1;i<=n;++i)pos[a1[i].id]=i;
for(int i=1;i<=n;++i){
if(query(pos[a2[i].id])+a2[i].w>W){f=false;break;}
update(pos[a2[i].id],a2[i].w);
}
fill(bit+1,bit+n+1,0),puts(f?"TAK":"NIE");
}
return 0;
}
2018.10.29 bzoj3718: [PA2014]Parking(树状数组)的更多相关文章
- BZOJ3718[PA2014]Parking——树状数组
题目描述 你的老板命令你将停车场里的车移动成他想要的样子.停车场是一个长条矩形,宽度为w.我们以其左下角顶点为原点,坐标轴平行于矩形的边,建立直角坐标系.停车场很长,我们可以认为它一直向右边伸展到无穷 ...
- CF Educational Codeforces Round 10 D. Nested Segments 离散化+树状数组
题目链接:http://codeforces.com/problemset/problem/652/D 大意:给若干个线段,保证线段端点不重合,问每个线段内部包含了多少个线段. 方法是对所有线段的端点 ...
- Educational Codeforces Round 10 D. Nested Segments 离线树状数组 离散化
D. Nested Segments 题目连接: http://www.codeforces.com/contest/652/problem/D Description You are given n ...
- Educational Codeforces Round 10 D. Nested Segments 【树状数组区间更新 + 离散化 + stl】
任意门:http://codeforces.com/contest/652/problem/D D. Nested Segments time limit per test 2 seconds mem ...
- 6398. 【NOIP2018模拟10.30】Generator(树状数组区间修改)
题目描述 Description Input Output 输出 q 行,第 i 行表示数据 Di 的答案. Sample Input 4 3 2 1 1 2 4 2 1 2 1 1 3 5 2 2 ...
- 2018牛客网暑假ACM多校训练赛(第五场)H subseq 树状数组
原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-2018-Summer-Round5-H.html 题目传送门 - https://www.no ...
- DNA Evolution CodeForces - 828E(树状数组)
题中有两种操作,第一种把某个位置的字母修改,第二种操作查询与[L, R]内与给出字符串循环起来以后对应位置的字母相同的个数.给出的字符串最大长度是10. 用一个四维树状数组表示 cnt[ATCG的编号 ...
- Libre OJ 130、131、132 (树状数组 单点修改、区间查询 -> 区间修改,单点查询 -> 区间修改,区间查询)
这三题均可以用树状数组.分块或线段树来做 #130. 树状数组 1 :单点修改,区间查询 题目链接:https://loj.ac/problem/130 题目描述 这是一道模板题. 给定数列 a[1] ...
- P3368 【模板】树状数组 2 单点查询与区间修改
题目描述 如题,已知一个数列,你需要进行下面两种操作: 1.将某区间每一个数数加上x 2.求出某一个数的和 输入输出格式 输入格式: 第一行包含两个整数N.M,分别表示该数列数字的个数和操作的总个数. ...
随机推荐
- JS中取得<asp:TextBox中的值
var s = document.getElementById("<%=txt_DaShen.ClientID %>").value; 注:txt_DaShen 为as ...
- Jasper打印示例
import java.io.IOException;import java.util.ArrayList;import java.util.HashMap;import java.util.List ...
- Codeforces Beta Round #57 (Div. 2)
Codeforces Beta Round #57 (Div. 2) http://codeforces.com/contest/61 A #include<bits/stdc++.h> ...
- ASP.Net MVC 中EF实体的属性取消映射数据库、自定义名称
例如:数据库中一个字段名称为CompanyId 自定义实体数据名称 [Column("CompanyId")] public int Id{ get; set; } 这样就可以使用 ...
- JavaScript各种继承方式(二):借用构造函数继承(constructor stealing)
一 原理 在子类的构造函数中,通过call ( ) 或 apply ( ) 的形式,调用父类的构造函数来实现继承. function Fruit(name){ this.name = name; th ...
- vue-app项目,将px自动转化为rem
1. 安装lib-flexible: npm install --save lib-flexible 2.安装postcss-loader和postcss-px2rem: npm install -- ...
- jQuery和js使用点滴
1.checkbox全选按钮 <input type="checkbox" name="allcheck" id="allcheck" ...
- 当前的开源SLAM方案
开源方案 传感器形式 地址链接 MonoSLAM 单目 https://github.com/hanmekim/SceneLib2 PTAM 单目 http://www.robots.ox.ac. ...
- opencv 3.2 vs2015 debug assertion __acrt_first_block == header
网上复制了一个转直方图的代码 ,说来也奇怪, 用imshow 显示 图片在独立窗体内,不存在问题, 要注释掉这段代码就出现了下边的错误. 网上查了查,原来是程序中 有个std::vector<c ...
- 关于ip包长度
http://blog.csdn.net/naturebe/article/details/6712153 这篇文章总结的不错,转自:http://hi.baidu.com/to_wait/blog/ ...