CF# 576 div2 D

本文解析了CodeForces平台上的一道题目,该题目涉及线段树数据结构和区间更新操作,通过具体示例和代码详细说明了解决方案。

http://codeforces.com/problemset/problem/1198/B
There is a country with n citizens. The i-th of them initially has ai money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.

Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don’t send a receipt.

You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.

Input
The first line contains a single integer n (1≤n≤2⋅105) — the numer of citizens.

The next line contains n integers a1, a2, …, an (0≤ai≤109) — the initial balances of citizens.

The next line contains a single integer q (1≤q≤2⋅105) — the number of events.

Each of the next q lines contains a single event. The events are given in chronological order.

Each event is described as either 1 p x (1≤p≤n, 0≤x≤109), or 2 x (0≤x≤109). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.

Output
Print n integers — the balances of all citizens after all events.

Examples
Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4

In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10
线段树,两种操作,1.单点修改 2.将数组中所有小于x的数改成x,
一开始想只记录最小值,第二个操作的时候如果最小值大于x直接return,不然暴力修改,然后很明显会TLE。。。还是要用lazy数组,第二个操作的时候区间修改

#include<stdio.h>
#include<algorithm>
#include<string.h>
#define maxn 200005
using namespace std;
int n,q,mi[maxn<<2],lazy[maxn<<2];
void pushup(int k)
{
	mi[k]=min(mi[k<<1],mi[k<<1|1]);
}
void pushdown(int k)
{
	if(lazy[k]>=0)
	{
		mi[k<<1]=max(mi[k<<1],lazy[k]);
		mi[k<<1|1]=max(mi[k<<1|1],lazy[k]);
		lazy[k<<1]=max(lazy[k<<1],lazy[k]);
		lazy[k<<1|1]=max(lazy[k<<1|1],lazy[k]);
		lazy[k]=-1;
	}
}
void build(int k,int l,int r)
{
	if(l==r)
	{
		scanf("%d",mi+k);
		return ;
	}
	int mid=(l+r)/2;
	build(k<<1,l,mid);
	build(k<<1|1,mid+1,r);
	pushup(k);
}
void set(int k,int l,int r,int loc,int x)
{
	if(l==r)
	{
		mi[k]=x;
		return ;
	}
	pushdown(k);
	int mid=(l+r)/2;
	if(loc<=mid)
	set(k<<1,l,mid,loc,x);
	else
	set(k<<1|1,mid+1,r,loc,x);
	pushup(k);
}
void oporate(int k,int x)
{
    if(mi[k]>=x)  
	return;
    mi[k]=x;
    lazy[k]=max(lazy[k],x);
}
void query(int k,int l,int r)
{
	if(l==r)
	{
		printf("%d ",mi[k]);
		return ;
	}
	pushdown(k);
	int mid=(l+r)/2;
	query(k<<1,l,mid);
	query(k<<1|1,mid+1,r);
}
int main()
{
	scanf("%d",&n);
	build(1,1,n);
	scanf("%d",&q);
	int op,loc,x;
	memset(lazy,-1,sizeof(lazy));
	while(q--)
	{
		scanf("%d",&op);
		if(op==1)
		{
			scanf("%d%d",&loc,&x);
			set(1,1,n,loc,x);
		} 
		else
		{
			scanf("%d",&x);
			oporate(1,x);
		}
	}
	query(1,1,n);
}
内容概要:本文提出了一种考虑不同充电需求的电动汽车有序充电调度方法,并提供了基于Matlab的完整代码实现。该方法通过构建精细化的数学模型,综合考量电动汽车用户的多样化充电需求,如充电起止时间、目标电量、充电偏好及用户满意度等因素,结合智能优化算法进行求解,实现对大规模电动汽车充电行为的协调控制。研究旨在通过有序调度策略有效平抑电网负荷波动,实现削峰填谷,降低配电网运行压力,提升电力系统运行的经济性与稳定性,尤其适用于未来高渗透率电动汽车接入场景下的充电管理与需求响应应用。; 适合人群:电气工程、自动化、能源系统及相关领域的科研人员、高校研究生,以及从事智能电网、电动汽车充电管理、能源优化调度等方向的技术人员,需具备一定的Matlab编程能力与优化理论基础。; 使用场景及目标:①应用于智能电网中规模化电动汽车集群的有序充电调度与能量管理;②支撑科研工作中关于需求响应、负荷调控、分布式资源优化调度等课题的模型构建与仿真验证;③为充电运营商或电力公司提供兼顾用户需求与电网安全的个性化、智能化充电服务解决方案。; 阅读建议:建议读者结合Matlab代码深入理解算法的具体实现流程,重点分析目标函数的设计思路、多类型约束条件的建模方式以及优化求解器的配置过程,可在此基础上拓展至多目标优化、实时滚动调度或考虑可再生能源不确定性的联合优化研究。
内容概要:本文研究了基于Benders分解的输配电网双层优化模型,旨在解决风电出力等不确定性因素对电网运行带来的挑战。模型采用TSO-DSO协调机制,其中输电网运营商(TSO)作为上层决策者负责全局优化与协调,配电网运营商(DSO)作为下层响应者进行本地优化。通过Benders分解算法将原问题分解为主问题与子问题,实现双层耦合系统的高效迭代求解,确保计算可行性与收敛性。研究涵盖了不确定性建模、双层博弈结构设计、协调变量传递机制及Benders割平面生成逻辑,并提供了完整的Matlab代码实现,具备良好的可复现性与工程应用价值。; 适合人群:具备电力系统优化、运筹学理论基础,熟悉Matlab编程语言,从事电力系统规划、调度、可再生能源集成及相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:① 掌握含不确定性因素的输配电网协同优化建模范式;② 深入理解Benders分解在多主体、多层次电力系统优化中的应用原理与实现路径;③ 开展高比例可再生能源接入背景下的电网调度仿真、鲁棒/分布鲁棒优化扩展研究及实际工程项目的技术验证; 阅读建议:建议结合Matlab代码逐模块剖析模型构建流程,重点关注主从问题间的变量耦合关系与Benders割的构造机制,进一步可引入多场景分析、分布鲁棒优化等高级不确定性处理方法进行模型拓展与深化研究。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值