#include<bits/stdc++.h> #define I if #define E else #define W while #define F for #define R return #define S scanf #define P printf using namespace std;int main(){int n,i,l,r;long long a;S("%d",&n);int t[n];int p[n+1];F(i=0;i<n;i++)S("%d",&t[i]);F(i=0;i<n;i++)p[t[i]]=i;P("%d ",n*2+1);a=0;l=r=p[n];F(i=1;i<=n;i++){I(i%2==0){l=min(l,p[n-i/2]);r=max(r,p[n-i/2]);}I(i-r+l>0)a+=i-r+l-max(0,i-r-1)-max(0,l+i-n);}P("%lld\n",a);}
1 2 3 4 5 6 7 8 9 10 | #include<bits/stdc++.h> #define I if #define E else #define W while #define F for #define R return #define S scanf #define P printf using namespace std;int main(){int n,i,l,r;long long a;S("%d",&n);int t[n];int p[n+1];F(i=0;i<n;i++)S("%d",&t[i]);F(i=0;i<n;i++)p[t[i]]=i;P("%d ",n*2+1);a=0;l=r=p[n];F(i=1;i<=n;i++){I(i%2==0){l=min(l,p[n-i/2]);r=max(r,p[n-i/2]);}I(i-r+l>0)a+=i-r+l-max(0,i-r-1)-max(0,l+i-n);}P("%lld\n",a);} |