LA 3938 线段树(区间合并)

WHY-Us框架:提升大模型输出一致性的提示工程新范式 大语言模型(LLM)提示工程正从‘指令式编写’迈向‘人机协作设计’,核心挑战在于结果漂移与交付不稳定。WHY-Us框架通过前置定义任务价值(Why)与人机角色契约(Us),为模型建立认知锚点,显著提升高影响力输出的一致性与可复现性。其原理基于LLM的推理依赖显式上下文约束,而非隐含理解;技术价值体现在降低迭代轮次、统一术语逻辑、强化决策对齐;广泛适用于金融合规报告生成、医疗文书解释、智能座舱交互等需强稳定性与专业可信度的工程场景。WHY-Us不依赖新API,仅重构Prompt首句结构,是当前提示工程向协作协 阅读详情

After doing Ray a great favor to collect sticks for Ray, Poor Neal becomes very hungry. In return for Neal's help, Ray makes a great dinner for Neal. When it is time for dinner, Ray arranges all the dishes he makes in a single line (actually this line is very long ... , the dishes are represented by 1, 2, 3 ... ). ``You make me work hard and don't pay me! You refuse to teach me Latin Dance! Now it is time for you to serve me", Neal says to himself.

Every dish has its own value represented by an integer whose absolute value is less than 1,000,000,000. Before having dinner, Neal is wondering about the total value of the dishes he will eat. So he raises many questions about the values of dishes he would have.

For each question Neal asks, he will first write down an interval [a, b] (inclusive) to represent all the dishes a, a + 1,..., b , where a and b are positive integers, and then asks Ray which sequence of consecutive dishes in the interval has the most total value. Now Ray needs your help.

Input 

The input file contains multiple test cases. For each test case, there are two integers n and m in the first line (n, m < 500000) . n is the number of dishes and m is the number of questions Neal asks.

Then n numbers come in the second line, which are the values of the dishes from left to right. Next m lines are the questions and each line contains two numbers a , b as described above. Proceed to the end of the input file.

Output 

For each test case, output m lines. Each line contains two numbers, indicating the beginning position and end position of the sequence. If there are multiple solutions, output the one with the smallest beginning position. If there are still multiple solutions then, just output the one with the smallest end position. Please output the result as in the Sample Output.

Sample Input 

3 1 
1 2 3 
1 1

Sample Output 

Case 1: 
1 1
 
有bug。D了半天没搞出来、改天再来更改。
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define maxn 500080
#define lson id<<1,l,mid
#define rson id<<1|1,mid+1,r
#define lson id<<1,l,mid
#define rson id<<1|1,mid+1,r
#define LL long long int
LL key[maxn];
int s,t;
struct ST
{
	int l,r,a,b,left,right;
	LL maxsum,sum,lsum,rsum;
}st[maxn<<2];

LL max (LL a,LL b)
{
	return a>b?a:b;
}

void PushUp(int id)
{
	st[id].left = st[id<<1].left;
	st[id].right = st[id<<1|1].right;
	st[id].lsum = st[id<<1].lsum;
	st[id].rsum = st[id<<1|1].rsum;
	st[id].sum = st[id<<1].sum + st[id<<1|1].sum;
	LL ans1 = st[id<<1].maxsum,ans2 = st[id<<1|1].maxsum;
	if(ans1 >= ans2)
	{
		st[id].maxsum = st[id<<1].maxsum;
		st[id].a = st[id<<1].a;
		st[id].b = st[id<<1].b;
	}
	else 
	{
		st[id].maxsum = st[id<<1|1].maxsum;
		st[id].a = st[id<<1|1].a;
		st[id].b = st[id<<1|1].b;
	}
	//lsum,rsum,maxsum,a,b,left,right都有可能更改
	//lsum
	if(st[id].lsum == st[id<<1].sum && st[id<<1|1].lsum > 0)
	{
		st[id].lsum = st[id].lsum + st[id<<1|1].lsum;
		st[id].left = st[id<<1|1].left;
	}
	//rsum
	if(st[id].rsum == st[id<<1|1].sum && st[id<<1].rsum >= 0)
	{
		st[id].rsum = st[id].rsum + st[id<<1].rsum;
		st[id].right = st[id<<1].right;
	}
	//maxsum
	if((st[id<<1].rsum + st[id<<1|1].lsum > st[id].maxsum) || 
	  (st[id<<1].right < st[id].a && st[id<<1].rsum + st[id<<1|1].lsum == st[id].maxsum))
	{
		st[id].maxsum = st[id<<1].rsum + st[id<<1|1].lsum;
		st[id].a = st[id<<1].right;
		st[id].b = st[id<<1|1].left;
	}
}

