题面

题解

李超线段树

为了与机房大佬 HYJ 同步伐

学习笔记请移步 yyb的博客

Code

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
const int N = 100005;
const int mod = 39989;
#define val(id, x) (k[id] * x + b[id])
using namespace std; int Q, cnt, ans;
struct node
{
int id;
double k, b;
} t[N << 2];
double k[N], b[N]; template < typename T >
inline T read()
{
T x = 0, w = 1; char c = getchar();
while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * w;
} void pushtag(int p, int l, int r, int id)
{
if(!t[p].id) { t[p] = (node) { id, k[id], b[id] }; return; }
int now = t[p].id;
double l1 = val(now, l), r1 = val(now, r), l2 = val(id, l), r2 = val(id, r);
if(l2 <= l1 && r2 <= r1) return;
if(l1 < l2 && r1 < r2) { t[p] = (node) { id, k[id], b[id] }; return; }
int mid = (l + r) >> 1; double x = (b[id] - b[now]) / (k[now] - k[id]);
if(x <= mid)
{
if(l1 <= l2) pushtag(p << 1, l, mid, id);
else pushtag(p << 1, l, mid, now), t[p] = (node) { id, k[id], b[id] };
}
else
{
if(l1 <= l2) pushtag(p << 1 | 1, mid + 1, r, now), t[p] = (node) { id, k[id], b[id] };
else pushtag(p << 1 | 1, mid + 1, r, id);
}
} void modify(int p, int l, int r, int ql, int qr, int id)
{
if(ql <= l && r <= qr) { pushtag(p, l, r, id); return; }
int mid = (l + r) >> 1;
if(ql <= mid) modify(p << 1, l, mid, ql, qr, id);
if(mid < qr) modify(p << 1 | 1, mid + 1, r, ql, qr, id);
} void check(int &a, int c, int x)
{
double y0 = val(a, x), y1 = val(c, x);
if(y1 > y0 || (fabs(y1 - y0) < 1e-7 && a > c)) a = c;
} int query(int p, int l, int r, int x)
{
if(l == r) return t[p].id;
int mid = (l + r) >> 1, res = t[p].id;
if(x <= mid) check(res, query(p << 1, l, mid, x), x);
else check(res, query(p << 1 | 1, mid + 1, r, x), x);
return res;
} int main()
{
/* freopen("cpp.in", "r", stdin);
freopen("cpp.out", "w", stdout);
*/ Q = read <int> ();
int opt, x0, x1, y0, y1;
while(Q--)
{
opt = read <int> ();
if(!opt)
{
// printf("%d\n", x0);
x0 = read <int> (), x0 = ((x0 + ans - 1) % mod + 1);
printf("%d\n", ans = query(1, 1, mod, x0));
}
else
{
x0 = read <int> (), y0 = read <int> (), x1 = read <int> (), y1 = read <int> ();
x0 = ((x0 + ans - 1) % mod + 1), y0 = ((y0 + ans - 1) % 1000000000 + 1);
x1 = ((x1 + ans - 1) % mod + 1), y1 = ((y1 + ans - 1) % 1000000000 + 1);
if(x0 > x1) swap(x0, x1), swap(y0, y1);
// printf("%d %d\n", x0, x1);
k[++cnt] = 1.0 * (y1 - y0) / (x1 - x0), b[cnt] = 1.0 * y0 - k[cnt] * x0;
modify(1, 1, mod, x0, x1, cnt);
}
}
return 0;
}
/*
3
1 3 5 7 7
1 3 9 7 3
0 5
*/

[题解] [HEOI2013] Segment的更多相关文章

  1. Bzoj 3165 [Heoi2013]Segment题解

    3165: [Heoi2013]Segment Time Limit: 40 Sec  Memory Limit: 256 MBSubmit: 668  Solved: 276[Submit][Sta ...

  2. 【BZOJ3165】[HEOI2013]Segment(李超线段树)

    [BZOJ3165][HEOI2013]Segment(李超线段树) 题面 BZOJ 洛谷 题解 似乎还是模板题QwQ #include<iostream> #include<cst ...

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

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

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

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

  5. BZOJ 3165: [Heoi2013]Segment

    3165: [Heoi2013]Segment Time Limit: 40 Sec  Memory Limit: 256 MBSubmit: 465  Solved: 187[Submit][Sta ...

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

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

  7. BZOJ3165 & 洛谷4097:[HEOI2013]Segment——题解

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

  8. HEOI2013 Segment

    传说中的“李超树”. 大意:给你若干线段,试求横坐标x上的最上方一条线段的编号.无则输出零. 解:用线段树维护. 插入的时候保存自己这个区间上可能成为最大值的线段,被抛弃的则看情况下放. 查询时从最底 ...

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

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

随机推荐

  1. oracle学习笔记:字符串替换 replace、regexp_replace、translate函数

    1.replace 函数 语法:replace(char, search_string, replacement_string) --针对字符串替换 功能: ​ 将char中的字符串替换. ​ 当re ...

  2. vue中使用ts后,父组件获取执行子组件方法报错问题

    一.问题产生背景: 子组件的一个方法: update () { this.$nextTick(() => { this.ul_slots.forEach((ul, cur_slots_index ...

  3. windows找不到头文件的问题

    windows系统中,设置好了环境变量,就可以在cmd下直接执行文件,但是 特别是在c语言或者c++程序中,include头文件的问题,如果找不到,就考虑是不是文件放错地方了. windows上编译c ...

  4. #LOF算法

    a.每个数据点,计算它与其他点的距离 b.找到它的K近邻,计算LOF得分 clf=LocalOutlierFactor(n_neighbors=20,algorithm='auto',contamin ...

  5. drunk_admin_hacking_challenge靶机之旅?

    注:  只是记录本人玩的时候发现的新奇点  如果你也想玩且看了这篇文章还是不会,请联系gg 靶机下载地址 https://www.vulnhub.com/entry/drunk-admin-web-h ...

  6. jmeter连接mysql数据库批量插入数据

    前提工作: 1.在jmeter官网下载jmeter包(官网地址:https://jmeter.apache.org/).此外还需下载mysql驱动包,如:mysql-connector-java-5. ...

  7. Django应用之content type(app应用之一django.contrib.contenttypes)

    当一张表作为多个表的FK(主键),并且只能选择其中一个或者几个时,就可以使用content_type表:例如下图的数据关系,因此就可以使用content_type表来将表与表中的对象进行关联,从而做到 ...

  8. 《构建之法》——Alpha2项目的测试

    这个作业属于哪个课程 课程的链接 这个作业要求在哪里 作业要求的链接 团队名称 Runningman 这个作业的目标 测试其他组的项目,互相借鉴 作业正文 作业正文 测试人姓名 陈嘉莹 测试人学号 2 ...

  9. Please, commit your changes or stash them before you can merge. Aborting

    1.stash 通常遇到这个问题,你可以直接commit你的修改:但我这次不想这样. 看看git stash是如何做的. git stash    git pull    git stash pop ...

  10. JavaScript 页面渲染

    1. 从输入url到得到html的详细过程 1.1 加载资源的形式      输入 URL 或跳转页面 加载 html 1.2 加载一个资源的过程 浏览器根据DNS服务器得到域名的IP地址 向这个IP ...