-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlamda.cpp
78 lines (65 loc) · 1.36 KB
/
lamda.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
73
74
75
76
77
78
//9 6
//1 0 0 1 1 0 0 0 1
//1 2 6
//1 4 8
//2 1 9
//2 3 5
//1 2 7
//2 5 8
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, q;
cin >> n >> q;
vector<bool> A(n + 1);
A[0] = 0;
int temp;
for(int i = 1; i <= n; ++i) {
cin >> temp;
A[i] = temp;
}
vector<int> P(n + 1);
P[0] = 0;
int t, l = 1, r = n;
auto transform = [&] () {
for(int i = 1; i <= n; ++i)
P[i] = A[i] + P[i-1];
};
auto sumCount = [&] () {
int sum = 0;
if(l == 1)
p[]
for(int i = l; i <= r; ++i) {
sum += P[i];
}
return sum;
};
transform();
auto Atransform = [&] () {
for(int i = l; i <= r; ++i) A[i] = !A[i];
};
//
auto print = [&] (auto items) {
for(int i = 0; i <= n; ++i) {
cout << items[i] << ", ";
}
cout << endl;
};
// cout <<" P initially " << endl;
// print(P);
while(q--) {
cin>> t >> l >> r;
if(t == 1) {
Atransform();
cout <<"Atranstorm\n";
print(A);
print(P);
transform();
cout <<"Ptranstorm\n";
print(A);
print(P);
}
else cout << sumCount() << endl;
}
}