[cpp] on arrays
\n#include <iostream>\n#include <queue>\n#include <vector>\n#include <cmath>\n#include <string>\n#include <sstream>\n#include <cstring>\n#include <algorithm>\n#
```\n#include <iostream>\n#include <queue>\n#include <vector>\n#include <cmath>\n#include <string>\n#include <sstream>\n#include <cstring>\n#include <algorithm>\n#include <climits>\n#include <stack>\n#include <set>\n#include <map>\n#include <list>\n#include <cassert>\n#include <unordered_map>\n#include <numeric>\n#include <iomanip>\n#include <iostream>\n#include <cstdio>\n#include <algorithm>\n#include <queue>\n#include <cstdlib>\n#include <cstring>\n\nusing namespace std;\n#pragma GCC optimize("O3,unroll-loops")\n#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")\n\n/* TYPES  */\n#define xf first\n#define xs second\n#define ll long long int\n#define ul unsigned long long int\n#define lli int64_t\n#define ulli uint64_t\n#define dbl double\n#define ldbl long double\n#define str string\n#define pii pair<int, int>\n#define pll pair<ll,ll>\n#define vi vector<int>\n#define vs vector<string>\n#define vll vector<long long>\n#define mii map<int, int>\n#define si set<int>\n#define sc set<char>\n\n/* FUNCTIONS */\n#define mid(l, r) \t       ((l + r) >> 1)\n#define all(a)             a.begin(),a.end()\n#define v(t) vector<t>\n#define st(t) stack<t>\n#define ar(t,sz) array<t,sz>\n#define s(t) set<t>\n#define ss(a) sort(a.begin(),a.end())\n#define ms(t) multiset<t>\n#define mipq(t) priority_queue<t>\n#define mapq(t) priority_queue<t,v(t),less<t>>\n#define trpl(a,b,c) tuple<a,b,c>\n#define m(t, t2) map<t, t2>\n#define um(t, t2) unordered_map<t, t2>\n#define p(t, t2) pair<t, t2>\n#define f(i, s, e) for(long long int i=s;i<e;i++)\n#define fc(i, s, e, c) for(long long int i=s;i<e;i+=c)\n#define fa(k,in) for(auto k:in)\n#define fm(i, s, e) for(long long int i=s;i!=e;i++)\n#define cf(i, s, e) for(long long int i=s;i<=e;i++)\n#define rf(i, e, s) for(long long int i=e-1;i>=s;i--)\n#define wl(c) while(c)\n#define pb push_back\n#define mpp make_pair\n#define cl clear\n#define eb emplace_back\n\n#include <vector>\n#include <bitset>\n#include <unordered_set>\n#include <algorithm>\n\nbool nd[1002];\nbool has[1002];\nclass Solution {\npublic:\n    int sumImbalanceNumbers(std::vector<int>& nums) {\n        int n=nums.size();\n        int c=0;\n        f(i,0,n){\n            memset(nd,0,sizeof(nd));\n            memset(has,0,sizeof(nd));\n            int mx=nums[i];\n            int k=1;\n            nd[nums[i]+1]=1;\n            has[nums[i]]=1;\n\n            f(j,i+1,n){\n                if(nd[nums[j]]){nd[nums[j]]=0;--k;}\n                mx=max(mx,nums[j]);\n                int nee=nums[j]+1;\n                if(nee<=1001&&!has[nee]){k+=nd[nee]==1?0:1;nd[nee]=1;}\n                has[nums[j]]=1;\n                c+=k;\n                if(mx+1<=1001&&nd[mx+1]){--c;}\n            }\n        }\n        return c;\n    }\n};\n\n```
[]