#include <iostream> #include <set> #include <vector> using namespace std; long long wyn = 1, poz; long long maxi; //Chcemy max Liczba ocen + 2*mediana void solve(vector<long long>& nums, long long k) { multiset<long long> window(nums.begin(), nums.begin() + k); vector <long long> medians; auto mid = next(window.begin(), k / 2); for (long long i = k; ; i++) { //if(i != nums.size()) //cout << i << " " << nums[i] << " " << nums[i-k]<< endl; if ((double(*mid) + *prev(mid, 1 - k % 2)) + k == maxi) wyn++; if (i - k > poz || i == nums.size()) break; window.insert(nums[i]); if (nums[i] < *mid) mid--; if (nums[i - k] <= *mid) mid++; window.erase(window.lower_bound(nums[i - k])); } } // 1 4 3 5 2 // 0 1 2 3 4 int main() { long long n, x; vector <long long> a; cin >> n; for (long long i = 0; i < n; i++) { cin >> x; if (x == n) poz = i; a.push_back(x); } maxi = 2*n + 1; cout << maxi << " "; for (long long i = 1; i < n; i++) { solve(a, i); } cout << wyn; 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #include <iostream> #include <set> #include <vector> using namespace std; long long wyn = 1, poz; long long maxi; //Chcemy max Liczba ocen + 2*mediana void solve(vector<long long>& nums, long long k) { multiset<long long> window(nums.begin(), nums.begin() + k); vector <long long> medians; auto mid = next(window.begin(), k / 2); for (long long i = k; ; i++) { //if(i != nums.size()) //cout << i << " " << nums[i] << " " << nums[i-k]<< endl; if ((double(*mid) + *prev(mid, 1 - k % 2)) + k == maxi) wyn++; if (i - k > poz || i == nums.size()) break; window.insert(nums[i]); if (nums[i] < *mid) mid--; if (nums[i - k] <= *mid) mid++; window.erase(window.lower_bound(nums[i - k])); } } // 1 4 3 5 2 // 0 1 2 3 4 int main() { long long n, x; vector <long long> a; cin >> n; for (long long i = 0; i < n; i++) { cin >> x; if (x == n) poz = i; a.push_back(x); } maxi = 2*n + 1; cout << maxi << " "; for (long long i = 1; i < n; i++) { solve(a, i); } cout << wyn; return 0; } |