离散化

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
//新操作

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
using namespace std;
bool comp(const int &x,const int &y){return a[x]<a[y];}
int a[maxn],to[maxn],n;
int main()
{
scanf("%d",&n);
fo(i,1,n)scanf("%d",&a[i]),to[i]=i;
sort(to+1,to+1+n,comp);
return 0;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
using namespace std;
#define ll long long
int n,a[100001];
struct node
{
int data,id;
}aa[100001];
bool comp(const node &a,const node &b){return a.data<b.data;}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;++i)scanf("%d",&aa[i].data),aa[i].id=i;
sort(aa+1,aa+1+n,comp);
for(int i=1;i<=n;++i)a[aa[i].id]=i;
return 0;
}
显示 Gitment 评论