Suffix Operations Codeforces Round #688 (Div. 2)B

博客文章介绍了如何解决Codeforces的一道编程竞赛题目,涉及到后缀数组操作,目标是通过加1和减1使得数组元素相等。文章首先阐述了不修改数组时的差分约束思路,然后讨论了修改数组中特定位置以减少操作数的方法,特别是修改开头、结尾和中间位置的影响,并提供了具体的计算规则。

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

http://codeforces.com/contest/1453/problem/B
题意:通过对后缀数组的+1-1使数全部相等,开始前你可以直接修改一个数的值,问最小操作数

思路:

差分约束,先不考虑修改数。首先,获取相邻数的差我们设为Si(Si=a[i]-a[i-1],2<=i<=n),假设我们改的后缀数组从j(1<j<=n)开始,那么由于同时更改,j-n的数之间差不变,只改变了j-1和j的数的差,而最终状态我们要使所有的差归零,也就是说要的操作数就是所有差的绝对值之和。
现在考虑,改一个数:
改开头和结尾,可以使S2,Sn归零
改中间,位置设为j(1<j<n):Sj,S(j+1)同增同减:同号没影响;异号操作数减少绝对值小的一个数的两倍
(如-3 -5 -2 ,差是 -2 3,把-5改成-3,差变为0 1,操作数减少4)
最后答案减去改的数减小的操作数就行了。

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+10;
int a[N],sub[N];
int main() {
   
   
 int t;
 cin>>t;
 
<!-- 插入集合 --> <insert id="insertListSelective" parameterType="java.util.List"> INSERT INTO art_customer_leads_pool <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null">id,</if> <if test="activityId != null">activity_id,</if> <if test="activityName != null">activity_name,</if> <if test="comCode != null">com_code,</if> <if test="comName != null">com_name,</if> <if test="customerName != null">customer_name,</if> <if test="licenseNo != null">license_no,</if> <if test="expiryMonth != null">expiry_month,</if> <if test="mobile != null">mobile,</if> <if test="referrerStaffNo != null">referrer_staff_no,</if> <if test="referrerType != null">referrer_type,</if> <if test="status != null">status,</if> <if test="source != null">source,</if> <if test="leadInboundTime != null">lead_inbound_time,</if> <if test="createTime != null">create_time,</if> <if test="updateTime != null">update_time,</if> </trim> VALUES <foreach collection="item" index="index" item="item" separator=","> <trim prefix="(" suffix=")" suffixOverrides=","> <if test="item.id != null">#{item.id, jdbcType=BIGINT},</if> <if test="item.activityId != null">#{item.activityId, jdbcType=VARCHAR},</if> <if test="item.activityName != null">#{item.activityName, jdbcType=VARCHAR},</if> <if test="item.comCode != null">#{item.comCode, jdbcType=VARCHAR},</if> <if test="item.comName != null">#{item.comName, jdbcType=VARCHAR},</if> <if test="item.customerName != null">#{item.customerName, jdbcType=VARCHAR},</if> <if test="item.licenseNo != null">#{item.licenseNo, jdbcType=VARCHAR},</if> <if test="item.expiryMonth != null">#{item.expiryMonth, jdbcType=DATE},</if> <if test="item.mobile != null">#{item.mobile, jdbcType=VARCHAR},</if> <if test="item.referrerStaffNo != null">#{item.referrerStaffNo, jdbcType=VARCHAR},</if> <if test="item.referrerType != null">#{item.referrerType, jdbcType=VARCHAR},</if> <if test="item.status != null">#{item.status, jdbcType=SMALLINT},</if> <if test="item.source != null">#{item.source, jdbcType=VARCHAR},</if> <if test="item.leadInboundTime != null">#{item.leadInboundTime, jdbcType=DATE},</if> <if test="item.createTime != null">#{item.createTime, jdbcType=DATE},</if> <if test="item.updateTime != null">#{item.updateTime, jdbcType=DATE},</if> </trim> </foreach> </insert> public interface ArtCustomerLeadsPoolExtMapper { int insertListSelective(@Param("item") List<ArtCustomerLeadsPool> record); }我这个那里写错了
最新发布
03-12
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值