Search
Duplicate

좌표 압축

주차
0
문제번호
18870
언어
C++
티어
실버
유형
정렬
nj_Blog
nj_상태
이해도
풀이
사람
이해도 2
13 more properties

Code

제출 날짜

@5/25/2021

메모리

39540 KB

시간

1300 ms
#include <iostream> #include <algorithm> #include <map> int N; int X[1000001]; int X_[1000001]; void io_faster() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); } void input() { io_faster(); std::cin >> N; for (int i = 0 ; i < N ; i++) { std::cin >> X[i]; X_[i] = X[i]; } } void solve() { int val = 0, tmp; std::map<int, int> m; std::sort(X, X + N); tmp = X[0]; m[tmp] = 0; for (int i = 0 ; i < N ; i++) { if (X[i] == tmp) continue; val++; m[X[i]] = val; tmp = X[i]; } for (int i = 0 ; i < N ; i++) std::cout << m[X_[i]] << " "; } int main() { input(); solve(); return (0); }
C++
복사