797. Difference

Enter a sequence of integers of length n.

Next enter m operations, each consisting of three integers l,r,c that add c to every number between [l,r] in the sequence.

Please output the sequence after all operations are performed.

Input format
The first line contains two integers n and m.

The second line contains n integers, representing a sequence of integers.

The next m lines, each line contains three integers l, r, c, representing an operation.

Output format
A line containing n integers representing the final sequence.

Data range
1≤n,m≤100000,
1≤l≤r≤n,
−1000≤c≤1000,
−1000≤The value of the elements in the integer sequence≤1000
Input example:
6 3
1 2 2 1 2 1
1 3 1
3 5 1
1 6 1
Sample output:
3 4 5 3 4 2

在这里插入代码片

#include<bits/stdc++.h>
using namespace std;
const int N = 100010;
int a[N], b[N];

int main()
{
    
    
    int n, m;
    cin >> n >> m;
    for(int i=1; i<=n; i++) {
    
    
        cin >> a[i];
    }
    
    for(int i=1; i<=n; i++) {
    
    
        b[i] = a[i] - a[i-1];
    }
    
    int l, r, c;
    while(m--) {
    
    
        cin >> l >> r >> c;
        b[l] += c;
        b[r+1] -= c;
    }
    
    for(int i=1; i<=n; i++) b[i] += b[i-1];
    
    for(int i=1; i<=n; i++) cout << b[i] << ' ';
    return 0;
}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=324123265&siteId=291194637