void buildtree(int id,int l,int r)
{
	st[id].l = l,st[id].r = r;
	if(l == r)
	{
		st[id].sum = st[id].lsum = st[id].rsum = st[id].maxsum = key[l];
		st[id].left = st[id].right = st[id].a = st[id].b = l;
		return;
	}
	int mid = (l + r) >> 1;
	buildtree(lson);
	buildtree(rson);
	PushUp(id);
}

LL query(int id,int l,int r)
{
	if(st[id].l == l && st[id].r == r)
	{
		s = st[id].a;
		t = st[id].b;
		return st[id].maxsum;
	}
	if(st[id<<1].r >= r)
	{
		return query(id<<1,l,r);
	}
	else if(st[id<<1|1].l <= l)
	{
		return query(id<<1|1,l,r);
	}
	else 
	{
		LL ans1 = query(id<<1,l,st[id<<1].r);
		LL ans2 = query(id<<1|1,st[id<<1|1].l,r);
		if(ans1 >= ans2)	query(id<<1,l,st[id<<1].r);
		LL ans = max(ans1,ans2);
		if((st[id<<1].rsum + st[id<<1|1].lsum > ans) || 
		   (st[id<<1].rsum + st[id<<1|1].lsum == ans && st[id<<1].right < s))
		{
			s = st[id<<1].right;
			t = st[id<<1|1].left;
		}
		ans = max(ans,st[id<<1].rsum + st[id<<1|1].lsum);
		return ans;
	}
}

int main()
{
	//freopen("in.txt","r",stdin);
	int n,m,cas = 0;
	while(scanf("%d%d",&n,&m)==2)
	{
		cas++;
		for(int i = 1;i <= n;i++)	scanf("%lld",&key[i]);
		buildtree(1,1,n);
		printf("Case %d:\n",cas);
		while(m--)
		{
			int u,v;
			scanf("%d%d",&u,&v);
			query(1,u,v);
			printf("%d %d\n",s,t);
		}
	}
	return 0;
}


回过头来看。终于把它A了。。热泪盈眶。。。
线段树维护的信息:a表示最小x。b表示最小y。
                  left表示最大前缀和的终点,right表示最大后缀和的起点
                  lsum,rsum,maxsum表示最大前缀和,最大后缀和,最大连续和。
                  此题query函数得写三个~~返回类型用结构体~~跪烂了!!
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define maxn 500080
#define lson id<<1,l,mid
#define rson id<<1|1,mid+1,r
#define lson id<<1,l,mid
#define rson id<<1|1,mid+1,r
#define LL long long int
LL key[maxn],Sum[maxn];//前缀和数组
struct ST
{
	int l,r,a,b,left,right;
	LL maxsum,sum,lsum,rsum;
}st[maxn<<2];

struct Node
{
	int l,r;
	LL sum;
};

LL max (LL a,LL b)
{
	return a>b?a:b;
}

