https://pintia.cn/problem-sets/994805046380707840/problems/994805107638517760
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IO ios::sync_with_stdio(false);cin.tie(0);
const int maxn=2e5+5;
const int INF = 0x3f3f3f3f;
ll n,vis[10],cnt,c,a[10];
char s[12];
int main(){
scanf("%s",s);
for(int i=0;i<11;i++){
vis[s[i]-'0']++;
}
printf("int[] arr = new int[]{");
for(int i=9;i>=0;i--){
if(vis[i]){
a[cnt]=i;
cnt++;
}
}
for(int i=0;i<cnt;i++){
cout<<a[i];
if(i!=cnt-1)
printf(",");
}
printf("};\n");
printf("int[] index = new int[]{");
for(int i=0;i<11;i++){
for(int j=0;j<cnt;j++){
if(a[j]==(s[i]-'0')){
printf("%d",j);break;
}
}
if(i!=10)
printf(",");
}
printf("};\n");
return 0;
}
优先队列+map
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IO ios::sync_with_stdio(false);cin.tie(0);
const int maxn=2e5+5;
const int INF = 0x3f3f3f3f;
ll n,vis[10],cnt,c;
char s[12];
priority_queue<ll,vector<ll>,less<ll> > q;
map<ll,ll> mp;
int main(){
cin>>s;
for(int i=0;i<11;i++){
if(!vis[s[i]-'0']){
cnt++;
q.push(s[i]-'0');
}
vis[s[i]-'0']++;
}
printf("int[] arr = new int[]{");
while(!q.empty()){
c++;
cout<<q.top();
mp[q.top()]=c-1;
q.pop();
if(c!=cnt)
cout<<",";
else
cout<<"};"<<endl;
}
printf("int[] index = new int[]{");
for(int i=0;i<11;i++){
cout<<mp[s[i]-'0'];
if(i!=10)
cout<<",";
else
cout<<"};"<<endl;
}
return 0;
}
L2-014
递减排列的放在一个调度队列中
https://www.cnblogs.com/zengguoqiang/p/8677456.html
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IO ios::sync_with_stdio(false);cin.tie(0);
const int maxn=2e5+5;
const int INF = 0x3f3f3f3f;
ll n,temp;
set<ll> s;
set<ll>::iterator it;
int main(){
cin>>n;
for(int i=0;i<n;i++){
cin>>temp;
if(s.upper_bound(temp)!=s.end()){
it=s.upper_bound(temp);
s.erase(it);
}
s.insert(temp);//不是递减则递增的添加 始终代替同一个调度路上的比它大的递减的元素
}
cout<<s.size()<<endl;
return 0;
}