Submission #924847

# Submission time Handle Problem Language Result Execution time Memory
924847 2024-02-09T22:41:37 Z Karoot Star triangles (IZhO11_triangle) C++17
100 / 100
1251 ms 87456 KB
#include <iostream>
#include <cmath>
#include <unordered_map>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <string>
#include <iomanip>
#include <algorithm>

#define all(x)  (x).begin(), (x).end()
#define rall(x)  (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;

ll linf = 1e15+1;

inline void scoobydoobydoo(){
    ios::sync_with_stdio(false);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
}

unordered_map<ll, set<ll>> yM;
unordered_map<ll, set<ll>> xM;

map<pair<ll, ll>, ll> yToI;
map<pair<ll, ll>, ll> xToI;

int main(){
    scoobydoobydoo();
    ll n; cin >> n;
    vector<pair<ll, ll> > v(n);
    for (ll i = 0; i < n; i++){
        ll x, y; cin >> x >> y;
        yM[y].insert(x);
        xM[x].insert(y);
        v[i] = {x, y};
    }


    for (auto p : yM){
        ll counter = 0;
        for (ll x : p.second){
            yToI[{p.first, x}] = counter++;
        }
    }

    for (auto p : xM){
        ll counter = 0;
        for (ll x : p.second){
            xToI[{p.first, x}] = counter++;
        }
    }
    ll tot = 0;

    for (ll i = 0; i < n; i++){
        ll x = v[i].first;
        ll y = v[i].second;
        auto biggerYPtr = yM[y].lower_bound(x);
        ll smallerY = yToI[{x, *biggerYPtr}];
        ll biggerY = yM[y].size()-smallerY-1;
        auto biggerXPtr = xM[x].lower_bound(y);
        ll smallerX = xToI[{y, *biggerXPtr}];
        ll biggerX = xM[x].size()-smallerX-1;
        //cout << x << " " << y << endl;
        //cout << smallerX << " " << biggerX << " " << smallerY << " " << biggerY << endl;
        tot += smallerX*smallerY;
        tot += smallerX*biggerY;
        tot += biggerX*smallerY;
        tot += biggerX*biggerY;
    }   


    cout << tot << endl;



    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 16 ms 4444 KB Output is correct
13 Correct 14 ms 4320 KB Output is correct
14 Correct 17 ms 5468 KB Output is correct
15 Correct 260 ms 35308 KB Output is correct
16 Correct 308 ms 37900 KB Output is correct
17 Correct 268 ms 35340 KB Output is correct
18 Correct 252 ms 35340 KB Output is correct
19 Correct 1145 ms 81328 KB Output is correct
20 Correct 675 ms 61572 KB Output is correct
21 Correct 1216 ms 87456 KB Output is correct
22 Correct 1251 ms 87044 KB Output is correct