惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
爱范儿
爱范儿
人人都是产品经理
人人都是产品经理
博客园 - 司徒正美
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
量子位
罗磊的独立博客
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
小众软件
小众软件
C
Cybersecurity and Infrastructure Security Agency CISA
Cyberwarzone
Cyberwarzone
大猫的无限游戏
大猫的无限游戏
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
雷峰网
雷峰网
Simon Willison's Weblog
Simon Willison's Weblog
The Cloudflare Blog
博客园 - 三生石上(FineUI控件)
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cyber Attacks, Cyber Crime and Cyber Security
博客园_首页
博客园 - 叶小钗
V
Vulnerabilities – Threatpost
T
The Exploit Database - CXSecurity.com
T
Tailwind CSS Blog
IT之家
IT之家
博客园 - 聂微东
Spread Privacy
Spread Privacy
V2EX - 技术
V2EX - 技术
S
Security Affairs
宝玉的分享
宝玉的分享
V
V2EX
C
Cisco Blogs
博客园 - Franky
美团技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
月光博客
月光博客
S
Securelist
J
Java Code Geeks
Webroot Blog
Webroot Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
L
LINUX DO - 热门话题
NISL@THU
NISL@THU
WordPress大学
WordPress大学
W
WeLiveSecurity
T
Threatpost
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
腾讯CDC
阮一峰的网络日志
阮一峰的网络日志

某岛

AtCoder Beginner Contest 409 Luogu P5325. 【模板】Min_25 筛 UOJ #188. 【UR #13】Sanrd AtCoder Beginner Contest 371 AtCoder Beginner Contest 369 RPGMaker 2k3 百科 OneShot 的考古 2024“开创拓芯”游戏创享节的相关记录 CJ 回来后的戒断反应 Luogu P10221. [省选联考 2024] 重塑时光 Luogu P5308 [COCI2018-2019#4] Akvizna wqs 二分 歌唱王国 Lean 相关 BZOJ 3153. Sone1 The 2023 ICPC World Finals Luxor 新巴别塔 Sora 的想象与思考 Facebook Hacker Cup 2023 Round 1 AtCoder Beginner Contest 322 LLaMA 2 相关 HuggingFace AI Game Jam ACL 2023 Trans 相关… Luogu P2053. [SCOI2007] 修车 Luogu P1973. [NOI2011] NOI 嘉年华 Luogu P1933. [NOI2010] 旅行路线 Luogu P1954. [NOI2010] 航空管制 Luogu P2048. [NOI2010] 超级钢琴 Luogu P2046. [NOI2010] 海拔 Luogu P3227. [HNOI2013] 切糕 Luogu P8500. [NOI2022] 冒泡排序 Luogu P3629. [APIO2010] 巡逻 USACO 2018 February Contest, Gold Problem 2. Directory Traversal Luogu P3647. [APIO2014] 连珠线 IZhO 2017. Problem F. Hard route SPOJ TWOPATHS. Two Paths 换根 dp 洪恩电脑 —— 开天辟地 Facebook Hacker Cup 2022 Round 2 Codeforces Round #875 Luogu P5828 边双连通图计数 EC Final 拉格朗日反演定理 Luogu P5827. 点双连通图计数 无标号连通图 AtCoder Beginner Contest 284 Luogu P4708. 画画 Luogu P6295. 有标号 DAG 计数 BZOJ #2863. 愤怒的元首 HDU 3303. Harmony Forever 聊聊《明日方舟 Side Story 孤星》与《崩坏:星穹铁道》 SGU 208. Toral Tickets 后日谈,SHLUG 月度分享(上) 钢琴练习 EasyRPG x ChatGPT ControlNet 相关 The 1st Universal Cup, Stage 4, Ukraine EasyRPG —— Sliding Puzzle The 1st Universal Cup, Stage 3, Poland DP 优化练习 NOI 2009 TypeDB Forces 2023 Nas 买来做什么… Global Game Jam 2023 参赛纪录 The 1st Universal Cup, Stage 2, Hongkong The 1st Universal Cup, Stage 0, Nanjing Codeforces Round #850 舟游同人游戏 RM2k3 机能增强 —— EasyRPG Player 魔改版 《海之歌》设定与剧本 dfs 序求 lca Codeforces Round #844 P3768 简单的数学题 AtCoder Beginner Contest 281 ChatGPT 相关 AtCoder Grand Contest 059 AtCoder Beginner Contest 280 Codeforces Global Round 24 事实核查,以乌鲁木齐火灾为例 SPOJ MUSKET. Musketeers Pinely Round 1 Note about FTX Permutation ICPC World Final 2021 CodeTON Round 3 Codeforces Round #831 Educational Codeforces Round 138 NovelAI 法术指南 卡农 Educational Codeforces Round 135 Codeforces Round #819 瓦喵之夏 NOI 2022 Luogu P3765 总统选举 Luogu P3369 【模板】普通平衡树 网络国家 旋转卡壳 OFAC Sanctions && Tornado Cash BZOJ 1185. [HNOI2007]最小矩形覆盖
BZOJ 3165. [Heoi2013]Segment
2021-09-12 · via 某岛

