(思维)Gym - 101669K

题意:1  2   2   1

           4  2   1    3

          以4开始的最长上升子序列长度为 1     ->  4

          以2开始的最长上升子序列长度为 2     ->  2   3

          以1开始的最长上升子序列长度为 2     ->  1   3

          以3开始的最长上升子序列长度为 1     ->  3

#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<bitset>
#include<iomanip>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define eps (1e-8)
#define MAX 0x3f3f3f3f
#define u_max 1844674407370955161
#define l_max 9223372036854775807
#define i_max 2147483647
#define re register
#define pushup() tree[rt]=tree[rt<<1]+tree[rt<<1|1]
#define nth(k,n) nth_element(a,a+k,a+n);  // 将 第K大的放在k位
#define ko() for(int i=2;i<=n;i++) s=(s+k)%i // 约瑟夫
#define ok() v.erase(unique(v.begin(),v.end()),v.end()) // 排序,离散化
#define Catalan C(2n,n)-C(2n,n-1)  (1,2,5,14,42,132,429...) // 卡特兰数
using namespace std;

inline int read(){
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' & c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}

typedef long long ll;
const double pi = atan(1.)*4.;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fLL;
const int M=63;
const int N=1e5+5;
vector<int>v;
int a[N],b[N];
struct fun{
    int x,y;
}f[N];

bool cmp(fun a,fun b){
    if(a.x!=b.x)
        return a.x<b.x;
    return a.y<b.y;
}
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) v.push_back(i);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        f[i].x=a[i];
        f[i].y=i;
    }
    sort(f+1,f+n+1,cmp);
    vector<int>::iterator it=v.begin();
    for(int i=1;i<=n;i++){
        int h=v.back();
        b[f[i].y]=h;
        v.pop_back();
    }
    int c=0;
    for(int i=1;i<=n;i++)
        printf(c++==0?"%d":" %d",b[i]);
    printf("\n");
    return 0;
}

猜你喜欢

转载自blog.csdn.net/black_horse2018/article/details/89060212