a53

IJK

a53
Nov 3rd, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define DAU ios::sync_with_stdio(false); fin.tie(0); fout.tie(0);
  3. #define PLEC fin.close(); fout.close(); return 0;
  4. using namespace std;
  5. using PII = pair<int, int>;
  6. using VP = vector<PII>;
  7. using VI = vector<int>;
  8. ifstream fin("ijk.in");
  9. ofstream fout("ijk.out");
  10. unordered_map<int, int> M;
  11. const int Dim = 70007;
  12. VI aib(Dim + 7), v, a, st, dr;
  13. int n, cnt;
  14. int64_t res;
  15. inline void Update(int poz)
  16. {
  17. for (int i = poz; i <= Dim; i += i & -i)
  18. ++aib[i];
  19. }
  20. inline int Query(int poz)
  21. {
  22. int s = 0;
  23. for (int i = poz; i > 0; i -= i & -i)
  24. s += aib[i];
  25. return s;
  26. }
  27. int main()
  28. {
  29. DAU
  30. fin >> n;
  31. v = a = st = dr = VI(n + 1);
  32. for (int i = 1; i <= n; ++i)
  33. {
  34. fin >> a[i];
  35. v[i] = -a[i];
  36. }
  37. sort(v.begin() + 1, v.end());
  38. for (int i = 1; i <= n; ++i)
  39. if (!M[v[i]])
  40. M[v[i]] = ++cnt;
  41. for (int i = 1; i <= n; ++i)
  42. a[i] = M[-a[i]];
  43. for (int i = 1; i <= n; ++i)
  44. {
  45. st[i] = Query(a[i] - 1);
  46. Update(a[i]);
  47. }
  48. aib = VI(Dim + 7);
  49. for (int i = n; i; --i)
  50. {
  51. dr[i] = Query(a[i] - 1);
  52. Update(a[i]);
  53. }
  54. for (int i = 2; i < n; ++i)
  55. res += 1LL * st[i] * dr[i];
  56. fout << res;
  57. PLEC
  58. }
Add Comment
Please, Sign In to add comment