其他分享
首页 > 其他分享> > [排序][vector] Jzoj P6288 旋转子段

[排序][vector] Jzoj P6288 旋转子段

作者:互联网

Description

 

题解

 

代码

 1 #include <vector>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <iostream>
 5 #include <algorithm>
 6 using namespace std;
 7 const int N=100010;
 8 vector<int>v[N*2];
 9 int n,ans,k,p,sum[N];
10 bool cmp(int x,int y) { return abs(x*2-k)<abs(y*2-k); }
11 int main()
12 {
13     freopen("rotate.in","r",stdin),freopen("rotate.out","w",stdout),scanf("%d",&n);
14     for (int i=1,x;i<=n;i++) scanf("%d",&x),v[x+i].push_back(i),sum[i]=sum[i-1]+(x==i);
15     for (int i=2;i<=n*2;i++)
16         if (!v[i].empty())
17         {
18             k=i,sort(v[i].begin(),v[i].end(),cmp),p=v[i].size();
19             for (int j=0;j<p;j++)
20             {
21                 int l=v[i][j],r=i-v[i][j];
22                 if (l>r) swap(l,r); 
23                 ans=max(ans,sum[l-1]+sum[n]-sum[r]+j+1);
24             }
25         }
26     printf("%d",ans);
27 }    

 

标签:Jzoj,int,反转,sum,子段,不动点,vector,ans,include
来源: https://www.cnblogs.com/Comfortable/p/11329766.html