记一下模板的写法。。。

做法一:李超树
https://github.com/lychees/ACM-Training/tree/master/Archive/BZOJ/3165.%20%5BHeoi2013%5DSegment

做法二:线段树套平衡树

因为李超树的大流行,树套树反而没人再去写了。。。

const int N = int(1e5) + 9;

#define ll double
struct Line {
	mutable ll k, b, p; int id;
	Line (ll k = 0, ll b = 0, int id = 0):k(k),b(b),id(id) {
	    p = 0;
	}
	ll y(ll x) const {return k*x + b;}
	bool operator<(const Line& o) const { return k < o.k; }
	bool operator<(ll x) const { return p < x; }
};

struct LineContainer : multiset<Line,less<>> {
	const ll inf = 1/.0;
	ll div(ll a, ll b) {
		return a / b;
    }
	bool isect(iterator x, iterator y) {
		if (y == end()) return x->p = inf, 0;
		if (x->k == y->k) x->p = x->b > y->b ? inf : -inf;
		else x->p = div(y->b - x->b, x->k - y->k);
		return x->p >= y->p;
	}
	void add(ll k, ll b, int i) {
		add(Line(k,b,i));
	}
	void add(Line t) {
		auto z = insert(t), y = z++, x = y;
		while (isect(y, z)) z = erase(z);
		if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
		while ((y = x) != begin() && (--x)->p >= y->p)
			isect(x, erase(y));
	}

	pair<ll, int> query(ll x) {
		assert(!empty());
		auto& l = *lower_bound(x);
		return {l.y(x), l.id};
	}
} H;
map<int, pair<ll,int> > M;


namespace Segtree {
    const int NN = 4 * N;
    LineContainer T[NN];
#define lx (x<<1)
#define rx (lx|1)
#define ml ((l+r)>>1)
#define mr (ml+1)
#define lc lx, l, ml
#define rc rx, mr, r
#define rt 1,1,39989
    void Insert(int x, int l, int r, int a, int b, Line L) {
        if (b < l || r < a) return;
        if (a <= l && r <= b) {
            T[x].add(L);
        } else {
            Insert(lc, a, b, L);
            Insert(rc, a, b, L);
        }
    }
    void Query(int x, int l, int r, int p, vector<LineContainer*>& L) {
        if (p < l || r < p) return;
        if (l <= p && p <= r) {
            if (!T[x].empty()) L.PB(&T[x]);
        }
        if (l != r) {
            Query(lc, p, L);
            Query(rc, p, L);
        }
    }
}

vector<LineContainer*> L;

int main(){

#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#endif

    int id = 0; Rush {
        LL x0, y0, x1, y1;
        if (RD()) {
            RD(x0, y0, x1, y1);
            x0 = (x0 + last_ans - 1) % 39989 + 1;
            x1 = (x1 + last_ans - 1) % 39989 + 1;
            y0 = (y0 + last_ans - 1) % int(1e9) + 1;
            y1 = (y1 + last_ans - 1) % int(1e9) + 1;
            if (x0 > x1) {
                swap(x0, x1);
                swap(y0, y1);
            }
            if (x0 == x1) {
                auto t = pair<ll, int>(max(y0, y1), ++id);
                if (CTN(M, x0))  {
                    M[x0] = t;
                } else {
                    checkMax(M[x0], t);
                }
            } else {
                DB k = (DB)(y1-y0)/(x1-x0);
                DB b = y0 - k*x0;
                Segtree::Insert(rt, x0, x1, Line(k, b, ++id));
            }
        } else {
            RD(x0);
            x0 = (x0 + last_ans - 1) % 39989 + 1;
            pair<ll, int> z = {-OO, 0}; L.clear(); Segtree::Query(rt, x0, L);
            for (auto& l: L) checkMax(z, l->query(x0));
            if (CTN(M, x0)) checkMax(z, M[x0]);
            OT(z.se);
        }
    }
}

Posted by xiaodao
Category: 日常