题解 | #【模板】差分#

【模板】差分

https://www.nowcoder.com/practice/4bbc401a5df140309edd6f14debdba42

import java.io.*;
import java.util.*;
import java.math.BigInteger;

public class Main {
    static int N = (int)(1e5+10);
    static long[] a = new long[N], d = new long[N];

    static void solve() {
        int n = in.nextInt(), m = in.nextInt();
        for(int i=1;i<=n;i++) {
            a[i] = in.nextLong();
            d[i] = a[i] - a[i-1];
        }
        while(m-->0) {
            int l = in.nextInt(), r = in.nextInt(), k = in.nextInt();
            d[l] += k;
            d[r+1] -= k;
        }
        for(int i=1;i<=n;i++) {
            d[i]+=d[i-1];
            out.print(d[i]+" ");
        }
    }

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    static FastReader in = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    static class FastReader {
        static BufferedReader br;
        static StringTokenizer st;

        FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            String str = "";
            while (st == null || !st.hasMoreElements()) {
                try {
                    str = br.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                st = new StringTokenizer(str);
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
06-27 15:07
点赞 评论 收藏
分享
牛客837006795号:简历抄别人的,然后再投,有反馈就是简历不行,没反馈就是学历不行,多投多改只要技术不差机会总会有的
点赞 评论 收藏
分享
矫健的闭门羹烹饪师又熬夜了:本人双非本,在鹅厂测开实习,你这个简历上写的这两个项目的技术栈都差不多,能够让面试官去延伸去问的八股除了redis就再没啥了,建议项目这边可以再改改,然后专业技能那块的话,感觉linux和测试工具可以分开写,毕竟不是干一件事的,反正没实习的基础上面试就深挖项目和八股,好好卷吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务