from
operator
import
add
class
FenwickTreeInjectable:
def
__init__(
self
, n, identity_factory, func):
self
.size
=
n
self
.tree
=
[identity_factory()
for
_
in
range
(n
+
1
)]
self
.func
=
func
self
.idf
=
identity_factory
self
.depth
=
n.bit_length()
def
add(
self
, i, x):
i
+
=
1
tree
=
self
.tree
func
=
self
.func
while
i <
=
self
.size:
tree[i]
=
func(tree[i], x)
i
+
=
i &
-
i
def
sum
(
self
, i):
i
+
=
1
s
=
self
.idf()
tree
=
self
.tree
func
=
self
.func
while
i >
0
:
s
=
func(s, tree[i])
i
-
=
i &
-
i
return
s
n, m, q
=
map
(
int
,
input
().split())
y_appear
=
set
()
queries
=
[]
for
_
in
range
(q):
t, x, y
=
map
(
int
,
input
().split())
y_appear.add(y)
queries.append((t
-
1
, x
-
1
, y))
compress
=
{y: i
+
1
for
i, y
in
enumerate
(
sorted
(y_appear))}
compress[
0
]
=
0
fwt
=
[
{
'count'
: FenwickTreeInjectable(
len
(compress)
+
5
,
int
, add),
'total'
: FenwickTreeInjectable(
len
(compress)
+
5
,
int
, add),
},
{
'count'
: FenwickTreeInjectable(
len
(compress)
+
5
,
int
, add),
'total'
: FenwickTreeInjectable(
len
(compress)
+
5
,
int
, add),
},
]
fwt[
0
][
'count'
].add(
0
, n)
fwt[
1
][
'count'
].add(
0
, m)
current
=
[[
0
]
*
n, [
0
]
*
m]
buf
=
[]
ans
=
0
for
t, x, y
in
queries:
i
=
compress[y]
z
=
current[t][x]
j
=
compress[z]
get
=
fwt[t ^
1
][
'count'
].
sum
(i)
*
y
loss1
=
fwt[t ^
1
][
'count'
].
sum
(j
-
1
)
*
z
loss2
=
fwt[t ^
1
][
'total'
].
sum
(i)
-
fwt[t ^
1
][
'total'
].
sum
(j
-
1
)
ans
+
=
get
-
loss1
-
loss2
fwt[t][
'count'
].add(i,
1
)
fwt[t][
'count'
].add(j,
-
1
)
fwt[t][
'total'
].add(i, y)
fwt[t][
'total'
].add(j,
-
z)
current[t][x]
=
y
buf.append(ans)
print
(
'\n'
.join(
map
(
str
, buf)))