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,分别表示该数列数字的个数和操作的总个数. ...
随机推荐
- http://ctf.bugku.com/challenges#Timer(%E9%98%BF%E9%87%8CCTF):Bugku——Timer(阿里CTF)
做了第一个android apk逆向题,很多工具啥的还没用过,再接再厉. 找到方法发现这个apk支持的SDK API是15-17,于是就下载了API 16并制作了模拟器,但发现还是运行不起来, ...
- ES3之变量提升 ( hoisting )
JavaScript引擎在预编译时,会将声明(函数声明.变量声明)自动提升至函数或全局代码的顶部.但是赋值不会提升. Because variable declarations (and declar ...
- Householder矩阵,Givens矩阵
householder 矩阵相当于对某一空间中的元素(向量.矩阵)进行镜像变换,但是模值并不发生变化. H=I-2uuT householder矩阵有几个重要的性质: 1 : H-1 = H 2: ...
- HDU 6315 Naive Operations(线段树区间整除区间)
Problem DescriptionIn a galaxy far, far away, there are two integer sequence a and b of length n.b i ...
- django序列化单表的4种方法的介绍
这里主要是讲序列化单表的几种方法 先看下models中设计的表结构 from django.db import models # Create your models here. class Book ...
- Exceptions
[定义] error: external, like out of memory exception: internal, like file not found 父类都是throwable 逻辑有错 ...
- 鼠标移上去触动hover致使div向上移动几个相素(动画transition轻轻的移动)
- for all entries
1.必须要判断for all entries in后面的内表是否为空,如果为空,where条件中与内表中字段进行比较的结果全部为真,会导致取出非常多的数据,影响系统性能.2.使用for all ent ...
- Union and Intersection of two sorted lists 并集和交集
跟面试官确认是arrayList还是singly-linked list /* Union 并集:两个升序的list a, b, 返回其并集(升序排序)*/ public class UnionTw ...
- wheelView实现滚动选择 三方开源的封装控件 spannableString autofitTextView、PinnedSectionListView SwipeListView等等
wheelView多用于popupwindow用来滚动选择条目 github上的开源三方控件 spannableString autofitTextView.PinnedSectionLi ...