Submission #499692

#TimeUsernameProblemLanguageResultExecution timeMemory
499692PoPularPlusPlusStar triangles (IZhO11_triangle)C++17
100 / 100
182 ms11244 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define pb(e) push_back(e) #define sv(a) sort(a.begin(),a.end()) #define sa(a,n) sort(a,a+n) #define mp(a,b) make_pair(a,b) #define vf first #define vs second #define ar array #define all(x) x.begin(),x.end() const int inf = 0x3f3f3f3f; const ll mod = 998244353 ; const double PI=3.14159265358979323846264338327950288419716939937510582097494459230; bool remender(ll a , ll b){return a%b;} bool cmp(pair<int,int> a ,pair<int,int> b){ return a.vs < b.vs; } void solve(){ int n; cin >> n; vector<pair<int,int>> v; for(int i = 0; i < n; i++){ int x , y; cin >> x >> y; v.pb(mp(x,y)); } sort(all(v) , cmp); ll ans = 0; map<int,ll> m; for(int i = 0; i < n; i++){ ll cnt = 1; int j = i + 1; while(j < n && v[j].vs == v[i].vs){ j++; cnt++; } i = j - 1; m[v[i].vs] = cnt; } sv(v); for(int i = 0; i < n; i++){ ll cnt = 1; int j = i + 1; while(j < n && v[j].vf == v[i].vf){ j++; cnt++; } for(int k = i; k < j; k++){ ans += (cnt - 1LL) * (m[v[k].vs]-1LL); } i = j - 1; } cout << ans << '\n'; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); //freopen("rblock.in", "r", stdin); //freopen("rblock.out", "w", stdout); //int t;cin >> t;while(t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...