2021.10.19 离散化模板

2021.10.19 离散化模板

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;

const int N=1e5+10;
int n,a[N],ai[N];

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

int main(){
	n=read();
	for(int i=1;i<=n;i++)ai[i]=a[i]=read();
	sort(ai+1,ai+n+1);
	cout<<"ai"<<endl;
	for(int i=1;i<=n;i++)cout<<ai[i]<<" ";cout<<endl;
	int len=unique(ai+1,ai+n+1)-ai-1;
	cout<<"ai"<<endl;
	for(int i=1;i<=n;i++)cout<<ai[i]<<" ";cout<<endl;
	for(int i=1;i<=n;i++)
	a[i]=lower_bound(ai+1,ai+len+1,a[i])-ai;
	for(int i=1;i<=n;i++)cout<<a[i]<<" ";cout<<endl;
	return 0;
}
上一篇:JWT加密解密


下一篇:贪心刷题小结