void PushUp(int id)
{
	st[id].left = st[id<<1].left;
	st[id].right = st[id<<1|1].right;
	st[id].lsum = st[id<<1].lsum;
	st[id].rsum = st[id<<1|1].rsum;
	st[id].sum = st[id<<1].sum + st[id<<1|1].sum;
	LL ans1 = st[id<<1].maxsum,ans2 = st[id<<1|1].maxsum;
	if(ans1 >= ans2)
	{
		st[id].maxsum = st[id<<1].maxsum;
		st[id].a = st[id<<1].a;
		st[id].b = st[id<<1].b;
	}
	else 
	{
		st[id].maxsum = st[id<<1|1].maxsum;
		st[id].a = st[id<<1|1].a;
		st[id].b = st[id<<1|1].b;
	}
	//lsum,rsum,maxsum,a,b,left,right都有可能更改
	//lsum
	if(st[id<<1].sum + st[id<<1|1].lsum > st[id<<1].lsum)
	{
		st[id].lsum = st[id<<1].sum + st[id<<1|1].lsum;
		st[id].left = st[id<<1|1].left;
	}
	//rsum
	if(st[id<<1|1].sum + st[id<<1].rsum >= st[id<<1|1].rsum)
	{
		st[id].rsum = st[id<<1].rsum + st[id<<1|1].sum;
		st[id].right = st[id<<1].right;
	}
	//maxsum
	if((st[id<<1].rsum + st[id<<1|1].lsum > st[id].maxsum) || 
	  (st[id<<1].right < st[id].a && st[id<<1].rsum + st[id<<1|1].lsum == st[id].maxsum))
	{
		st[id].maxsum = st[id<<1].rsum + st[id<<1|1].lsum;
		st[id].a = st[id<<1].right;
		st[id].b = st[id<<1|1].left;
	}
}

void buildtree(int id,int l,int r)
{
	st[id].l = l,st[id].r = r;
	if(l == r)
	{
		st[id].sum = st[id].lsum = st[id].rsum = st[id].maxsum = key[l];
		st[id].left = st[id].right = st[id].a = st[id].b = l;
		return;
	}
	int mid = (l + r) >> 1;
	buildtree(lson);
	buildtree(rson);
	PushUp(id);
}

Node query_suffix(int id,int l,int r)
{
	if(st[id].l == l && st[id].r == r)
	{
		Node a;
		a.l = st[id].right;;
		a.r = r;
		a.sum = st[id].rsum;
		return a;
	}
	if(st[id<<1].r >= r)
	{
		return query_suffix(id<<1,l,r);
	}
	else if(st[id<<1|1].l <= l)
	{
		return query_suffix(id<<1|1,l,r);
	}
	Node a = query_suffix(id<<1,l,st[id<<1].r);
	Node b = query_suffix(id<<1|1,st[id<<1|1].l,r);
	Node ans;
	ans.r = r;
	if(a.sum + Sum[r] - Sum[st[id<<1].r] >= b.sum)
	{
		ans.sum = a.sum + Sum[r] - Sum[st[id<<1].r];
		ans.l = a.l;
	}
	else 
	{
		ans.sum = b.sum;
		ans.l = b.l;
	}
	return ans;
}

Node query_pre(int id,int l,int r)
{
	if(st[id].l == l && st[id].r == r)
	{
		Node a;
		a.l = l;
		a.r = st[id].left;
		a.sum = st[id].lsum;
		return a;
	}
	if(st[id<<1].r >= r)
	{
		return query_pre(id<<1,l,r);
	}
	else if(st[id<<1|1].l <= l)
	{
		return query_pre(id<<1|1,l,r);
	}
	Node a = query_pre(id<<1,l,st[id<<1].r);
	Node b = query_pre(id<<1|1,st[id<<1|1].l,r);
	Node ans;
	ans.l = l;
	if(st[id<<1].sum + b.sum > a.sum)
	{
		ans.sum = st[id<<1].sum + b.sum;
		ans.r = b.r;
	}
	else 
	{
		ans.sum = a.sum;
		ans.r = a.r;
	}
	return ans;
}

Node query(int id,int l,int r)
{
	if(st[id].l == l && st[id].r == r)
	{
		Node a;
		a.l = st[id].a;
		a.r = st[id].b;
		a.sum = st[id].maxsum;
		return a;
	}
	if(st[id<<1].r >= r)
	{
		return query(id<<1,l,r);
	}
	else if(st[id<<1|1].l <= l)
	{
		return query(id<<1|1,l,r);
	}
	else 
	{
		Node ans1 = query(id<<1,l,st[id<<1].r);
		Node ans2 = query(id<<1|1,st[id<<1|1].l,r);
		Node a = query_suffix(id<<1,l,st[id<<1].r);
		Node b = query_pre(id<<1|1,st[id<<1|1].l,r);
		Node ans;
		if(ans1.sum >= ans2.sum)
		{
			ans.sum = ans1.sum;
			ans.l = ans1.l;
			ans.r = ans1.r;
		}
		else 
		{
			ans.sum = ans2.sum;
			ans.l = ans2.l;
			ans.r = ans2.r;
		}
		if(a.sum + b.sum > ans.sum || (a.sum + b.sum == ans.sum && a.l < ans.l))
		{
			ans.sum = a.sum + b.sum;
			ans.l = a.l;
			ans.r = b.r;
		}
		return ans;
	}
}

