题目的链接在这里:https://www.nowcoder.com/practice/4bbc401a5df140309edd6f14debdba42
- 题目大意
- 一、示意图
- 二、解题思路
- 差分
题目大意 ![在这里插入图片描述](https://img-blog.csdnimg.cn/b6965d6108df48bd8ff1637613424d8f.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5YWz5YiH5b6X5aSn56We,size_20,color_FFFFFF,t_70,g_se,x_16)
一、示意图 二、解题思路
差分差分
代码如下:
import java.util.*; public class Main{ public static void main(String[] args) { //差分 n个长度的正整数组 a1。。。an //进行m次 *** 作 有三个参数 l r k 表示把al。。。ar 都加上k Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); long a[]=new long[n]; //输入n个数 for(int i=0;i0){ m--; int l=sc.nextInt(); int r=sc.nextInt(); long k=sc.nextLong(); //这里会超时的 //说明是左边这个值加上k dp[l-1]+=k; //因为是 l-1到r-1 if(r 欢迎分享,转载请注明来源:内存溢出
评论列表(0条)