#include <bits/stdc++.h> #define ll long long int using namespace std; const int MAXN = 1e6; vector<ll> tab(MAXN+10), pom(MAXN+10); ll n, cnt=0,cel; void szukaj(int start); ll mediana2(int start, int koniec); int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n; cel=2*n+1; for(int i=1;i<=n;++i) cin>>tab[i]; for(int i=1;i<=n;++i) szukaj(i); cout<<cel<<" "<<cnt; return 0; } //5 //1 4 3 5 2 void szukaj(int start){ for(int i=start;i<=n;++i){ pom[i]=tab[i]; sort(pom.begin()+start, pom.begin()+i+1); // cout<<"\n"; // for(int j=start;j<=i;++j) // cout<<pom[j]<<" "; if(i-start+1 + mediana2(start,i)==cel) ++cnt; } } ll mediana2(int start, int koniec){ ll k=koniec-start+1; if(k%2==1) return 2*pom[start+k/2]; else return pom[start+k/2]+pom[start+k/2-1]; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | #include <bits/stdc++.h> #define ll long long int using namespace std; const int MAXN = 1e6; vector<ll> tab(MAXN+10), pom(MAXN+10); ll n, cnt=0,cel; void szukaj(int start); ll mediana2(int start, int koniec); int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n; cel=2*n+1; for(int i=1;i<=n;++i) cin>>tab[i]; for(int i=1;i<=n;++i) szukaj(i); cout<<cel<<" "<<cnt; return 0; } //5 //1 4 3 5 2 void szukaj(int start){ for(int i=start;i<=n;++i){ pom[i]=tab[i]; sort(pom.begin()+start, pom.begin()+i+1); // cout<<"\n"; // for(int j=start;j<=i;++j) // cout<<pom[j]<<" "; if(i-start+1 + mediana2(start,i)==cel) ++cnt; } } ll mediana2(int start, int koniec){ ll k=koniec-start+1; if(k%2==1) return 2*pom[start+k/2]; else return pom[start+k/2]+pom[start+k/2-1]; } |