Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- using ll = long long;
- using vl = vector<ll>;
- using vvl = vector<vector<ll>>;
- public:
- long long countQuadruplets(vector<int>& ns) {
- ll ret = 0;
- int n = ns.size();
- vvl ij(n, vl(n));
- vvl kl(n, vl(n));
- for (int i = 0; i < n; ++i) {
- int val = 0;
- for (int j = 0; j < i; ++j) {
- if (ns[j] < ns[i]) ++val;
- ij[i][j] = val;
- }
- }
- for (int k = n - 1; k >= 0; --k) {
- int val = 0;
- for (int l = n - 1; l > k; --l) {
- if (ns[k] < ns[l]) ++val;
- kl[k][l] = val;
- }
- }
- for (int k = 0; k + 1 < n; ++k)
- for (int j = 1; j < k; ++j)
- if (ns[k] < ns[j]) {
- printf("k:%d j:%d, ij:%lld kl:%lld\n", k, j, ij[j][j-1], kl[j][k] - 1);
- ret += ij[j][j-1] * (kl[j][k] - 1);
- }
- return ret;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement