Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define DAU ios::sync_with_stdio(false); fin.tie(0); fout.tie(0);
- #define PLEC fin.close(); fout.close(); return 0;
- using namespace std;
- using PII = pair<int, int>;
- using VP = vector<PII>;
- using VI = vector<int>;
- ifstream fin("ijk.in");
- ofstream fout("ijk.out");
- unordered_map<int, int> M;
- const int Dim = 70007;
- VI aib(Dim + 7), v, a, st, dr;
- int n, cnt;
- int64_t res;
- inline void Update(int poz)
- {
- for (int i = poz; i <= Dim; i += i & -i)
- ++aib[i];
- }
- inline int Query(int poz)
- {
- int s = 0;
- for (int i = poz; i > 0; i -= i & -i)
- s += aib[i];
- return s;
- }
- int main()
- {
- DAU
- fin >> n;
- v = a = st = dr = VI(n + 1);
- for (int i = 1; i <= n; ++i)
- {
- fin >> a[i];
- v[i] = -a[i];
- }
- sort(v.begin() + 1, v.end());
- for (int i = 1; i <= n; ++i)
- if (!M[v[i]])
- M[v[i]] = ++cnt;
- for (int i = 1; i <= n; ++i)
- a[i] = M[-a[i]];
- for (int i = 1; i <= n; ++i)
- {
- st[i] = Query(a[i] - 1);
- Update(a[i]);
- }
- aib = VI(Dim + 7);
- for (int i = n; i; --i)
- {
- dr[i] = Query(a[i] - 1);
- Update(a[i]);
- }
- for (int i = 2; i < n; ++i)
- res += 1LL * st[i] * dr[i];
- fout << res;
- PLEC
- }
Add Comment
Please, Sign In to add comment