BZOJ5223: [Lydsy2017省队十连测]有理有据题(KD树)

这篇博客介绍了BZOJ5223题目,重点讲解了如何利用KD树进行矩阵操作,包括加1、赋0和查询历史最大值。解题过程中提到了时间复杂度为O((m+A)n+Clogn+qn),但代码实现中常数项未优化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

传送门

题解:
KD树支持矩阵加1,矩阵赋0,查询历史最大值。

时间复杂度 O ( ( m + A ) n + C log ⁡ n + q n ) O((m+A)\sqrt{n} + C \log n + qn) O((m+A)n +Clogn+qn)

代码标记用了二元组,没把常数压下去。。

#include <bits/stdc++.h>
using namespace std;

const int RLEN=1<<18|1;
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 rd() {
    
    
	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-'0'; ch=nc();}
	return i*f;
}
inline void W(int x) {
    
    
	static int buf[50];
	if(!x) {
    
    putchar('0'); return;}
	if(x<0) {
    
    putchar('-'); x=-x;}
	while(x) {
    
    buf[++buf[0]]=x%10; x/=10;}
	while(buf[0]) {
    
    putchar(buf[buf[0]--]+'0');}
}

const int N=5e4+50, INF=0x3f3f3f3f;
int n,m,q,tot;
inline int Max(int x,int y) {
    
    return (x>y) ? x : y;}
inline int Min(int x,int y) {
    
    return (x<y) 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值