forked from Prince-1501/Hello_world-Competiitve-Programming
-
Notifications
You must be signed in to change notification settings - Fork 1
/
59_codechef_operations_on_a_matrix.cpp
68 lines (63 loc) · 1.46 KB
/
59_codechef_operations_on_a_matrix.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
//
// main.cpp
// bbcfjc
//
// Created by Prince Kumar on 06/10/19.
// Copyright © 2019 Prince Kumar. All rights reserved.
//
// ***-- October Long Challeneg 2019 --***
/ ***-- Operations on a Matrix --****
#include <iostream>
#include <cstring>
#include <string>
#include <string.h>
#define ll long long
using namespace std;
int main()
{
ll int T; cin>>T;
while(T--)
{
ll int n,m,q;cin>>n>>m>>q;
ll int a[n+1]; memset(a,0,sizeof(a)); // row
ll int c[m+1]; memset(c,0,sizeof(c)); // column
for(ll int i=0;i<q;i++)
{
ll int a1, a2;cin>>a1>>a2;
a[a1]++; c[a2]++;
}
ll int odd=0,even=0,a_zero=0;
for(ll int i=1;i<=n;i++)
{// row
if(a[i]>0)
{
if(a[i]%2!=0)
odd++;
else
even++;
}
else
a_zero++;
}
// for column
ll int count=0;
for(ll int i=1;i<=m;i++)
{
if(c[i]>0)
{
if(c[i]%2!=0)
{
count+=even+a_zero;
}
else
{
// even
count+=odd;
}
}
else
count+=odd;
}
cout<<count<<endl;
}
}