-
Notifications
You must be signed in to change notification settings - Fork 0
/
poj1656-black.c
96 lines (84 loc) · 1.27 KB
/
poj1656-black.c
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
#include <stdio.h>
#include <string.h>
#define N 100
int t, x, y, l;
int color[101][101];
int sum[101][101];
char cmd[10];
int
lowbit(int x)
{
return x & (-x);
}
void
update(int x, int y, int c)
{
int i, j;
color[x][y] = c;
for (i = x; i <= N; i += lowbit(i))
{
for (j = y; j <= N; j += lowbit(j))
{
if (c == 0) sum[i][j]--;
else sum[i][j]++;
}
}
}
int
getsum(int x, int y)
{
int i, j;
int result = 0;
for (i = x; i > 0; i -= lowbit(i))
{
for (j = y; j > 0; j -= lowbit(j))
{
result += sum[i][j];
}
}
return result;
}
int
main()
{
int i, j;
for (i = 0; i <= N; i++)
{
for (j = 0; j <= N; j++)
{
color[i][j] = 0;
sum[i][j] = 0;
}
}
scanf("%d", &t);
while (t--)
{
scanf("%s", cmd);
scanf("%d %d %d", &x, &y, &l);
if (strcmp(cmd, "BLACK") == 0)
{
for (i = x; i <= x + l - 1; i++)
{
for (j = y; j <= y + l - 1; j++)
{
if (color[i][j] == 0) update(i, j, 1);
}
}
}
else if (strcmp(cmd, "WHITE") == 0)
{
for (i = x; i <= x + l - 1; i++)
{
for (j = y; j <= y + l - 1; j++)
{
if (color[i][j] == 1) update(i, j, 0);
}
}
}
else
{
printf("%d\n", getsum(x + l - 1, y + l - 1) - getsum(x + l - 1, y - 1) - getsum(x - 1, y + l - 1) + getsum(x - 1, y - 1));
}
}
return 0;
}