#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; using namespace std; const int N = 1e6 + 5; int tab[N], kub[4*N]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); ordered_set o_set; int n; cin>>n; for(int i=1;i<=n;i++){ cin>>tab[i]; } for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++) o_set.insert(tab[i]); for(int j=i;j<=n;j++){ double md; if((j-i+1)%2){ md=*(o_set.find_by_order((j-i+2)/2-1)); } else{ int sub1=*(o_set.find_by_order((j-i+1)/2-1)); int sub2=*(o_set.find_by_order((j-i+1)/2)); md=(sub1+sub2)/2.0; } int pom = j-i+1+2*md; kub[pom]++; o_set.insert(tab[j+1]); } o_set.clear(); } for(int i=4e6+5;i>=1;i--){ if(kub[i]){ cout<<i<<" "<<kub[i]; return 0; } } return 0; }
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 | #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; using namespace std; const int N = 1e6 + 5; int tab[N], kub[4*N]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); ordered_set o_set; int n; cin>>n; for(int i=1;i<=n;i++){ cin>>tab[i]; } for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++) o_set.insert(tab[i]); for(int j=i;j<=n;j++){ double md; if((j-i+1)%2){ md=*(o_set.find_by_order((j-i+2)/2-1)); } else{ int sub1=*(o_set.find_by_order((j-i+1)/2-1)); int sub2=*(o_set.find_by_order((j-i+1)/2)); md=(sub1+sub2)/2.0; } int pom = j-i+1+2*md; kub[pom]++; o_set.insert(tab[j+1]); } o_set.clear(); } for(int i=4e6+5;i>=1;i--){ if(kub[i]){ cout<<i<<" "<<kub[i]; return 0; } } return 0; } |