Advertisement
TAImatem

Аврора Интенсив день2

Nov 22nd, 2022
792
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.66 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #define _USE_MATH_DEFINES
  3. #include "stdio.h"
  4. #include "stdlib.h"
  5. #include "time.h"
  6. #include <cmath>
  7. #include <math.h>
  8. #include <algorithm>
  9. #include <map>
  10. #include <vector>
  11. #include <utility>
  12. #include <set>
  13. #include <string>
  14. #include <cstring>
  15. #include <iostream>
  16. #include <fstream>
  17. #include <unordered_map>
  18. #include <unordered_set>
  19. #include <queue>
  20. #include <bitset>
  21. #include <cassert>
  22. #include <functional>
  23. //#include <intrin.h>
  24. #include <stack>
  25. #include <thread>
  26. using namespace std;
  27. //typedef long long ll;
  28. #define ll long long
  29. #define ld long double
  30.  
  31. const long long mod = 1000000007;
  32.  
  33. #define MIN(x,y) ((x)<(y)?(x):(y))
  34. #define MAX(x,y) ((x)>(y)?(x):(y))
  35. #define PI 3.14159265358979323846
  36. #define ABS(a) ((a)<0?-(a):(a))
  37. template <typename T> inline T gcd(T a, T b) {
  38.     while (b) { a %= b; swap(a, b); }
  39.     return a;
  40. }
  41. long long fastpow(long long a, long long n)
  42. {
  43.     auto mult = a;
  44.     long long res = 1;
  45.     while (n)
  46.     {
  47.         if (n & 1)
  48.             res *= mult;
  49.         mult *= mult;
  50.         n >>= 1;
  51.     }
  52.     return res;
  53. }
  54.  
  55.  
  56. void PrefSum()
  57. {
  58.     int n;
  59.     cin >> n;
  60.     vector<long long> num(n), n_sum(n + 1);
  61.     for (auto& a : num)
  62.     {
  63.         cin >> a;
  64.     }
  65.     n_sum[0] = 0;
  66.     for (int i = 0; i < n; i++)
  67.         n_sum[i + 1] = n_sum[i] + num[i];
  68.     int m, a, b;
  69.     cin >> m;
  70.     for (int i = 0; i < m; i++)
  71.     {
  72.         cin >> a >> b;
  73.         cout << n_sum[b + 1] - n_sum[a] << endl;
  74.     }
  75. }
  76. void Bins_ex()
  77. {
  78.     int n;
  79.     cin >> n;
  80.     vector<long long> num(n);
  81.     for (auto& a : num)
  82.     {
  83.         cin >> a;
  84.     }
  85.     int m;
  86.     long long a;
  87.     cin >> m;
  88.     for (int i = 0; i < m; i++)
  89.     {
  90.         cin >> a;
  91.         int l = 0, r = n - 1;
  92.         while (l < r)
  93.         {
  94.             int m = (l + r + 1) / 2;
  95.             if (num[m] <= a)
  96.             {
  97.                 l = m;
  98.             }
  99.             else
  100.             {
  101.                 r = m - 1;
  102.             }
  103.         }
  104.         cout << l << endl;
  105.     }
  106. }
  107.  
  108. vector<long long> cows;
  109.  
  110. int checkCows(int a)
  111. {
  112.     vector<int> ans_arr(cows.size());
  113.     ans_arr[0] = 1;
  114.     int ans = 1;
  115.     for (int i = 1; i < cows.size(); i++)
  116.     {
  117.         int ind = upper_bound(cows.begin(), cows.end(), cows[i] - a) - cows.begin() - 1;
  118.         if (ind < 0)
  119.             ans_arr[i] = 1;
  120.         else
  121.             ans_arr[i] = ans_arr[ind] + 1;
  122.         ans = max(ans_arr[i], ans);
  123.     }
  124.     return ans;
  125. }
  126. void Cows()
  127. {
  128.     int n, sell;
  129.     cin >> n >> sell;
  130.     cows.resize(n);
  131.     for (auto& a : cows)
  132.         cin >> a;
  133.     sort(cows.begin(), cows.end());
  134.     int l = 0, r = cows.back();
  135.     while (l < r)
  136.     {
  137.         int m = (l + r + 1) / 2;
  138.         if (n - checkCows(m) <= sell)
  139.             l = m;
  140.         else
  141.             r = m - 1;
  142.     }
  143.     cout << l << endl;
  144. }
  145.  
  146. void Ternary()
  147. {
  148.     double l = -PI / 2, r = PI / 2;
  149.     while (r - l > 0.001)
  150.     {
  151.         double m1 = (l * 2 + r) / 3, m2 = (l + r * 2) / 3;
  152.         if (cos(m1) > cos(m2))
  153.             r = m2;
  154.         else
  155.             l = m1;
  156.     }
  157.     cout << l << endl;
  158. }
  159.  
  160. void SubseqNN()
  161. {
  162.     int n;
  163.     cin >> n;
  164.     vector<long long> nums(n);
  165.     vector<vector<long long>> subseq(n);
  166.     vector<int> ans(n);
  167.     for (auto& a : nums)
  168.         cin >> a;
  169.     subseq[0] = { nums[0],INT64_MAX };
  170.     ans[0] = 1;
  171.     int max_ans = 1, maxi = 0;
  172.     for (int i = 1; i < nums.size(); i++)
  173.     {
  174.         subseq[i] = subseq[i - 1];
  175.         int ind = upper_bound(subseq[i].begin(), subseq[i].end(), nums[i]) - subseq[i].begin();
  176.         subseq[i][ind] = nums[i];
  177.         ans[i] = ind + 1;
  178.         if (ans[i] > max_ans)
  179.         {
  180.             max_ans = ans[i];
  181.             maxi = i;
  182.         }
  183.         if (ind >= subseq[i].size() - 1)
  184.             subseq[i].push_back(INT64_MAX);
  185.     }
  186.     cout << max_ans << endl;
  187.     subseq[maxi].pop_back();
  188.     for (auto& a : subseq[maxi])
  189.         cout << a << " ";
  190.     cout << endl;
  191. }
  192.  
  193. void SubseqNlogN()
  194. {
  195.     int n;
  196.     cin >> n;
  197.     vector<long long> nums(n);
  198.     vector<long long> subseq;
  199.     for (auto& a : nums)
  200.         cin >> a;
  201.     subseq = { nums[0],INT64_MAX };
  202.     int max_ans = 1, maxi = 0;
  203.     for (int i = 1; i < nums.size(); i++)
  204.     {
  205.         int ind = upper_bound(subseq.begin(), subseq.end(), nums[i]) - subseq.begin();
  206.         subseq[ind] = nums[i];
  207.         if (ind + 1 > max_ans)
  208.         {
  209.             max_ans = ind + 1;
  210.             maxi = i;
  211.         }
  212.         if (ind >= subseq.size() - 1)
  213.             subseq.push_back(INT64_MAX);
  214.     }
  215.     cout << max_ans << endl;
  216.     subseq = { nums[0],INT64_MAX };
  217.     for (int i = 1; i <= maxi; i++)
  218.     {
  219.         int ind = upper_bound(subseq.begin(), subseq.end(), nums[i]) - subseq.begin();
  220.         subseq[ind] = nums[i];
  221.         if (ind + 1 > max_ans)
  222.         {
  223.             max_ans = ind + 1;
  224.             maxi = i;
  225.         }
  226.         if (ind >= subseq.size() - 1)
  227.             subseq.push_back(INT64_MAX);
  228.     }
  229.     subseq.pop_back();
  230.     for (auto& a : subseq)
  231.         cout << a << " ";
  232.     cout << endl;
  233. }
  234.  
  235. void MapAlt()
  236. {
  237.     vector<long long> keys, nums;
  238.     keys = { 1,3,1000000,99999999 };
  239.     nums = { 0,0,0,0 };
  240.     long long key = 99999999;
  241.     int ind = lower_bound(keys.begin(), keys.end(), key) - keys.begin();
  242.     nums[ind]++;
  243.     cout << nums[ind] << endl;
  244. }
  245.  
  246. int main() {
  247. #ifdef DEBUG
  248.     freopen("input.txt", "r", stdin);
  249.     //freopen("output.txt", "w", stdout);
  250. #endif
  251.     return 0;
  252. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement