死亡回放: https://www.luogu.com.cn/record/list?pid=P1020&user=1075989
代码:
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
vector<int> tmp;
void mergeSort(vector<int> &a,vector<int> &b,int start,int end){
if(start>end){
mergeSort(a,b,start,end/2);
mergeSort(a,b,end/2,end);
int x=start,y=(start+end)/2;
for(int i=start;i<end;i++){
if(y>=end||(x<(start+end)/2&&a[b[x]]>a[b[y]])){
tmp[i]=b[x];
x++;
}else{
tmp[i]=b[y];
y++;
}
}
for(int i=start;i<end;b[i]=tmp[i]);
}
}
int main(){
string wi;
getline(cin,wi);
vector<int> heights;
int n=0;
heights.push_back(0);
for(int i=0;i<wi.size();i++){
if(wi[i]==' '){
heights.push_back(0);
n++;
}else if(wi[i]>='0'&&wi[i]<='9'){
heights[n]*=10;
heights[n]+=wi[i]-'0';
}
}
n++;
vector<int> ma(n);
for(int i=0;i<n;i++){
ma[i]=i;
tmp.push_back(0);
}
mergeSort(heights,ma,0,n);
int now=heights[0],all=1;
for(int i=1;i<n;i++){
if(heights[i]>now){
all++;
}
now=heights[i];
}
vector<int> dp(n,0);dp[0]=1;
for(int i=0;i<n;i++){
if(heights[i-1]>heights[i]){
dp[i]=dp[i-1]+1;
}else{
for(int j=0;j<ma.size();j++){
if(heights[ma[j]]>heights[i]){
dp[i]+=dp[ma[j]];
}
}
}
}
int allmax=dp[0];
for(int i=1;i<n;i++){
if(dp[i]>allmax){
allmax=dp[i];
}
}
cout<<allmax<<endl<<all<<endl;
return 0;
}
自己搓了个归并排序(熟悉一下排序,怕比赛的时候不让用sort)