-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaddalg.cpp
68 lines (61 loc) · 921 Bytes
/
addalg.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
#include<bits/stdc++.h>
using namespace std;
#define ll int
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main() {
fast
ll n,m;
cin>>n>>m;
ll a[n][m],i,j,pre[n][m];
string s[n];
for(i=0;i<n;i++)
cin>>s[i];
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
a[i][j] = s[i][j]-'0';
pre[i][j]=0;
}
}
ll q;
cin>>q;
ll x1,y1,x2,y2;
while(q--) {
cin>>x1>>y1>>x2>>y2;
x1--;
y1--;
y2--;
x2--;
pre[x1][y1]++;
if(x2+1<n && y2+1<m)
pre[x2+1][y2+1]++;
if(x2+1<n)
pre[x2+1][y1]--;
if(y2+1<m)
pre[x1][y2+1]--;
}
for(i=0;i<m;i++) {
for(j=1;j<n;j++) {
pre[j][i] += pre[j-1][i];
}
}
for(i=0;i<n;i++) {
for(j=1;j<m;j++) {
pre[i][j] += pre[i][j-1];
}
}
for(i=0;i<n;i++) {
for(j=0;j<m;j++) {
if(pre[i][j]%2) {
if(a[i][j] == 1)
cout<<0;
else
cout<<1;
}
else
cout<<a[i][j];
}
cout<<"\n";
}
}