#include <stdio.h>                                                                                                                                                                                        
#include <stdlib.h>                                                                                                                                                                                       
#include <string.h>                                                                         
                                                                                            
int main(void)                                                                              
{                                                                                           
        int max_x, max_y, num, now_x = 0, now_y = 0, i, ans;                                
        int **point, *mode;                                                             
                                                                                        
        scanf("%d %d %d", &max_x, &max_y, &num);                                        
                                                                                        
        point = calloc(sizeof(int *), num);                                             
        mode = calloc(sizeof(int), num);                                                
                                                                                        
        for (i = 0; i < num; i++) {                                                     
                point[i] = calloc(sizeof(int), 2);                                      
                scanf("%d %d %d", &point[i][0], &point[i][1], &mode[i]);                
        }                                                                               
                                                                                        
        for (i = 0; i < num; i++) {                                                     
                if (mode[i] == 1) {                                                     
                        now_x = now_x < point[i][0] ? point[i][0] : now_x;              
                } else if (mode[i] == 2) {                                              
                        max_x = max_x < point[i][0] ? max_x : point[i][0];              
                } else if (mode[i] == 3) {                                               
                        now_y = now_y < point[i][1] ? point[i][1] : now_y;              
                } else if (mode[i] == 4) {                                              
                        max_y = max_y < point[i][1] ? max_y : point[i][1];              
                }                                                                       
        }                                                                               
                                                                                        
        if ((max_x - now_x) < 0 || (max_y - now_y) < 0) {                               
                ans = 0;                                                                
        } else {                                                                        
                ans = (max_x - now_x) * (max_y - now_y);                                
        }                                                                               
        printf("%d\n", ans);                                                            
        return 0;                                                                       
}

Measured memory_bytes: 128