-
Notifications
You must be signed in to change notification settings - Fork 0
/
code_range.cpp
75 lines (53 loc) · 1 KB
/
code_range.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
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <vector>
using namespace std;
void make_changes( int , int, int, int, int* );
int main()
{
int t;
int min, max;
vector<int> sol;
cin >> t;
for ( int i =0; i < t; i++ ) {
int n, m;
cin >> n;
cin >> m;
int arr[n];
for ( int k = 1; k <= n; k++ ) {
arr[k-1] = k;
}
for ( int j = 0; j < m; j++ ) {
int w, x, y, z;
cin >> w;
cin >> x;
cin >> y;
cin >> z;
make_changes( w, x, y, z, arr);
}
int min, max;
min = max = arr[0];
for ( int a = 0; a < n; a++ ) {
if ( arr[a] < min )
min = arr[a];
else if ( arr[a] > max )
max = arr[a];
}
sol.push_back(max - min );
}
vector<int> :: iterator it = sol.begin();
for ( it = sol.begin(); it != sol.end(); it++ ) {
cout << *it << endl;
}
return 0;
}
void make_changes( int w, int x, int y, int z, int *arr ) {
if ( w == 1 ) {
for ( int i = x - 1; i < y; i++ ) {
arr[i] += z;
}
} else {
for ( int i = x - 1; i < y; i++ ) {
arr[i] -= z;
}
}
}