Lang:G++
Edit12345678910111213141516171819202122232425262728293031#include<iostream>#include<cstdio>#include<map>#include<vector>using namespace std;const int maxn = 1000;int a[maxn+5];int n;// we have first < secondmap<int, vector<pair<int,int> > > position;long long compute(vector<pair<int, int> > pairs) {// sort by the first element, into different groups// then the answer is just the multiplication of different group size - invalid pairs// the number of invalid pairs is the one with the same second elementmap<pair<int, int>, int> y2count; // map[y][group]map<pair<int, int>, int> x2count; // map[x][group]vector<int> last; // index of last element of group iint group = 0;for (int i = 0; i < pairs.size(); ++i) {if (i > 0 && pairs[i].first != pairs[i-1].first) {group++;last.push_back(i);}x2count[{pairs[i].first, group}] ++;y2count[{pairs[i].second, group}] ++;}last.push_back(pairs.size());