-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShooting (Hard)
141 lines (132 loc) Β· 3.53 KB
/
Shooting (Hard)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include <bits/stdc++.h>
#define lowbit(x) ((x) & -(x))
#define ml(a, b) ((1ll * (a) * (b)) % M)
#define tml(a, b) (a) = ((1ll * (a) * (b)) % M)
#define ad(a, b) ((0ll + (a) + (b)) % M)
#define tad(a, b) (a) = ((0ll + (a) + (b)) % M)
#define mi(a, b) ((0ll + M + (a) - (b)) % M)
#define tmi(a, b) (a) = ((0ll + M + (a) - (b)) % M)
#define tmin(a, b) (a) = min((a), (b))
#define tmax(a, b) (a) = max((a), (b))
#define iter(a) (a).begin(), (a).end()
#define riter(a) (a).rbegin(), (a).rend()
#define inin(a, b) memset((a), (b), sizeof(a))
#define cpy(a, b) memcpy((a), (b), sizeof(a))
#define uni(a) a.resize(unique(iter(a)) - a.begin())
#define size(x) (int)x.size()
#define pb emplace_back
#define mpr make_pair
#define ls(i) ((i) << 1)
#define rs(i) ((i) << 1 | 1)
#define INF 0x3f3f3f3f
#define NIF 0xc0c0c0c0
#define eps 1e-9
#define F first
#define S second
#define AC cin.tie(0)->sync_with_stdio(0)
using namespace std;
typedef long long llt;
typedef unsigned long long ull;
typedef __int128_t lll;
typedef double dl;
typedef pair<int, int> pii;
typedef pair<dl, dl> pdd;
typedef pair<llt, llt> pll;
typedef pair<llt, int> pli;
typedef complex<dl> cd;
typedef complex<llt> cll;
// const int M = 998244353;
// random_device rm;
// mt19937 rg(rm());
// default_random_engine rg(rm());
// uniform_int_distribution<int> rnd(INT_MIN, INT_MAX);
// uniform_real_distribution<double> rd(0, M_PI);
void db() { cerr << "\n"; }
template <class T, class... U>
void db(T a, U... b) { cerr << a << " ", db(b...); }
inline char gc()
{
const static int SZ = 1 << 16;
static char buf[SZ], *p1, *p2;
if (p1 == p2 && (p2 = buf + fread(p1 = buf, 1, SZ, stdin), p1 == p2))
return -1;
return *p1++;
}
void rd() {}
template <typename T, typename... U>
void rd(T &x, U &...y)
{
x = 0;
bool f = 0;
char c = gc();
while (!isdigit(c))
f ^= !(c ^ 45), c = gc();
while (isdigit(c))
x = (x << 1) + (x << 3) + (c ^ 48), c = gc();
f && (x = -x), rd(y...);
}
template <typename T>
void prt(T x)
{
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
prt(x / 10);
putchar((x % 10) ^ 48);
}
pll operator+(const pll &a, const pll &b)
{
return pll(a.F + b.F, a.S + b.S);
}
pll operator-(const pll &a, const pll &b)
{
return pll(a.F - b.F, a.S - b.S);
}
pll operator*(const pll &a, const llt &b)
{
return pll(a.F * b, a.S * b);
}
signed main()
{
int t, n, m, x;
rd(t);
while (t--)
{
rd(n, m);
vector<pll> c1(n + m), c2(n + m), a1(n + m), a2(n + m);
#define fx(x, y) (x + y)
#define fy(x, y) (x - y + m - 1)
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
rd(x);
if (x == 1 || x == 3)
c1[fx(i, j)].F++, c2[fy(i, j)].F++;
if (x == 2 || x == 3)
c1[fx(i, j)].S++, c2[fy(i, j)].S++;
}
}
auto slv = [&](vector<pll> &c, vector<pll> &a) -> void
{
pll cr(0, 0), d(0, 0);
for (int i = 0; i < n + m; i++)
cr = cr + c[i] * i, d = d + c[i];
for (int i = 0; i < n + m; i++)
{
a[i] = cr, d = d - c[i] * 2;
cr = cr - d;
}
};
slv(c1, a1), slv(c2, a2);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
pll ans = a1[fx(i, j)] + a2[fy(i, j)];
prt(abs(ans.S - ans.F) >> 1);
putchar(" \n"[j == m - 1]);
}
}
}
}