bzoj 3165: [Heoi2013]Segment 线段树
题目:
Description
要求在平面直角坐标系下维护两个操作:
- 在平面上加入一条线段。记第i条被插入的线段的标号为i。
- 给定一个数k,询问与直线 x = k相交的线段中,交点最靠上的线段的编号。
题解:
同[SDOI 2016]游戏
还要简单一些,就不写题解了.
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(ll &x){
x=0;char ch;bool flag = false;
while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
const ll maxn = 100010;
const ll maxp = 40010;
const double eps = 1e-9;
inline ll dcmp(double x){
return (x > eps) - (x < -eps);
}
struct Node{
double k,b;ll id;
bool vis;
Node(){id = 0;k = b = 0;}
}T[maxn<<2];
ll L,R,idx;double K,B;
inline void solve(ll rt,ll l,ll r){
if(T[rt].vis == false){
T[rt].k = K;T[rt].b = B;
T[rt].id = idx;
T[rt].vis = true;
return ;
}
double y0 = T[rt].k*l + T[rt].b;
double y1 = K*l + B;
double y2 = T[rt].k*r + T[rt].b;
double y3 = K*r + B;
if(dcmp(y1-y0) > 0 && dcmp(y3 - y2) > 0){
if(dcmp(K-T[rt].k) == 0 && dcmp(B - T[rt].b) == 0) return;
T[rt].k = K;T[rt].b = B;
T[rt].id = idx;
return ;
}
if(dcmp(y1-y0) <= 0 && dcmp(y3 - y2) <= 0) return ;
ll mid = l+r >> 1;
solve(rt<<1,l,mid);solve(rt<<1|1,mid+1,r);
}
inline void insert(ll rt,ll l,ll r){
if(L <= l && r <= R){
solve(rt,l,r);
return ;
}
ll mid = l+r >> 1;
if(L <= mid) insert(rt<<1,l,mid);
if(R > mid) insert(rt<<1|1,mid+1,r);
}
inline void insert(ll x0,ll x1,ll y0,ll y1,ll num){
L = x0;R = x1;K = (double)(y1-y0)/(double)(x1-x0);
B = y0 - x0*K;idx = num;insert(1,1,maxp);
}
typedef pair<ll,ll> pa;
double ans;ll ans_id;
inline void query(ll rt,ll l,ll r,ll pos){
double x = T[rt].k*pos + T[rt].b;
if(dcmp(x-ans) == 1 || (dcmp(x-ans) == 0 && T[rt].id < ans_id)) ans = x,ans_id = T[rt].id;
if(l == r) return ;
ll mid = l+r >> 1;
if(pos <= mid) query(rt<<1,l,mid,pos);
else query(rt<<1|1,mid+1,r,pos);
}
ll a[maxn],id[maxn];
int main(){
ll n;read(n);
ll lastans = 0;
ll op,x0,y0,x1,y1,x;
ll num = 0;
while(n--){
read(op);
if(op == 0){
read(x);
x = ((x +lastans-1)%39989+1);
ans = ans_id = 0;
query(1,1,maxp,x);
if(ans < a[x] || (ans == a[x] && id[x] < ans_id)) ans_id = id[x];
printf("%d\n",lastans = ans_id);
}else if(op == 1){
++ num;
read(x0);read(y0);read(x1);read(y1);
x0 = (x0+lastans-1)%39989+1;
y0 = (y0+lastans-1)%1000000000+1;
x1 = (x1+lastans-1)%39989+1;
y1 = (y1+lastans-1)%1000000000+1;
if(x0 > x1) swap(x0,x1),swap(y0,y1);
if(x0 == x1 ){
if(max(y0,y1) > a[x0]) a[x0] = max(y0,y1),id[x0] = num;
}else insert(x0,x1,y0,y1,num);
}
}
getchar();getchar();
return 0;
}
bzoj 3165: [Heoi2013]Segment 线段树的更多相关文章
- bzoj 3165: [Heoi2013]Segment 动态凸壳
3165: [Heoi2013]Segment Time Limit: 40 Sec Memory Limit: 256 MBSubmit: 202 Solved: 89[Submit][Stat ...
- BZOJ 3165: [Heoi2013]Segment
3165: [Heoi2013]Segment Time Limit: 40 Sec Memory Limit: 256 MBSubmit: 465 Solved: 187[Submit][Sta ...
- Bzoj 3165 [Heoi2013]Segment题解
3165: [Heoi2013]Segment Time Limit: 40 Sec Memory Limit: 256 MBSubmit: 668 Solved: 276[Submit][Sta ...
- BZOJ.3165.[HEOI2013]Segment(李超线段树)
BZOJ 洛谷 对于线段,依旧是存斜率即可. 表示精度误差一点都不需要管啊/托腮 就我一个人看成了mod(10^9+1)吗.. //4248kb 892ms #include <cstdio&g ...
- BZOJ_3165_[Heoi2013]Segment_线段树
BZOJ_3165_[Heoi2013]Segment_线段树 Description 要求在平面直角坐标系下维护两个操作: 1.在平面上加入一条线段.记第i条被插入的线段的标号为i. 2.给定一个数 ...
- Bzoj 2752 高速公路 (期望,线段树)
Bzoj 2752 高速公路 (期望,线段树) 题目链接 这道题显然求边,因为题目是一条链,所以直接采用把边编上号.看成序列即可 \(1\)与\(2\)号点的边连得是. 编号为\(1\)的点.查询的时 ...
- codeforces 22E XOR on Segment 线段树
题目链接: http://codeforces.com/problemset/problem/242/E E. XOR on Segment time limit per test 4 seconds ...
- BZOJ.3938.Robot(李超线段树)
BZOJ UOJ 以时间\(t\)为横坐标,位置\(p\)为纵坐标建坐标系,那每个机器人就是一条\(0\sim INF\)的折线. 用李超线段树维护最大最小值.对于折线分成若干条线段依次插入即可. 最 ...
- BZOJ.1558.[JSOI2009]等差数列(线段树 差分)
BZOJ 洛谷 首先可以把原序列\(A_i\)转化成差分序列\(B_i\)去做. 这样对于区间加一个等差数列\((l,r,a_0,d)\),就可以转化为\(B_{l-1}\)+=\(a_0\),\(B ...
随机推荐
- c#中关于compare比较的一点注意事项
一直没有太注意,今天发现在compare比较两个字符串的时候出了点小问题 如果我设置了两个字符串 一个是“2”,一个是“12” 那么在比较的时候 第一个会大于第二个: 如果第一个是“02”,第二个是“ ...
- 记录-阿里云Oss文件上传
public class OssUtil { /** * 上传图片 * @param file * @param request * @return */ public static Map<S ...
- 九度OJ 1182:统计单词 (计数)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3920 解决:1443 题目描述: 编一个程序,读入用户输入的,以"."结尾的一行文字,统计一共有多少个单词,并分别输出 ...
- iptables的用例
iptables书写思路顺序 1.协议 icmp 2.哪个功能和目标:过滤,拒绝 3.数据包流向:外到内 4.哪个链适合:越早越好,INPUT 5.源地址和目标地址 练习1.禁止某些主机或网络访问本机 ...
- spring配置中的classpath
1 classpath指WEB-INF下面的classes目录 2 配置成classpath*的话,spring会去所有的classpath中去找,包括lib下面的jar包 对于web app而言,c ...
- apache .htaccess实现301重定向
<IfModule mod_rewrite.c> Options +FollowSymlinks RewriteEngine On #301定向 RewriteCond %{HTTP_HO ...
- leetcode第一刷_Permutations
生成全排列的经典问题.递归方法的典范. bool visited[10000]; void getPermutation(vector<int> &num, vector<v ...
- eclilpse svn : Item is out of date 解决办法
尝试以下方面, 1. 2.如果上面的还不行,就说明你修改了原有项目结构,可能是增加了新包,或者重命名的包或文件,那么你得先update,然后再提交 这样就OK了,我就是用了2才成功的哦.
- Maven+SSM框架(Spring+SpringMVC+MyBatis) - Hello World(转发)
[JSP]Maven+SSM框架(Spring+SpringMVC+MyBatis) - Hello World 来源:http://blog.csdn.net/zhshulin/article/de ...
- Django——自定义分页(可调用)
1.view from django.shortcuts import render,HttpResponse # Create your views here. from app01.models ...