#include<bits/stdc++.h> using namespace std; vector<int>sufix; int mini; int stabilnosc(vector<int>A){ int wynik = 2; int obecny = 2; for(int i=2;i<(int)A.size();i++){ if((A[i]>A[i-1]) == (A[i-1]>A[i-2])) obecny++; else obecny = 2; wynik = max(wynik, obecny); } return wynik; } void policz(vector<int>A, vector<int>B){ if(A.size()==0 && B.size()==0){ mini = min(mini, stabilnosc(sufix)); return; } if(A.size()==0){ sufix.push_back(B.back()); B.pop_back(); policz(A,B); sufix.pop_back(); return; } if(B.size()==0){ sufix.push_back(A.back()); A.pop_back(); policz(A,B); sufix.pop_back(); return; } sufix.push_back(B.back()); B.pop_back(); policz(A,B); B.push_back(sufix.back()); sufix.pop_back(); sufix.push_back(A.back()); A.pop_back(); policz(A,B); A.push_back(sufix.back()); sufix.pop_back(); } int f(vector<int>A, vector<int>B){ sufix.clear(); mini = 1000010; policz(A, B); return mini; } int zlicz[1000010]; int tab[2][300010]; int main() { int n, m, s1, s2, t1, t2, i; scanf("%d%d", &n, &m); for(i=0;i<n;i++) scanf("%d", &tab[0][i]); for(i=0;i<m;i++) scanf("%d", &tab[1][i]); /* vector<int>A, B; for(i=0;i<n;i++) A.push_back(tab[0][i]); for(i=0;i<m;i++) B.push_back(tab[1][i]); */ // printf("%d\n", f(A,B)); for(s1=0;s1<n;s1++) for(t1=s1;t1<n;t1++) for(s2=0;s2<m;s2++) for(t2=s2;t2<m;t2++){ vector<int>A, B; for(i=s1;i<=t1;i++) A.push_back(tab[0][i]); for(i=s2;i<=t2;i++) B.push_back(tab[1][i]); zlicz[f(A, B)]++; } for(i=1;i<=n+m;i++) printf("%d ", zlicz[i]%1000000007); }
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | #include<bits/stdc++.h> using namespace std; vector<int>sufix; int mini; int stabilnosc(vector<int>A){ int wynik = 2; int obecny = 2; for(int i=2;i<(int)A.size();i++){ if((A[i]>A[i-1]) == (A[i-1]>A[i-2])) obecny++; else obecny = 2; wynik = max(wynik, obecny); } return wynik; } void policz(vector<int>A, vector<int>B){ if(A.size()==0 && B.size()==0){ mini = min(mini, stabilnosc(sufix)); return; } if(A.size()==0){ sufix.push_back(B.back()); B.pop_back(); policz(A,B); sufix.pop_back(); return; } if(B.size()==0){ sufix.push_back(A.back()); A.pop_back(); policz(A,B); sufix.pop_back(); return; } sufix.push_back(B.back()); B.pop_back(); policz(A,B); B.push_back(sufix.back()); sufix.pop_back(); sufix.push_back(A.back()); A.pop_back(); policz(A,B); A.push_back(sufix.back()); sufix.pop_back(); } int f(vector<int>A, vector<int>B){ sufix.clear(); mini = 1000010; policz(A, B); return mini; } int zlicz[1000010]; int tab[2][300010]; int main() { int n, m, s1, s2, t1, t2, i; scanf("%d%d", &n, &m); for(i=0;i<n;i++) scanf("%d", &tab[0][i]); for(i=0;i<m;i++) scanf("%d", &tab[1][i]); /* vector<int>A, B; for(i=0;i<n;i++) A.push_back(tab[0][i]); for(i=0;i<m;i++) B.push_back(tab[1][i]); */ // printf("%d\n", f(A,B)); for(s1=0;s1<n;s1++) for(t1=s1;t1<n;t1++) for(s2=0;s2<m;s2++) for(t2=s2;t2<m;t2++){ vector<int>A, B; for(i=s1;i<=t1;i++) A.push_back(tab[0][i]); for(i=s2;i<=t2;i++) B.push_back(tab[1][i]); zlicz[f(A, B)]++; } for(i=1;i<=n+m;i++) printf("%d ", zlicz[i]%1000000007); } |