답안 #299857

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
299857 2020-09-15T21:27:24 Z mohamedsobhi777 별들과 삼각형 (IZhO11_triangle) C++14
100 / 100
412 ms 12380 KB
#include<bits/stdc++.h>

/*
#pragma GCC optimize("-Ofast")
//#pragma GCC optimize("trapv")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")*/

#define I inline void 
#define S struct 
#define vi vector<int> 
#define vii vector<pair<int,int>>
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std ; 
using ll = long long ; 
using ld = long double ; 

const int N = 5e5 + 7 , mod = 1e9 + 7 ; 
const int inf = N ; 
// How interesting!

int n; 
map<int,int> oxx ;
map<int,int> sumx ;  

int main(){
        ios_base::sync_with_stdio(0) ; 
        cin.tie(0) ;

        int n ;
        cin >> n; 

        vector<pair<int,int>> v ;
        for(int i = 0 ;i < n;i++){
                int x , y; 
                cin >> x >> y ;
                v.push_back({y , x}) ;
                oxx[x] ++ ;
        }

        sort(v.begin() , v.end()) ;

        int ly = -2e9 ; 
        ll sum = 0 ;
        ll ans = 0 ; 
        for(int i = 0 ; i < n; i ++){   
                if(ly == v[i].first){
                        ans += sumx[v[i].first] ;
                }  
                sumx[v[i].first] += oxx[v[i].second] -1 ; 
                ly = v[i].first ; 
        }
        sumx.clear() ;
        ly = -2e9 ; 

        for(int i = 0 ;i < n;i ++ )
                v[i].second *= -1 ;
        sort(v.begin() , v.end()) ;

        for(int i = 0 ; i < n; i ++){   
                if(ly == v[i].first){
                        ans += sumx[v[i].first] ;
                }  
                sumx[v[i].first] += oxx[-v[i].second] - 1 ; 
                ly = v[i].first ; 
        }

        cout<< ans; 
        return 0 ; 
}

Compilation message

triangle.cpp: In function 'int main()':
triangle.cpp:47:12: warning: unused variable 'sum' [-Wunused-variable]
   47 |         ll sum = 0 ;
      |            ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 7 ms 1024 KB Output is correct
13 Correct 10 ms 1044 KB Output is correct
14 Correct 12 ms 1400 KB Output is correct
15 Correct 132 ms 6252 KB Output is correct
16 Correct 144 ms 6504 KB Output is correct
17 Correct 138 ms 6252 KB Output is correct
18 Correct 131 ms 6248 KB Output is correct
19 Correct 368 ms 11880 KB Output is correct
20 Correct 263 ms 9444 KB Output is correct
21 Correct 403 ms 12252 KB Output is correct
22 Correct 412 ms 12380 KB Output is correct