Submission #1085575

#TimeUsernameProblemLanguageResultExecution timeMemory
1085575SunbaeStar triangles (IZhO11_triangle)C++17
100 / 100
208 ms11860 KiB
#include <bits/stdc++.h>
typedef long long ll;
#define mp make_pair
#define F first
#define S second
using namespace std;
using pii = pair<int,int>;
const int N = 3e5 + 5;
pii p[N];
int cp[2][N], m[2];
ll cnt[2][N];
int pos(int t, int x){ return lower_bound(cp[t], cp[t]+m[t], x) - cp[t];}
signed main(){
	int n; scanf("%d", &n);
	for(int i = 0, x, y; i<n; ++i){
		scanf("%d %d", &x, &y);
		p[i] = mp(x, y);
		cp[0][m[0]++] = x;
		cp[1][m[1]++] = y;
	}
	for(int j = 0; j<2; ++j) sort(cp[j], cp[j]+m[j]), m[j] = unique(cp[j], cp[j]+m[j]) - cp[j];
	for(int i = 0; i<n; ++i) ++cnt[0][pos(0, p[i].F)], ++cnt[1][pos(1, p[i].S)];
	ll tot = 0;
	for(int i = 0; i<n; ++i){
		int x = pos(0, p[i].F), y = pos(1, p[i].S);
		tot += (cnt[0][x] - 1) * (cnt[1][y] - 1);
	}
	printf("%lld", tot);
}

Compilation message (stderr)

triangle.cpp: In function 'int main()':
triangle.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  int n; scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
triangle.cpp:16:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |   scanf("%d %d", &x, &y);
      |   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...