-
Notifications
You must be signed in to change notification settings - Fork 0
/
banderas.cpp
59 lines (49 loc) · 1.1 KB
/
banderas.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// #include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
typedef long long int lld;
typedef long double llf;
typedef pair<int, int> pii;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
/*
n Q
Q líneas de la forma [i, j], v
*/
int n, Q;
cin >> n >> Q;
int bucket[n + 1];
fill(bucket, bucket + n + 1, 0);
for (int q = 0; q < Q; ++q) {
int i, j, v;
cin >> i >> j >> v;
bucket[i] += v;
bucket[j + 1] -= v;
}
int arr[n + 1];
arr[0] = 0;
for (int i = 1; i <= n; ++i) {
// arr[i] es la suma de las banderas que afectaron de [1, i]
// Es decir es la suma de bucket[1] + bucket[2] + ... + bucket[i]
arr[i] = arr[i - 1] + bucket[i];
}
// Imprimimos el arreglo
for (int i = 1; i <= n; ++i) {
cout << arr[i] << " ";
}
cout << endl;
return 0;
}