-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy path18870.cpp
More file actions
38 lines (34 loc) · 848 Bytes
/
Copy path18870.cpp
File metadata and controls
38 lines (34 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright@2023 Jihoon Lucas Kim <jihoon.lucas.kim@gmail.com>
// 좌표 압축
// https://www.acmicpc.net/problem/18870
// 힌트
// 1.X원 소 중 중복을 제외하고 오름차순으로 정렬된 새로운 vector를 구한다.
// 2. 이 vector값의 작은 수부터 0부터 시작하는 좌표 값을 mapping 해준다.
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int main()
{
int N;
cin >> N;
vector<int> X(N);
for (int i = 0; i < N; i++)
{
cin >> X[i];
}
vector<int> X2 = X;
sort(X2.begin(), X2.end());
X2.erase(unique(X2.begin(), X2.end()), X2.end());
map<int, int> m;
for (int i = 0; i < X2.size(); i++)
{
m[X2[i]] = i;
}
for (int i = 0; i < N; i++)
{
cout << m[X[i]] << " ";
}
return 0;
}