int main()
{
	//freopen("in.txt","r",stdin);
	int n,m,cas = 0;
	while(scanf("%d%d",&n,&m)==2)
	{
		cas++;
		Sum[0] = 0;
		for(int i = 1;i <= n;i++)	
		{
			scanf("%lld",&key[i]);
			Sum[i] = Sum[i-1] + key[i];
		}
		buildtree(1,1,n);
		printf("Case %d:\n",cas);
		while(m--)
		{
			int u,v;
			scanf("%d%d",&u,&v);
			Node a = query(1,u,v);
			printf("%d %d\n",a.l,a.r);
		}
	}
	return 0;
}




        
【编译原理】龙书第三章作业答案 【编译原理】龙书第三章作业答案 练习3.1.1:根据3.1.2节中的讨论,将下面的C++程序划分成正确的词素序列。哪些词素应该有相关联的词法值?应该具有什么值? 答案: 左列为词素,右列为值,划分如下: < float> 值为它本身 <id,limitedSquare> 值为*limitedSquare指针 <(> 标点符号无值 ... 阅读详情

相关推荐

VS2019配置Qt5.14.2开发环境全流程(含MSVC2017 64-bit选择指南)

本文详细介绍了在VS2019中配置Qt5.14.2开发环境的完整流程,特别针对MSVC2017 64-bit编译器的选择提供了专业建议。从环境准备、Qt安装配置到VS2019集成设置,逐步指导开发者完成开发环境的搭建,并提供了常见问题的解决方案和高级优化技巧,帮助开发者高效进行Qt开发。

weixin_29243279的博客 521

CF303B:Rectangle Puzzle II(数学)

B. Rectangle Puzzle II time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a rectangle grid. That

junior19的博客 490

机械臂控制的基础知识

在现代工业中,机械臂的自动化控制已经成为智能制造的重要一环。控制机械臂涉及多个学科,包括机械设计、运动学、控制理论和编程等。本文将从以下几个方面介绍机械臂控制的核心知识点:机械臂的构成、运动学分析、动力学建模、控制方法及编程实现。

qq_45728381的博客 5479

LA 3938 经典线段树

这道线段树是求最大连续子序列的分治算法的进阶版本。它的根本思想还是分治算法,我的算法如下: 1,线段树的每一个节点保存8个变量(虽然看似很多但是都很有用),分别为 sum(该区间的和); maxl(包含该区间最左位置的最大值) , idxl(maxl的最右位置); 同上maxr , idxr ; mmid(该区间的最大值),midl(最大值的左位置),midr(最大值的右位置) ; 2

ZQDNR 615

ZYNQ实战:手把手教你用AXI4-Full IP核打通PL与PS的DDR数据通道

本文提供了一份详细的ZYNQ实战指南,手把手教你创建并使用具备AXI4-Full Master接口的自定义IP核,实现PL(可编程逻辑)通过AXI HP接口直接读写PS(处理系统)的DDR内存。文章涵盖了从Vivado硬件设计、IP核配置、地址映射到Vitis软件验证的完整流程,并深入解析了数据一致性(禁用Cache)等关键要点,旨在帮助开发者掌握ZYNQ异构计算中高效数据搬运的核心技术。

weixin_29193359的博客 290

机械臂速成小指南(七):从旋转矩阵到齐次变换——机械臂位姿的数学表达

本文详细介绍了机械臂位姿描述的数学基础,包括旋转矩阵、欧拉角和齐次变换等核心概念。通过解析旋转矩阵的几何意义和合成方法,以及欧拉角的直观描述,帮助读者理解机械臂位姿的数学表达。文章还探讨了齐次变换在工程实践中的应用,并提供了数值稳定性、坐标系约定和计算效率等实用建议。

cuda7parallel的博客 841

LA3938-Ray, Pass me the dishes!--动态最大连续区间和(线段树+前后缀数和组)

题意:给一个数组,求任意区间的最大连续和 长度n,查询次数m   n,m大小是5*10^5 每个数不超过1e9 之前做的是静态数组求一次最大连续和,方法有很多,dp之类的都能o(n)解决。   还有一个是分治法,nlogn解决:http://blog.csdn.net/viphong/article/details/48221429 这里也是用分治法的思路解决: 称区间【l,r】的最大

缺氧 1830

proteus仿真51单片机操作指南:串口通信仿真配置详解

深入讲解如何在proteus仿真51单片机中实现串口通信,涵盖虚拟串口设置、电路连接与调试技巧,帮助开发者高效完成通信仿真验证。

weixin_36197669的博客 579

UVA1400&LA3938 线段树

构造线段树每个节点维护三个值 max_pre 满足当前线段最大前缀和的右端点编号 max_suf 满足当前线段最大后缀和的左端点编号 max_sub 用pair维护满足当前线段最大连续和的两个端点编号 维护max_sub 有三种情况 左右端点都在 左子节点 max_sub等于左子节点的max_sub 左右端点都在 右子节点 max_sub等于右子节点的max_sub 左端点在 左子

CoderFly的博客 439

置顶必读(1) |《滚雪球学SpringBoot 3.x》· 高质量专栏介绍,你值得拥有!

《滚雪球学SpringBoot 3.x》 并不是普通的技术讲解合集,它是专为开发者精心设计的系统化学习路径。通过不断“滚动学习”,我们将带领你从基础入门到高阶应用,从理解每一行代码到设计和优化大规模分布式系统,最终帮助你成长为一位精通 spring架构 的工程师。

**My Coding Family** 12万+

ERROR conda.core.link:_execute(502): error occurred while installing conda-forge::setuptools 解决方案

本文主要介绍了ERROR conda.core.link:_execute(502): An error occurred while installing package mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge::setuptools-65.5.1-pyhd8ed1ab_0.FileNotFoundError(2, 系统找不到指定的文件。, None, 2) 解决方案,希望能对新手有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 8万+

LA 3938 线段树区间更新

题目链接 题意: 给你一个序列 (n 如果只求和,那么这题还算比较顺手, 但求下标,节点保存的数据比较多,导致更新的时候很容易出错,其实题目本身还是很容易想到的,只是比较麻烦,锻炼查错能力。 思路; 对于某一区间最值的更新: 1. 左区间的最值 2  右区间的最值 3  左区间的最大后缀和 + 右区间的最大前缀和 对于最大前缀和的更新: 1 左区间的最大前缀和

Nicolas 1998

《UDS协议从入门到精通》系列——图解0x2E:通过ID写数据

图解数据包格式+直观的通信示例,迅速认识0x2E服务!!

车载系统攻城狮 3612

LA3938——线段树区间合并

题意:给定一个长度为n的序列,每次询问一个区间[a, b],求出该区间内最大连续和的范围。 维护线段树节点的5个域:l, r区间的左右端点;x, y最大连续和的范围的左右端点;ln最大前缀和的右端点;rn最大后缀和的左端点。在区间合并的时候,分情况讨论,不详述。 查询的时候,如果待查询区间“横跨”了所在区间的中点,分三种情况讨论:最大连续和在左区间,在右区间,以及跨区间中点。对于跨区间中点的情

cool_Fires的专栏 758

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

线段树-区间合并uva1400(LA3938)

"Ray, Pass me the dishes!" 求最大连续和。 写起来太蛋疼了,还是因各种细节过不了,忘了考虑,多组满足时x尽量小,y尽量小,查询的时候也是缺这个少那个。。。 下面是标程,写的很漂亮,多学习! #include #include #include using namespace std; const int maxn = 500000 + 10; const int

龙崎的专栏 775

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

LA3938 "Ray, Pass me the dishes!" (线段树区间合并)

题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=22105 题意:给定整数n和m,给出一个n个元素的序列,查询m次给定区间[L,R]的最大连续和的位置[x,y],有多个区间输出x最小的,还有多个的话输出y最小的。 分析:每个节点存8个信息,最大连续和、最大后缀和、最大前缀和、区间和、前缀末位置、后缀首位置、最大连续和

w20810的专栏 839

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

HDU1540——线段树区间合并——求最长连续区间

题目链接:https://vjudge.net/contest/168122#problem/I 这是另一种线段树的常见问题,相当于原本有一串长为n的1串,现将其中一些点标记为0或恢复为1,每次询问问你pos所在的最长1连续区间为多长。这种题其实之前见过,就是白书201页的LA3938,一个求动态最大连续和的问题,其实都是区间合并的问题。 思路也是类似,每个区间维护最长1前缀长度maxpre,...

Q755100802的博客 502

LA3938 :"Ray, Pass me the dishes!" (线段树区间查询)

先呈上原题链接"Ray, Pass me the dishes!" (vjudge) (大白书刷题笔记) 又是一道比较练代码能力的题目,开始的时候常数写太大了还写成了 O(n∗log⁡n∗log⁡n)O(n*\log n*\log n)O(n∗logn∗logn),数据范围又是 5e55e55e5 且多组数据,所以 TLE 了。。。后来全部改写过了。 还有就是里面有许多细节加之平时用结构体少,历...

BNUbeginner的博客 220

HDU3308LCIS(线段树区间合并)

题意: Given n integers. You have two operations: U A B: replace the Ath number by B. (index counting from 0) Q A B: output the length of the longest consecutive increasing subsequence (LCIS) in

蒟蒻LQL的ACM征程 370

并查集题集

大部分是风神博客上的题目,我在此基础上增删了些题目。 【HDU】 1213 How Many Tables 基础并查集★ 1272 小希的迷宫 基础并查集★ 1325&&poj1308 Is It A Tree? 基础并查集★ 1856 More is better 基础并查集★ 1232 畅通工程 基础并查集★ 1811 Rank of Tetris 并查...

weixin_30713953的博客 176

LA 3938( 线段树)

#include #include #include const int maxn = 500005; typedef long long ll; int n,m; ll a[maxn],sum[maxn]; struct node { int x,y,pre,suf,dx,dy; }; node tnode[maxn*2]; void Build(int o,int x,int y) {

qining的专栏 694

LA 3938 动态最大连续区间 线段树

思路很清晰,实现很繁琐。分析过程可以参考LRJ,自己的总结晚些放。 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxN=5e5+5,maxNode=1e6+5; #define ll long lo...

SH16666的博客 203

LA 3938 "Ray, Pass me the dishes!" / 线段树单点更新

中间有一个| 我写成了|| 查了好几个小时 我日 每次询问一段区间最大和的起始和终点坐标 x,y x y 尽量小 对于某个节点 最大和要么是左子树的最大和 要么是右子树的最大值 要么是左右各有 最后一中情况要保存最大前缀和最大后缀 取左子树的最大后缀和右子树的最大前缀 #include #include #include #include #include #include

嗯。 1215

线段树,分治法(动态最大连续和,LA 3938)

长代码找手误真的难= =。很容易脑补成对的,然后就混过去了。其实不应该贪快嫌麻烦,一定要想清楚。 线段树维护:区间左坐标,区间右坐标,区间和,最大连续和,最大连续和左坐标,最大连续和右坐标,最大前缀和,最大前缀和右坐标,最大后缀和,最大后缀和左坐标。 如果区间和相等,都是在保证左坐标最小的情况下,右坐标最小。 可以证明当区间和相等时,选择右边>左+右>选择左边。

xl2015190026的博客 774

LA3938:"Ray, Pass me the dishes!"(线段树)

Description After doing Ray a great favor to collect sticks for Ray, Poor Neal becomes very hungry. In return for Neal's help, Ray makes a great dinner for Neal. When it is time for dinner, Ray

ACM!荣耀之路! 2572

LA3938 线段树+分治

题意 给出长度为n的整数序列,然后m次询问,对于每次询问,要求找到区间内的两个下标x,y使得区间和尽量大,如果有多解,x尽量小,还有多解,那么y也尽量小 分析 最大连续和的分治分治算法是解决此题的关键,构造一棵线段树,并查集维护四个值:区间和sum,最大连续和max_sub、最大前缀和max_pre、最大后缀和max_last。建树与修改时注意 max_sub[o]=max(max(m

G_congratulation的博客 545
上一篇: UVA 11235
下一篇: UVA 11992 二维线段树
SCUT_Pein
博客等级 码龄14年 54粉丝 480原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值