Problem Description
The children lined up and the teacher gave them apples.
Children mark 1..N from left to right. There are M teachers. Each time the i-th teacher will give Li to Ri, a total of Ri-Li + 1 children will send Ci apples each.
Finally, the teacher wants to know how many apples each child has.
Children mark 1..N from left to right. There are M teachers. Each time the i-th teacher will give Li to Ri, a total of Ri-Li + 1 children will send Ci apples each.
Finally, the teacher wants to know how many apples each child has.
Input format
The two integers N and M in the first line indicate the number of children and the number of teachers.
In the next M lines, there are three integers Li, Ri, and Ci in each line. The meaning is as stated in the title.
In the next M lines, there are three integers Li, Ri, and Ci in each line. The meaning is as stated in the title.
Output format
A row of N numbers, the ith number represents the fruit in the ith child's hand.
Sample input
5 3
1 2 1
2 3 2
2 5 3
1 2 1
2 3 2
2 5 3
Sample output
1 6 5 3 3
Data size and agreement
For 40% of the data, N and M ≤ 1 000.
For 100% of the data, N, M≤100 000, 1≤Li≤Ri≤N, 0≤Ci≤100.
For 100% of the data, N, M≤100 000, 1≤Li≤Ri≤N, 0≤Ci≤100.
Prefix and difference knowledge points are forgotten, to be reviewed.
1 #include <bits/stdc++.h> 2 using namespace std; 3 int a[100010]; 4 int main() { 5 int n, m; 6 cin >> n >> m; 7 while (m--) { 8 int l, r, c; 9 cin >> l >> r >> c; 10 a[r] += c; 11 a[l - 1] -= c; 12 } 13 for (int i = n - 1; i >= 1; i--) { 14 a[i] += a[i + 1]; 15 } 16 for (int i = 1; i <= n; i++) { 17 cout << a[i] << " "; 18 } 19 return 0; 20 }