[๋ฐฑ์ค] 18870 ์ขํ ์์ถ
๋ฌธ์ :
18870๋ฒ: ์ขํ ์์ถ
์์ง์ ์์ N๊ฐ์ ์ขํ X1, X2, ..., XN์ด ์๋ค. ์ด ์ขํ์ ์ขํ ์์ถ์ ์ ์ฉํ๋ ค๊ณ ํ๋ค. Xi๋ฅผ ์ขํ ์์ถํ ๊ฒฐ๊ณผ X'i์ ๊ฐ์ Xi > Xj๋ฅผ ๋ง์กฑํ๋ ์๋ก ๋ค๋ฅธ ์ขํ์ ๊ฐ์์ ๊ฐ์์ผ ํ๋ค. X1, X2, ..., XN์ ์ข
www.acmicpc.net
๋ถ์ :
์ขํ ์์ถ์ ์์ง์ ์ ๋์ ๋ฒ์์ ๋นํด ์ ์ ์ ์ ์ฐ๋ ๊ฒ์ด ๋นํจ์จ์ ์ด๋ผ๋ ์ ์์ ๊ณ ์ํ ๊ธฐ์ ์ด๋ค. ( ์ ๋ธ๋ก๊ทธ๋ฅผ ์ฐธ๊ณ ํ์๋ค.)
์ ์ ์ขํ๋ฅผ ์ธ๋ฑ์ฑํ์ฌ ์ ๋ ฌ๋ ์์๋ก ๋ฒํธ๋ฅผ ๋งค๊ธฐ๋ ๋ฐฉ์์ด๋ค.
unique :
ex > unique(index.begin(), index.end())
index ๋ผ๋ ๋ฒกํฐ์ ์ฒ์๋ถํฐ ๋๊น์ง ์ค๋ณต๋์ง ์๊ฒ ์์๋ฅผ ์ฌ๋ฐฐ์ดํ๋ค.
๋ง์ฝ ๋ฒกํฐ ์์
- 10, 2, 4, 4, 9 ๊ฐ ์๋ค๋ฉด -10, 2, 4, 9 ๋ก ๋ง๋ ๋ค !! ๋ค์๋ ๋ฌด์จ ๋ค๋ฅธ ์ซ์๊ฐ ๋ถ๋ ๊ฑฐ ๊ฐ์๋ฐ ์ดํด๊ฐ ์ ๋์ง ์๋ ๋ถ๋ถ ..
lower_bound :
ex> lower_bound(index.begin(), index.end(), c)
index ๋ผ๋ ๋ฒกํฐ์ ์ฒ์๋ถํฐ ๋๊น์ง ์ค์ ๊ฐ์ด c ์ด์์ธ ์ธ๋ฑ์ค๋ฅผ ์ฐพ๋๋ค.
upper_bound :
ex> upper_bound(index.begin(), index.end(), c)
index ๋ผ๋ ๋ฒกํฐ์ ์ฒ์๋ถํฐ ๋๊น์ง ์ค์ ๊ฐ์ด c๊ฐ ์ด๊ณผ๋๋ ์ธ๋ฑ์ค๋ฅผ ์ฐพ๋๋ค.
c++ ์ฝ๋ :
//
// 18870_cc.cpp
// SOMA๐ฉ๐ป๐ป
//
// Created by JoSoJeong on 2021/02/18.
//
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int N;
cin >> N;
vector<int> index(N);
vector<int> points(N);
for(int i = 0; i < N; i ++){
cin >> index.at(i);
points.at(i) = index.at(i);
}
sort(index.begin(), index.end());
index.erase(unique(index.begin(), index.end()), index.end());
for(auto& c : points){
cout << lower_bound(index.begin(), index.end(), c) - index.begin() << " ";
}
cout << endl;
return 0;
}