# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
33044 | 2017-10-19T07:16:01 Z | chonka | 별들과 삼각형 (IZhO11_triangle) | C++ | 396 ms | 10292 KB |
#include<iostream> #include<stdio.h> #include<vector> #include<algorithm> #include<map> using namespace std ; #define MAXN 300007 int n ; pair < int , int > a[ MAXN ] ; map < int , int > ZX ; int h[ MAXN ] ; int v[ MAXN ] ; void compress ( ) { vector < int > srt ; srt.clear ( ) ; int i ; for ( i = 1 ; i <= n ; i ++ ) { srt.push_back ( a[ i ].first ) ; } sort ( srt.begin ( ) , srt.end ( ) ) ; int id = 1 ; ZX.clear ( ) ; ZX[ srt[ 0 ] ] = 1 ; for ( i = 1 ; i < n ; i ++ ) { if ( srt[ i ] == srt[ i - 1 ] ) { continue ; } id ++ ; ZX[ srt[ i ] ] = id ; } for ( i = 1 ; i <= n ; i ++ ) { a[ i ].first = ZX[ a[ i ].first ] ; v[ a[ i ].first ] ++ ; } srt.clear ( ) ; ZX.clear ( ) ; id = 1 ; for ( i = 1 ; i <= n ; i ++ ) { srt.push_back ( a[ i ].second ) ; } sort ( srt.begin ( ) , srt.end ( ) ) ; ZX[ srt[ 0 ] ] = 1 ; for ( i = 1 ; i < n ; i ++ ) { if ( srt[ i ] == srt[ i - 1 ] ) { continue ; } id ++ ; ZX[ srt[ i ] ] = id ; } for ( i = 1 ; i <= n ; i ++ ) { a[ i ].second = ZX[ a[ i ].second ] ; h[ a[ i ].second ] ++ ; } } void input ( ) { scanf ( "%d" , &n ) ; int i ; for ( i = 1 ; i <= n ; i ++ ) { scanf ( "%d%d" , &a[ i ].first , &a[ i ].second ) ; } compress ( ) ; } void solve ( ) { long long ans = 0 ; int i ; for ( i = 1 ; i <= n ; i ++ ) { ans += 1LL * ( v[ a[ i ].first ] - 1 ) * ( h[ a[ i ].second ] - 1 ) ; } printf ( "%lld\n" , ans ) ; } int main ( ) { input ( ) ; solve ( ) ; return 0 ; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 6712 KB | Output is correct |
2 | Correct | 0 ms | 6712 KB | Output is correct |
3 | Correct | 0 ms | 6712 KB | Output is correct |
4 | Correct | 0 ms | 6712 KB | Output is correct |
5 | Correct | 0 ms | 6712 KB | Output is correct |
6 | Correct | 0 ms | 6712 KB | Output is correct |
7 | Correct | 0 ms | 6712 KB | Output is correct |
8 | Correct | 0 ms | 6712 KB | Output is correct |
9 | Correct | 0 ms | 6712 KB | Output is correct |
10 | Correct | 0 ms | 6712 KB | Output is correct |
11 | Correct | 0 ms | 6712 KB | Output is correct |
12 | Correct | 6 ms | 7248 KB | Output is correct |
13 | Correct | 9 ms | 6984 KB | Output is correct |
14 | Correct | 9 ms | 7248 KB | Output is correct |
15 | Correct | 109 ms | 8756 KB | Output is correct |
16 | Correct | 136 ms | 8756 KB | Output is correct |
17 | Correct | 123 ms | 8756 KB | Output is correct |
18 | Correct | 129 ms | 8756 KB | Output is correct |
19 | Correct | 343 ms | 10292 KB | Output is correct |
20 | Correct | 233 ms | 9268 KB | Output is correct |
21 | Correct | 396 ms | 10292 KB | Output is correct |
22 | Correct | 343 ms | 10292 KB | Output is correct |