Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.63 KB | None | 0 0
  1. // Просто решаю.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
  2. //
  3.  
  4. //KiruxaLight
  5. #define _CRT_SECURE_NO_WARNINGS
  6. #define _USE_MATH_DEFINES
  7. #include <iostream>
  8. #include <vector>
  9. #include <string>
  10. #include <set>
  11. #include <map>
  12. #include <algorithm>
  13. #include <utility>
  14. #include <cmath>
  15. #include <iomanip>
  16. #include <stack>
  17. #include <deque>
  18. #include <queue>
  19. #include <cstdio>
  20. #include <unordered_map>
  21. #include <unordered_set>
  22. #include <numeric>
  23. #include <cassert>
  24. using namespace std;
  25. #define int long long
  26. #define all(a) a.begin(), a.end()
  27. #define rall(a) a.rbegin(), a.rend()
  28. const int INF = 1e9 + 123, MAXN = 2e5 + 47, MEGAINF = 1e18;
  29. template <class T>
  30. inline istream& operator >> (istream& in, vector <T>& a)
  31. {
  32.   for (auto& i : a)
  33.     in >> i;
  34.   return in;
  35. }
  36. template <class T>
  37. inline ostream& operator << (ostream& out, vector <T>& a)
  38. {
  39.   for (auto& i : a)
  40.     out << i << " ";
  41.   return out;
  42. }
  43. template <class T, class U>
  44. inline istream& operator >> (istream& in, vector <pair <T, U>>& a)
  45. {
  46.   for (auto& i : a)
  47.     in >> i.first >> i.second;
  48.   return in;
  49. }
  50. template <class T, class U>
  51. inline ostream& operator << (ostream& out, vector <pair <T, U>>& a)
  52. {
  53.   for (auto& i : a)
  54.     out << i.first << " " << i.second << endl;
  55.   return out;
  56. }
  57. signed main()
  58. {
  59.   setlocale(LC_ALL, "rus");
  60.  
  61.   /*freopen(".in", "r", stdin);
  62.   freopen(".out", "w", stdout);*/
  63.  
  64.   ios_base::sync_with_stdio(false);
  65.   cin.tie(NULL);
  66.   cout.tie(NULL);
  67.  
  68.   int n;
  69.   cin >> n;
  70.   vector <int> a(n);
  71.   cin >> a;
  72.   vector <int> plus, minus;
  73.   for (int i = 0; i < n; ++i)
  74.     if (a[i] > 0)
  75.       plus.push_back(i);
  76.     else if (a[i] < 0)
  77.       minus.push_back(i);
  78.   int ans = 0;
  79.   cout << plus << endl << minus << endl;
  80.   int cnt = 1;
  81.   for (int i = 1; i < plus.size(); ++i)
  82.     if (plus[i] - 1 == plus[i - 1])
  83.       ++cnt;
  84.     else
  85.     {
  86.       ans += cnt * (cnt + 1) / 2;
  87.       cnt = 1;
  88.     }
  89.   ans += cnt * (cnt + 1) / 2;
  90.   cnt = 1;
  91.   for (int i = 1; i < minus.size(); ++i)
  92.     if (minus[i] - 1 == minus[i - 1])
  93.       ++cnt;
  94.     else
  95.     {
  96.       ans += cnt * (cnt + 1) / 2;
  97.       cnt = 1;
  98.     }
  99.   ans += cnt * (cnt + 1) / 2;
  100.   cnt = 1;
  101.   cout << ans;
  102. }
  103. // Запуск программы: CTRL+F5 или меню "Отладка" > "Запуск без отладки"
  104. // Отладка программы: F5 или меню "Отладка" > "Запустить отладку"
  105.  
  106. // Советы по началу работы
  107. //   1. В окне обозревателя решений можно добавлять файлы и управлять ими.
  108. //   2. В окне Team Explorer можно подключиться к системе управления версиями.
  109. //   3. В окне "Выходные данные" можно просматривать выходные данные сборки и другие сообщения.
  110. //   4. В окне "Список ошибок" можно просматривать ошибки.
  111. //   5. Последовательно выберите пункты меню "Проект" > "Добавить новый элемент", чтобы создать файлы кода, или "Проект" > "Добавить существующий элемент", чтобы добавить в проект существующие файлы кода.
  112. //   6. Чтобы снова открыть этот проект позже, выберите пункты меню "Файл" > "Открыть" > "Проект" и выберите SLN-файл.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement