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
#include <stdio.h>
#include <vector>
using namespace std;

struct car {
  unsigned int position = 1, time = 0, index = 0;
};

car* createCar(unsigned int position, unsigned int time) {
  car* temp = new car;
  temp->position = position;
  temp->time = time;
  temp->index = time - position + 1000000;
  return temp;
}

unsigned int rows[2000002];
unsigned int cols[2000002];
vector<unsigned int> rowsv;

int main(int argc, char const *argv[]) {
  unsigned int i, j,carsNum, type, position, time, result = 0;
  if (!scanf("%d\n", &carsNum)) return 1;

  for (i = 0; i < 2000002; ++i) {
    rows[i] = cols[i] = 0;
  }

  for (i = 0; i < carsNum; ++i) {
    if (!scanf("%d %d %d", &type, &position, &time)) return 1;

    car* temp = createCar(position, time);
    // printf("%d %d %d %d %d\n", i, type, position, time, temp->index);

    if (type == 1) {
      ++cols[temp->index];
    } else if (type == 2) {
      ++rows[temp->index];
      if (rows[temp->index] == 1) {
        rowsv.push_back(temp->index);
      }
    }
  }

  for (i = 0; i < rowsv.size(); ++i) {
    unsigned int index = rowsv[i];
    if (rows[index] > 0 && cols[index] > 0) {
      result += rows[index] > cols[index] ? cols[index] : rows[index];
    }
  }

  printf("%d", result);
  return 0;
}