传送门

简单来说就是对于每条线段,先把它拆成\(O(logn)\)条,然后对于每一条再\(O(logn)\)判断在所有子区间的优劣程度

//minamoto
#include<bits/stdc++.h>
#define R register int
#define ls (p<<1)
#define rs (p<<1|1)
#define fp(i,a,b) for(R i=a,I=b+1;i<I;++i)
#define fd(i,a,b) for(R i=a,I=b-1;i>I;--i)
#define go(u) for(R i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
inline int max(const R&x,const R&y){return x>y?x:y;}
inline int min(const R&x,const R&y){return x<y?x:y;}
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
R res,f=1;char ch;
while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
return res*f;
}
char sr[1<<21],z[20];int C=-1,Z=0;
inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(R x){
if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;
while(z[++Z]=x%10+48,x/=10);
while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
const int N=1e5+5;
struct node{
int l,r,id;
double yl,yr;
node(int x1=0,int y1=0,int x2=0,int y2=0,int i=0){
l=x1,r=x2;yl=y1,yr=y2;id=i;
if (l==r) yl=yr=max(yl,yr);
}
double get(int x){return l==r?yl:yl+(k()*(x-l));}
double k(){return (yr-yl)/(r-l);}
void lm(int x){yl=get(x);l=x;}
void rm(int x){yr=get(x);r=x;}
};
bool cmp(node a,node b,int x){
return a.get(x)==b.get(x)?a.id<b.id:a.get(x)>b.get(x);
}
struct TR{
node tr[N<<2];
void build(int p,int l,int r){
tr[p].l=l,tr[p].r=r;if(l==r)return;
R mid=(l+r)>>1;
build(ls,l,mid),build(rs,mid+1,r);
}
node query(int p,int l,int r,int x){
if(l==r)return tr[p];node res;R mid=(l+r)>>1;
res=(x<=mid)?query(ls,l,mid,x):query(rs,mid+1,r,x);
return cmp(res,tr[p],x)?res:tr[p];
}
void update(int p,int l,int r,node x){
if(tr[p].l>x.l)x.lm(tr[p].l);
if(tr[p].r<x.r)x.rm(tr[p].r);
R mid=(l+r)>>1;
if(cmp(x,tr[p],mid))swap(tr[p],x);
if(l==r||min(tr[p].yl,tr[p].yr)>=max(x.yl,x.yr))return;
tr[p].k()<=x.k()?update(rs,mid+1,r,x):update(ls,l,mid,x);
}
void insert(int p,int l,int r,node x){
if(x.l>r||x.r<l)return;
if(tr[p].l>x.l)x.lm(tr[p].l);if(tr[p].r<x.r)x.rm(tr[p].r);
if(l==x.l&&r==x.r)return (void)(update(p,l,r,x));
if(l==r)return;R mid=(l+r)>>1;
insert(ls,l,mid,x),insert(rs,mid+1,r,x);
}
}T;
int lastans,cnt,n=39989,lim=1e9,m,op,k,x,y,xx,yy;node res;
int main(){
// freopen("testdata.in","r",stdin);
T.build(1,1,n);m=read();
while(m--){
op=read();
if(!op){
k=read(),k=(k+lastans-1)%n+1;
lastans=T.query(1,1,n,k).id;
print(lastans);
}else{
x=read(),y=read(),xx=read(),yy=read();
x=(x+lastans-1)%n+1,xx=(xx+lastans-1)%n+1;
y=(y+lastans-1)%lim+1,yy=(yy+lastans-1)%lim+1;
if(x>xx)swap(x,xx),swap(y,yy);
res=node(x,y,xx,yy,++cnt),T.insert(1,1,n,res);
}
}return Ot(),0;
}

P4097 [HEOI2013]Segment的更多相关文章

  1. 洛谷 P4097 [HEOI2013]Segment 解题报告

    P4097 [HEOI2013]Segment 题目描述 要求在平面直角坐标系下维护两个操作: 在平面上加入一条线段.记第 \(i\) 条被插入的线段的标号为 \(i\) 给定一个数 \(k\),询问 ...

  2. P4097 [HEOI2013]Segment(李超树)

    链接 https://www.luogu.org/problemnew/show/P4097 https://www.lydsy.com/JudgeOnline/problem.php?id=3165 ...

  3. 【题解】Luogu P4097 [HEOI2013]Segment

    原题传送门 这珂以说是李超线段树的模板题 按着题意写就行了,时间复杂度为\(O(n\log^2n)\) #include <bits/stdc++.h> #define N 40005 # ...

  4. Luogu P4097 [HEOI2013]Segment 李超线段树

    题目链接 \(Click\) \(Here\) 李超线段树的模板.但是因为我实在太\(Naive\)了,想象不到实现方法. 看代码就能懂的东西,放在这里用于复习. #include <bits/ ...

  5. 2018.07.23 洛谷P4097 [HEOI2013]Segment(李超线段树)

    传送门 给出一个二维平面,给出若干根线段,求出x" role="presentation" style="position: relative;"&g ...

  6. 洛谷P4097 [HEOI2013]Segment(李超线段树)

    题面 传送门 题解 调得咱自闭了-- 不难发现这就是个李超线段树,不过因为这里加入的是线段而不是直线,所以得把线段在线段树上对应区间内拆开之后再执行李超线段树的操作,那么复杂度就是\(O(n\log^ ...

  7. P4097 [HEOI2013]Segment 李超线段树

    $ \color{#0066ff}{ 题目描述 }$ 要求在平面直角坐标系下维护两个操作: 在平面上加入一条线段.记第 i 条被插入的线段的标号为 i 给定一个数 k,询问与直线 x = k 相交的线 ...

  8. [洛谷P4097] [HEOI2013] Segment

    Description 要求在平面直角坐标系下维护两个操作: 1.在平面上加入一条线段.记第 \(i\) 条被插入的线段的标号为 \(i\) 2.给定一个数 \(k\) ,询问与直线 \(x = k\ ...

  9. bzoj 3165: [Heoi2013]Segment 动态凸壳

    3165: [Heoi2013]Segment Time Limit: 40 Sec  Memory Limit: 256 MBSubmit: 202  Solved: 89[Submit][Stat ...

随机推荐

  1. Leetcode 218.天际线问题

    天际线问题 城市的天际线是从远处观看该城市中所有建筑物形成的轮廓的外部轮廓.现在,假设您获得了城市风光照片(图A)上显示的所有建筑物的位置和高度,请编写一个程序以输出由这些建筑物形成的天际线(图B). ...

  2. Codeforces Round #352 (Div. 2),A题与B题题解代码,水过~~

    ->点击<- A. Summer Camp time limit per test 1 second memory limit per test 256 megabytes input s ...

  3. HDU 4803 贪心

    尽可能的让当前的平均值接近最后的平均值才能最快达到终点的情况 #include <cstdio> #include <cstring> #include <iostrea ...

  4. hdu 4771好题

    #include<stdio.h> #include<string.h>//通过只记录每一步此时点的状态.题非常好 #include<queue> using na ...

  5. Linux find常用命令

    今天研究一下find的一些常用的命令. find格式:find filepath [-option] [-print|-exec|-ok...] 其中常用的option主要有 -type d|f|s| ...

  6. BZOJ2272: [Usaco2011 Feb]Cowlphabet 奶牛文字

    n<=250个大写字母和m<=250个小写字母,给p<=200个合法相邻字母,求用这些合法相邻字母的规则和n+m个字母能合成多少合法串,答案mod 97654321. 什么鬼膜数.. ...

  7. JVM定位程序假死或cpu占用高的线程

    linux系统: 参考:https://blog.csdn.net/qq_40197576/article/details/80287515 1>使用top命令查看占用cpu进程情况,得到jav ...

  8. commons-lang常用工具类StringEscapeUtils

    原文:https://my.oschina.net/mousai/blog/88832 在apache commons-lang(2.3以上版本)中为我们提供了一个方便做转义的工具类,主要是为了防止s ...

  9. 关于python内存管理里的引用计数算法和标记-清楚算法的讨论

    先记录于此,后续有时间再深究吧: 1.https://www.zhihu.com/question/33529443 2.http://patshaughnessy.net/2013/10/30/ge ...

  10. Linux学习系列之Inotify+Rsync实现实时数据同步

    Inotify简介 inotify介绍 inotify是一种强大的.异步的文件系统监控机制,linux内核从2.6.13起,加入了inotify的支持,通过inotify可以监控文件系统中添加.删除. ...