-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path18870bj.cpp
More file actions
52 lines (45 loc) · 1021 Bytes
/
18870bj.cpp
File metadata and controls
52 lines (45 loc) · 1021 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n;
//n=100만 => O(nlogn)허용
//n=5000 => O(n^2) 허용
int X[1000005];
vector<int> tmp,X2; //정렬 담을 배열 과 중복 제거된 배열 담을 배열
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> X[i];
//tmp.push_back(X[i]);
X2.push_back(X[i]);
}
sort(X2.begin(), X2.end());
//unique(): 중복 제거된 원소들 모아주고 다음 값 itertator 가리켜 by STL
//erase() : first ,Last 쓰레기값 원소 제거
X2.erase(unique(X2.begin(), X2.end()) , X2.end());
/*
//정렬
sort(tmp.begin(), tmp.end());
//int cnt = 0;
//중복제거
for (int i = 0; i < n; i++) {
if (i != 0&& tmp[i - 1] == tmp[i])
{
//cnt++;
;
}
else {
//cnt = 1;
X2.push_back(tmp[i]);
}
}
*/
//X2[] 인덱스 자체가 Xi>Xj 만족하는 개수와 같음
for (int i = 0; i < n; i++) {
cout << lower_bound(X2.begin(),X2.end(),X[i])-X2.begin()<<' ';
}
return 0;
}