Submission #207031

# Submission time Handle Problem Language Result Execution time Memory
207031 2020-03-06T07:04:15 Z pavement Star triangles (IZhO11_triangle) C++17
100 / 100
337 ms 48248 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

int N, C, X[300005], Y[300005], CX[300005], CY[300005];
pair<int, int> TX[300005], TY[300005];
vector<int> XC[300005], YC[300005];

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> X[i] >> Y[i];
		TX[i] = make_pair(X[i], i);
		TY[i] = make_pair(Y[i], i);
	}
	sort(TX + 1, TX + 1 + N);
	sort(TY + 1, TY + 1 + N);
	for (int i = 1, c = 1; i <= N; i++) {
		CX[TX[i].second] = c;
		c += (TX[i].first != TX[i + 1].first);
	}
	for (int i = 1, c = 1; i <= N; i++) {
		CY[TY[i].second] = c;
		c += (TY[i].first != TY[i + 1].first);
	}
	for (int i = 1; i <= N; i++) {
		XC[CX[i]].push_back(CY[i]);
		YC[CY[i]].push_back(CX[i]);
	}
	for (int i = 1; i <= N; i++) {
		sort(XC[i].begin(), XC[i].end());
		sort(YC[i].begin(), YC[i].end());
	}
	for (int i = 1; i <= N; i++) {
		auto it = upper_bound(YC[CY[i]].begin(), YC[CY[i]].end(), CX[i]), it2 = upper_bound(XC[CX[i]].begin(), XC[CX[i]].end(), CY[i]), it3 = lower_bound(YC[CY[i]].begin(), YC[CY[i]].end(), CX[i]), it4 = lower_bound(XC[CX[i]].begin(), XC[CX[i]].end(), CY[i]);
		C += (YC[CY[i]].size() - (it - YC[CY[i]].begin())) * (XC[CX[i]].size() - (it2 - XC[CX[i]].begin()));
		C += (YC[CY[i]].size() - (it - YC[CY[i]].begin())) * (it4 - XC[CX[i]].begin());
		C += (it3 - YC[CY[i]].begin()) * (XC[CX[i]].size() - (it2 - XC[CX[i]].begin()));
		C += (it3 - YC[CY[i]].begin()) * (it4 - XC[CX[i]].begin());
	}
	cout << C << '\n';
}

Compilation message

triangle.cpp:9:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
# Verdict Execution time Memory Grader output
1 Correct 14 ms 14456 KB Output is correct
2 Correct 13 ms 14456 KB Output is correct
3 Correct 14 ms 14456 KB Output is correct
4 Correct 14 ms 14456 KB Output is correct
5 Correct 14 ms 14456 KB Output is correct
6 Correct 14 ms 14456 KB Output is correct
7 Correct 14 ms 14456 KB Output is correct
8 Correct 14 ms 14456 KB Output is correct
9 Correct 15 ms 14456 KB Output is correct
10 Correct 14 ms 14584 KB Output is correct
11 Correct 14 ms 14584 KB Output is correct
12 Correct 23 ms 15480 KB Output is correct
13 Correct 23 ms 15480 KB Output is correct
14 Correct 20 ms 15608 KB Output is correct
15 Correct 105 ms 24052 KB Output is correct
16 Correct 116 ms 24956 KB Output is correct
17 Correct 103 ms 23992 KB Output is correct
18 Correct 104 ms 23996 KB Output is correct
19 Correct 296 ms 39908 KB Output is correct
20 Correct 207 ms 37176 KB Output is correct
21 Correct 333 ms 48248 KB Output is correct
22 Correct 337 ms 48248 KB Output is correct