数据离散化(unique)

离散化详解

unique用法

#include
using namespace std;
#define pi acos(-1)
#define mod 998244353
#define INF 0x3f3f3f
#define fi first
#define se second
#define it iterator
#define ins insert
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define ll long long
#define ull unsigned long long
#define mem(a) memset(a,0,sizeof(a))
#define cio ios::sync_with_stdio(false)
#define gcd __gcd
ll lgcd(ll a,ll b){return b == 0? a:lgcd(b, a % b);}
int lowbit(int x){return x&(-x);}
#define T int t;scanf("%d",&t);while(t--)
#define CE cout << endl
#define C(n) cout << n << endl
#define CY cout << "YES" << endl
#define CN cout << "NO" << endl
#define Cy cout << "Yes" << endl
#define Cn cout << "No" << endl

int a[50010];
int b[50010];

int main()
{
    int n;
    while(cin>>n){
        mem(a);
        mem(b);
        for(int i = 1; i <= n; i++){
            cin >> a[i];
            b[i] = a[i];
        }
        sort(b+1,b+n+1);
        int m = unique(b+1,b+n+1)-b-1;
        for(int i = 1; i <= n; i++){
            a[i] = lb(b+1,b+m+1,a[i])-b;
        }
        for(int i = 1; i <= n; i++){
            cout << a[i] << " ";
        }
        CE;
    }
    return 0;   
}

你可能感兴趣的:(模板)