#include <stdio.h>
#include <stdlib.h>
#define null 0
typedef struct {
int x1;
int y1;
int x2;
int y2;
} twoCell;
typedef struct {
int x;
int y;
} oneCell;
typedef struct {
long groupId;
long numVoltage;
} cell;
int charToInt(char c) {
int i;
switch (c) {
case 'A':
i=0;
break;
case 'B':
i=1;
break;
case 'C':
i=2;
break;
case 'D':
i=3;
break;
case 'E':
i=4;
break;
case 'F':
i=5;
break;
case 'G':
i=6;
break;
case 'H':
i=7;
break;
case 'I':
i=8;
break;
case 'J':
i=9;
break;
case 'K':
i=10;
break;
case 'L':
i=11;
break;
case 'M':
i=12;
break;
case 'N':
i=13;
break;
case '0':
i=14;
break;
case 'P':
i=15;
break;
case 'Q':
i=16;
break;
case 'R':
i=17;
break;
case 'S':
i=18;
break;
case 'T':
i=19;
break;
case 'U':
i=20;
break;
case 'V':
i=21;
break;
case 'W':
i=22;
break;
case 'X':
i=23;
break;
case 'Y':
i=24;
break;
case 'Z':
i=25;
break;
case 'a':
i=26;
break;
case 'b':
i=27;
break;
case 'c':
i=28;
break;
case 'd':
i=29;
break;
case 'e':
i=30;
break;
case 'f':
i=31;
break;
case 'g':
i=32;
break;
case 'h':
i=33;
break;
case 'i':
i=34;
break;
case 'j':
i=35;
break;
case 'k':
i=36;
break;
case 'l':
i=37;
break;
case 'm':
i=38;
break;
case 'n':
i=39;
break;
case 'o':
i=40;
break;
case 'p':
i=41;
break;
case 'q':
i=42;
break;
case 'r':
i=43;
break;
case 's':
i=44;
break;
case 't':
i=45;
break;
case 'u':
i=46;
break;
case 'v':
i=47;
break;
case 'w':
i=48;
break;
case 'x':
i=49;
break;
case 'y':
i=50;
break;
case 'z':
i=51;
break;
}
return i;
}
int base52(char msbChar, char lsbChar) {
int retVal;
int msb, lsb;
msb = charToInt(msbChar);
lsb = charToInt(lsbChar);
retVal = 52 * msb + lsb;
//printf (" base52 %c %c %d\n", msbChar, lsbChar, retVal);
return retVal;
}
twoCell * readTwoCell(char str[]) {
twoCell* retVal = (twoCell*)malloc(sizeof(twoCell));
int x1, x2, x3, x4;
retVal->x1 = base52(str[0], str[1]);
retVal->y1 = base52(str[2], str[3]);
retVal->x2 = base52(str[4], str[5]);
retVal->y2 = base52(str[6], str[7]);
return retVal;
}
oneCell* readOneCell(char str[]) {
oneCell* retVal = (oneCell*)malloc(sizeof(oneCell));
retVal->x = base52(str[0], str[1]);
retVal->y = base52(str[2], str[3]);
return retVal;
}
void print_board(cell ** board, int r, int c, long groups[], long groupIdToGroup[], long numGroupIds, long numGroups) {
int i;
int j;
long currNumVoltage;
long currGroupId;
long currGroup;
long currGroupVoltage;
printf("Printing Board \n");
printf("numGroupIds %ld numGroups %ld \n", numGroupIds, numGroups);
printf("Printing Board On/Off\n");
for(i=0;i<r;i++) {
for(j=0;j<c;j++) {
currNumVoltage = board[i][j].numVoltage;
if (currNumVoltage > 0)
printf("1");
else {
currGroupId = board[i][j].groupId;
if (currGroupId != -1) {
currGroup = groupIdToGroup[currGroupId];
currGroupVoltage = groups[currGroup];
if (currGroupVoltage > 0)
printf("1");
else
printf("0");
}
else
printf("0");
}
}
printf("\n");
}
printf("Printing Board GroupIds\n");
for(i=0;i<r;i++) {
for(j=0;j<c;j++) {
currGroupId = board[i][j].groupId;
printf("%ld", currGroupId);
}
printf("\n");
}
printf("\n");
printf("Printing GroupIds to Groups\n");
for(i=0;i<numGroupIds;i++) {
currGroup = groupIdToGroup[i];
printf("%ld ", currGroup);
}
printf("\n");
printf("Printing Group Voltages \n");
for(i=0;i<numGroups;i++) {
currNumVoltage = groups[i];
printf("%ld ", currNumVoltage);
}
printf("\n");
}
void handleW(cell ** board, int r, int c, int x1, int y1, int x2, int y2, long groups[], long &numGroups, long &numGroupId, long groupIdToGroup[]) {
long groupVoltage1, groupVoltage2;
long groupId1, groupId2, newGroupId;
long group1, group2, newGroup;
long totalGroupVoltage;
long numVoltage, numVoltage1, numVoltage2;
if ( (x1 == x2) && (y1 == y2))
return;
groupId1 = board[x1][y1].groupId;
groupId2 = board[x2][y2].groupId;
if(groupId1 == -1) {
group1 = -1;
}
else {
group1 = groupIdToGroup[groupId1];
}
if(groupId2 == -1) {
group2 = -1;
}
else {
group2 = groupIdToGroup[groupId2];
}
if (group1 != -1 && group2 != -1) {
if(group1 != group2) {
/* Find the smaller group */
if (group1 < group2) {
/* point the group ids for cell 2 to the smaller group */
groupIdToGroup[groupId2]=group1;
/* The voltage for smaller group is the sum of voltages for two groups */
numVoltage1 = groups[group1];
numVoltage2 = groups[group2];
totalGroupVoltage = numVoltage1 + numVoltage2;
groups[group1]=totalGroupVoltage;
}
else {
/* point the group ids for cell 1 to the smaller group */
groupIdToGroup[groupId1]=group2;
/* The voltage for smaller group is the sum of voltages for two groups */
numVoltage1 = groups[group1];
numVoltage2 = groups[group2];
totalGroupVoltage = numVoltage1 + numVoltage2;
groups[group2]=totalGroupVoltage;
}
}
}
else {
if (!((group1 == -1) && (group2 == -1))) {
if (group1 == -1) {
/* set groupId of node 1 to group 2 */
board[x1][y1].groupId = groupId2;
/*if cell 1 has voltage connected to it increment the voltage for group 2 */
numVoltage = board[x1][y1].numVoltage;
if (numVoltage > 0) {
numVoltage2 = groups[group2];
totalGroupVoltage = numVoltage + numVoltage2;
groups[group2] = totalGroupVoltage;
}
}
else {
/* set groupId of node2 to group1 */
board[x2][y2].groupId = groupId1;
/*if cell 2 has voltage connected to it increment the voltage for group 1 */
numVoltage = board[x2][y2].numVoltage;
if (numVoltage > 0) {
numVoltage1 = groups[group1];
totalGroupVoltage = numVoltage + numVoltage1;
groups[group1] = totalGroupVoltage;
}
}
}
else {
/* If both are not in a group create a groupId and a group */
newGroupId = numGroupId;
numGroupId++;
newGroup = numGroups;
numGroups++;
/* set new group id to new group */
groupIdToGroup[newGroupId] = newGroup;
/* The voltage of this group is the sum of numVoltages for two cell */
numVoltage1 = board[x1][y1].numVoltage;
numVoltage2 = board[x2][y2].numVoltage;
totalGroupVoltage = numVoltage1 + numVoltage2;
groups[newGroup] = totalGroupVoltage;
/* set group id for each cell to this new group id*/
board[x1][y1].groupId = newGroupId;
board[x2][y2].groupId = newGroupId;
}
}
return;
}
void handleV(cell **board, int r, int c, int x, int y, long groups[], long groupIdToGroup[]) {
long currNumVoltage, currGroupVoltage;
long currGroupId, currGroup;
/* increment num voltage for this cell*/
currNumVoltage = board[x][y].numVoltage;
board[x][y].numVoltage = currNumVoltage + 1;
//printf("handleV o/o board[%d][%d] numVoltage %ld \n", x, y, currNumVoltage + 1);
/* if the cell belongs to any group increment the voltage for that group */
currGroupId = board[x][y].groupId;
if (currGroupId != -1) {
currGroup = groupIdToGroup[currGroupId];
currGroupVoltage = groups[currGroup];
groups[currGroup] = currGroupVoltage + 1;
}
return;
}
void handleR(cell **board, int r, int c, int x, int y, long groups[], long groupIdToGroup[]) {
long currNumVoltage, currGroupVoltage;
long currGroupId, currGroup;
/* decrement num voltage for this cell*/
currNumVoltage = board[x][y].numVoltage;
board[x][y].numVoltage = currNumVoltage - 1;
/* if the cell belongs to any group decrement the voltage for that group */
currGroupId = board[x][y].groupId;
if (currGroupId != -1) {
currGroup = groupIdToGroup[currGroupId];
currGroupVoltage = groups[currGroup];
groups[currGroup] = currGroupVoltage - 1;
}
return;
}
void handleL(cell **board, int r, int c, int x1, int y1, int x2, int y2, long groups[], long groupIdToGroup[]) {
int cellVoltage1 = 0;
int cellVoltage2 = 0;
long numVoltage1, numVoltage2;
long group1, group2, groupId1, groupId2;
long groupVoltage1, groupVoltage2;
/* If the numVoltage of a cell is greater than 1 it is high */
numVoltage1 = board[x1][y1].numVoltage;
if(numVoltage1 > 0) {
cellVoltage1 = 1;
}
else {
/* If group voltage is greater than 1 it is high */
groupId1 = board[x1][y1].groupId;
if (groupId1 != -1) {
group1 = groupIdToGroup[groupId1];
groupVoltage1 = groups[group1];
if (groupVoltage1 > 0) {
cellVoltage1 = 1;
}
}
}
numVoltage2 = board[x2][y2].numVoltage;
if(numVoltage2 > 0) {
cellVoltage2 = 1;
}
else {
/* If group voltage is greater than 1 it is high */
groupId2 = board[x2][y2].groupId;
if (groupId2 != -1) {
group2 = groupIdToGroup[groupId2];
groupVoltage2 = groups[group2];
if (groupVoltage2 > 0) {
cellVoltage2 = 1;
}
}
}
if (cellVoltage1 != cellVoltage2) {
printf("ON\n");
}
else {
printf("OFF\n");
}
return;
}
int main() {
char str[9];
long n,x;
int r, c;
int i,j;
char op, ch;
oneCell * oc;
twoCell * tc;
cell **board;
scanf("%ld %d %d ", &n, &r, &c);
board = (cell**)malloc(sizeof(cell*)*r);
for(i=0;i<r;i++) {
board[i]=(cell*)malloc(sizeof(cell)*c);
}
long groups[1000000];
long groupIdToGroup[1000000];
long numGroups = 0;
long numGroupIds = 0;
for(i=0;i<r;i++) {
for(j=0;j<c;j++) {
board[i][j].groupId = -1;
board[i][j].numVoltage = 0;
}
}
for(x=0;x<n;x++) {
scanf("%c", &op);
switch (op) {
case 'W':
{
for(i=0;i<8;i++) {
scanf("%c", &ch);
str[i]=ch;
}
str[i]='\0';
scanf("%c", &ch);
while (ch != '\n')
scanf("%c", &ch);
break;
}
case 'V': {
for(i=0;i<4;i++) {
scanf("%c", &ch);
str[i]=ch;
}
str[i]='\0';
scanf("%c", &ch);
while (ch != '\n')
scanf("%c", &ch);
break;
}
case 'R': {
for(i=0;i<4;i++) {
scanf("%c", &ch);
str[i]=ch;
}
str[i]='\0';
scanf("%c", &ch);
while (ch != '\n')
scanf("%c", &ch);
break;
}
case 'L':
{
for(i=0;i<8;i++) {
scanf("%c", &ch);
str[i]=ch;
}
str[i]='\0';
scanf("%c", &ch);
while (ch != '\n')
scanf("%c", &ch);
break;
}
}
switch(op) {
case 'W': {
tc = readTwoCell(str);
//printf("W %d %d %d %d \n", tc->x1, tc->y1, tc->x2, tc->y2);
handleW(board, r, c, (tc->y1-1)/5, tc->x1-1, (tc->y2-1)/5, tc->x2-1, groups, numGroups, numGroupIds, groupIdToGroup);
free(tc);
//print_board(board, r, c, groups, groupIdToGroup, numGroupIds, numGroups);
break;
}
case 'V': {
oc = readOneCell(str);
//printf("V %d %d \n", oc->x, oc->y);
handleV(board, r, c, (oc->y-1)/5, oc->x-1, groups, groupIdToGroup);
free(oc);
//print_board(board, r, c, groups, groupIdToGroup, numGroupIds, numGroups);
break;
}
case 'R': {
oc = readOneCell(str);
//printf("R %d %d \n", oc->x, oc->y);
handleR(board, r, c, (oc->y-1)/5, oc->x-1, groups, groupIdToGroup);
//print_board(board, r,c, groups, groupIdToGroup, numGroupIds, numGroups);
free(oc);
break;
}
case 'L': {
tc = readTwoCell(str);
//printf("L %d %d %d %d \n", tc->x1, tc->y1, tc->x2, tc->y2);
handleL(board, r, c,(tc->y1-1)/5, tc->x1-1, (tc->y2-1)/5, tc->x2-1, groups, groupIdToGroup);
free(tc);
break;
}
default : {
break;
}
}
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCgojZGVmaW5lIG51bGwgMAoKCnR5cGVkZWYgc3RydWN0IHsKICAgIGludCB4MTsKCWludCB5MTsKCWludCB4MjsKCWludCB5MjsKfSB0d29DZWxsOwoKdHlwZWRlZiBzdHJ1Y3QgewoJaW50IHg7CglpbnQgeTsKfSBvbmVDZWxsOwoKCnR5cGVkZWYgc3RydWN0IHsKCWxvbmcgZ3JvdXBJZDsKCWxvbmcgbnVtVm9sdGFnZTsKfSBjZWxsOwoKCmludCBjaGFyVG9JbnQoY2hhciBjKSB7CglpbnQgaTsKCXN3aXRjaCAoYykgewoJCWNhc2UgJ0EnOgoJCQlpPTA7CgkJCWJyZWFrOwoJCWNhc2UgJ0InOgoJCQlpPTE7CgkJCWJyZWFrOwoJCWNhc2UgJ0MnOgoJCQlpPTI7CgkJCWJyZWFrOwoJCWNhc2UgJ0QnOgoJCQlpPTM7CgkJCWJyZWFrOwoJCWNhc2UgJ0UnOgoJCQlpPTQ7CgkJCWJyZWFrOwoJCWNhc2UgJ0YnOgoJCQlpPTU7CgkJCWJyZWFrOwoJCWNhc2UgJ0cnOgoJCQlpPTY7CgkJCW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Jc2NhbmYoIiVsZCAlZCAlZCAiLCAmbiwgJnIsICZjKTsKCWJvYXJkID0gKGNlbGwqKiltYWxsb2Moc2l6ZW9mKGNlbGwqKSpyKTsKCWZvcihpPTA7aTxyO2krKykgewoJCWJvYXJkW2ldPShjZWxsKiltYWxsb2Moc2l6ZW9mKGNlbGwpKmMpOwoJfQoJbG9uZyBncm91cHNbMTAwMDAwMF07Cglsb25nIGdyb3VwSWRUb0dyb3VwWzEwMDAwMDBdOwoJbG9uZyBudW1Hcm91cHMgPSAwOwoJbG9uZyBudW1Hcm91cElkcyA9IDA7Cglmb3IoaT0wO2k8cjtpKyspIHsKCQlmb3Ioaj0wO2o8YztqKyspIHsKCQkJYm9hcmRbaV1bal0uZ3JvdXBJZCA9IC0xOwoJCQlib2FyZFtpXVtqXS5udW1Wb2x0YWdlID0gMDsKCQl9Cgl9CgkKCWZvcih4PTA7eDxuO3grKykgewoJCXNjYW5mKCIlYyIsICZvcCk7CgkJc3dpdGNoIChvcCkgewogICAgICAgICAgICAgICAgICAgICAgICBjYXNlICdXJzoKICAgICAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZvcihpPTA7aTw4O2krKykgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2NhbmYoIiVjIiwgJmNoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN0cltpXT1jaDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc3RyW2ldPSdcMCc7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2NhbmYoIiVjIiwgJmNoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB3aGlsZSAoY2ggIT0gJ1xuJykKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNjYW5mKCIlYyIsICZjaCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KCQkJY2FzZSAnVic6IHsKCQkJCWZvcihpPTA7aTw0O2krKykgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2NhbmYoIiVjIiwgJmNoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN0cltpXT1jaDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc3RyW2ldPSdcMCc7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2NhbmYoIiVjIiwgJmNoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB3aGlsZSAoY2ggIT0gJ1xuJykKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNjYW5mKCIlYyIsICZjaCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CgkJCX0KCQkJY2FzZSAnUic6IHsKCQkJCWZvcihpPTA7aTw0O2krKykgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2NhbmYoIiVjIiwgJmNoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN0cltpXT1jaDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc3RyW2ldPSdcMCc7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2NhbmYoIiVjIiwgJmNoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB3aGlsZSAoY2ggIT0gJ1xuJykKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNjYW5mKCIlYyIsICZjaCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CgkJCX0KCQkJY2FzZSAnTCc6CiAgICAgICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmb3IoaT0wO2k8ODtpKyspIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNjYW5mKCIlYyIsICZjaCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdHJbaV09Y2g7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN0cltpXT0nXDAnOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNjYW5mKCIlYyIsICZjaCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGNoICE9ICdcbicpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzY2FuZigiJWMiLCAmY2gpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgc3dpdGNoKG9wKSB7CgkJCWNhc2UgJ1cnOiB7CgkJCQl0YyA9IHJlYWRUd29DZWxsKHN0cik7CgkJCQkvL3ByaW50ZigiVyAlZCAlZCAlZCAlZCBcbiIsIHRjLT54MSwgdGMtPnkxLCB0Yy0+eDIsIHRjLT55Mik7CgkJCQloYW5kbGVXKGJvYXJkLCByLCBjLCAodGMtPnkxLTEpLzUsIHRjLT54MS0xLCAodGMtPnkyLTEpLzUsIHRjLT54Mi0xLCBncm91cHMsIG51bUdyb3VwcywgbnVtR3JvdXBJZHMsIGdyb3VwSWRUb0dyb3VwKTsKCQkJCWZyZWUodGMpOwoJCQkJLy9wcmludF9ib2FyZChib2FyZCwgciwgYywgZ3JvdXBzLCBncm91cElkVG9Hcm91cCwgbnVtR3JvdXBJZHMsIG51bUdyb3Vwcyk7CgkJCQlicmVhazsKCQkJfQoJCQljYXNlICdWJzogewoJCQkJ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