比赛 |
CSP2023-J模拟赛 |
评测结果 |
AAAAAAAAAATTTTTTTTTT |
题目名称 |
排列变换 |
最终得分 |
50 |
用户昵称 |
liuyiche |
运行时间 |
10.008 s |
代码语言 |
C++ |
内存使用 |
4.69 MiB |
提交时间 |
2023-10-18 20:12:08 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
int n, Max = -1, Maxid;
struct node
{
int id;
int w;
};
vector<node> v;
vector<node> vv;
vector<int> c;
inline bool cmp(node a, node b)
{
return a.w-a.id > b.w-b.id ? true : false;
}
int main()
{
freopen("permutrans.in", "r", stdin);
freopen("permutrans.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n;
if(n == 1)
{
cout << 1 << " " << 0;
return 0;
}
for(int i = 1; i <= n; ++i)
{
node a;
a.id = i;
cin >> a.w;
v.push_back(a);
}
vv = v;
sort(v.begin(),v.end(),cmp);
for (int i = 0; i < n; ++i)
c.push_back(v[i].w-v[i].id);
for (int i = 1; i < n; ++i)
{
int p = upper_bound(c.begin(),c.begin()+n,i-1,greater<int>())-c.begin();
if(p > Max)
{
Max = p;
Maxid = i-1;
}
auto p2 = lower_bound(v.begin(),v.end(),vv[n-i],cmp);
v.erase(p2);
c.erase(p2-v.begin()+c.begin());
node a = vv[n-i];
a.id = 1-i;
auto p3 = lower_bound(v.begin(),v.end(),a,cmp);
v.insert(p3,a);
c.insert(p3-v.begin()+c.begin(),a.w-a.id);
}
int p = upper_bound(c.begin(),c.begin()+n,n-1,greater<int>())-c.begin();
if(p > Max)
{
Max = p;
Maxid = n-1;
}
cout << Max << " " << Maxid;
return 0;
}