id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
3,535
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
3
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n int MOD = 1000000007;\n int n = nums.size();\n vector<vector<int>> dp(51, vector<int>(51, 0));\n\n for (int i = 0; i <= nums[0]; ++i) {\n int k = nums[0] - i;\n dp[i][k] = 1;\n }\...
3,535
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
3
{ "code": "class Solution {\npublic:\n int mod=1e9+7;\n int f(vector<vector<vector<int>>>&dp,vector<int>& nums,int i,int p1,int p2){\n if(i==nums.size()){\n return 1;\n }\n if(dp[i][p1][p2]!=-1) return dp[i][p1][p2];\n int ans=0;\n for(int x=0;x<=50;x++){\n ...
3,535
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
3
{ "code": "class Solution {\npublic:\n int mod = 1e9+7;\n int solve(int ind, int prev1, int prev2, vector<int>& nums, vector<vector<vector<int>>>& dp) {\n if(ind >= nums.size()) {\n return 1;\n }\n if(dp[ind][prev1+1][prev2]!=-1) {\n return dp[ind][prev1+1][prev2];\n ...
3,535
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
3
{ "code": "class Solution {\npublic:\n int mod=1000000007;\n int solve(vector<int>&nums,int n,int idx,int pre1,int pre2,vector<vector<vector<int>>>&dp)\n {\n if(idx>=n)\n {\n return 1;\n }\n if(dp[idx][pre1+1][pre2+1]!=-1)\n {\n return dp[idx][pre1+1][...
3,535
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
3
{ "code": "class Solution {\npublic:\n\n int solve(vector<int>&nums, int i, int last1, int last2, vector<vector<vector<int>>>&dp){\n // cout<<i<<\" \"<<last1<<\" \"<<last2<<endl;\n int M = 1e9 + 7;\n if(i >= nums.size()) return 1;\n if(dp[i][last1][last2+1] != -1) return dp[i][last1][la...
3,535
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
3
{ "code": "const int MOD = 1000000007;\nconst int MAX_VAL = 60;\n\nclass Solution {\npublic:\n int countOfPairs(vector<int>& values) {\n int size = values.size();\n vector<vector<vector<long long>>> dppp(size, vector<vector<long long>>(MAX_VAL + 1, vector<long long>(MAX_VAL + 1, -1)));\n retur...
3,535
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
3
{ "code": "#define MOD 1000000007\nclass Solution {\npublic:\n int rec(int index,int last_1,int last_2,vector<int>& num,vector<vector<vector<int>>>& dp)\n {\n int n=num.size();\n if(index==n){return 1;}\n if(dp[index][last_1][last_2]!=-1){return dp[index][last_1][last_2];}\n int ways...
3,535
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
3
{ "code": "class Solution {\npublic:\n int MOD = 1000000007;\n int countOfPairs(vector<int>& nums) {\n int n = nums.size();\n vector<vector<vector<long>>> dp(n, vector<vector<long>>(55, vector<long>(55, 0)));\n for(int i = 0; i <= nums[0]; ++i){\n dp[0][i][nums[0]-i] = 1;\n ...
3,535
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
3
{ "code": "class Solution {\npublic:\n int mod=1e9+7;\n int recursion(vector<int> &nums,int i,int arr1Prev,int arr2Prev,vector<vector<vector<int>>> &dp){\n if(i>=nums.size()){\n return 1;\n }\n if(dp[i][arr1Prev][arr2Prev+1]!=-1){\n return dp[i][arr1Prev][arr2Prev+1];\...
3,535
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
3
{ "code": "class Solution {\npublic:\n int mod = 1e9 + 7;\n long long solve(int i, long long prevnum1, long long prevnum2, vector<int>& nums, vector<vector<vector<long long>>>& dp){\n int n = nums.size();\n if(i == n){\n return 1;\n }\n if(dp[i][prevnum1][prevnum2]!= -1){\...
3,535
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
3
{ "code": "class Solution {\npublic:\n int mod = 1e9 + 7;\n long long solve(int i, long long prevnum1, long long prevnum2, vector<int>& nums, vector<vector<vector<long long>>>& dp){\n int n = nums.size();\n if(i == n){\n return 1;\n }\n if(dp[i][prevnum1][prevnum2]!= -1){\...
3,535
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
3
{ "code": "#include <vector>\n\nusing namespace std;\n\nclass Solution {\npublic:\n int dtob(int t) {\n int sum = 0;\n int u = 1;\n while (t > 0) {\n int p = (t & 1);\n sum += p * u;\n t >>= 1;\n u *= 10;\n }\n return sum;\n }\n\n ...
3,535
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
3
{ "code": "class Solution {\npublic:\nint cnt = 0;\n int f(int ind,int prev1,int prev2,vector<int> &nums,vector<vector<vector<int>>> &dp){\n if(ind==nums.size()){\n return 1;\n }\n int mod = 1e9 + 7;\n int ans = 0;\n if(dp[ind][prev1][prev2]!=-1) return dp[ind][prev1][prev2];\n for(int i = 0...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
0
{ "code": "class Solution { \npublic:\n const int mod = 1e9 + 7;\n const static int maxN = 1e3 + 5;\n\n int dp[maxN], pref[maxN];\n\n int countOfPairs(vector<int>& nums) {\n int n = nums.size();\n \n memset(dp, 0, sizeof(dp));\n memset(pref, 0, sizeof(pref));\n for (i...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
0
{ "code": "\nclass Solution2Helper {\n public:\n static inline constexpr std::array<int64_t, 3001> ComputeFactorials() noexcept {\n std::array<int64_t, 3001> ret;\n ret[0] = 1;\n for (int64_t i = 1; i <= 3000; ++i) {\n ret[i] = (ret[i - 1] * i) % Mod;\n }\n return ret;\n }\n\n static inline con...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
0
{ "code": "typedef long long ll;\nclass Solution {\npublic:\n static const int mod = (int)(1e9 + 7);\n int countOfPairs(vector<int>& nums) {\n int n = nums.size();\n int b = nums[0];\n for (auto v : nums) b = max(b, v);\n vector<ll> dp(b + 1, 0);\n for (int i = 0; i <= nums[0]...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
0
{ "code": "class Solution {\n public:\n const int MOD = 1000000007;\n int countOfPairs(vector<int>& nums) {\n const int n = nums.size();\n const int m = (*max_element(nums.begin(), nums.end())) + 2;\n vector<vector<int>> f(2, vector<int>(m + 1, 0));\n vector<vector<int>> s(2, vecto...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
0
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n int n = nums.size();\n // vector<vector<int>> cur(1001, vector<int>(1001, 0)),\n vector<int>cur(1001,0),prev(1001,0);\n \n for (int i = nums[0]; i >= 0; i--) {\n prev[i] = 1;\n }\n...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
0
{ "code": "class Solution {\npublic:\n int mod=1e9+7;\n int multi(int a,int b) {\n return (1ll*a*b)%mod;\n }\n int power(int x,int n){\n int ans=1;\n int part=x;\n while(n){\n if(n&1){\n ans=multi(ans,part);\n }\n part=multi(part,...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
0
{ "code": "long long dp[2005][1005] = {};\nlong long pref[1005] = {};\nclass Solution {\npublic:\n long long mod = 1e9 + 7;\n int n;\n void setup_(int n, int mx){\n for(int i = 0; i <= n; i++)\n for(int j = 0; j <= mx; j++)\n dp[i][j] = 0;\n }\n int countOfPairs(vector<...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
0
{ "code": "class Solution {\npublic:\n struct val {\n int il;\n int jl;\n long long int v;\n };\n long long int find_no_pairs(vector<int>& nums, int n, int in, int tn,\n struct val* tol) {\n long long int i, j, k, p, u, v, ul, vl;\n k = 0;\n ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
0
{ "code": "template <int64_t mod> class int_mod {\n private:\n\tint64_t value;\n\n public:\n\tconstexpr static int64_t mval() { return mod; }\n\t// int_mod/* -> */int_mod\n\tint_mod() : value{} {}\n\tint_mod(const std::integral auto &x) {\n\t\tvalue = static_cast<int64_t>(x % mod);\n\t\tif (value < 0)\n\t\t\tvalue ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
0
{ "code": "class Solution {\npublic:\n int mod=1e9+7;\n int multi(int a,int b) {\n return (1ll*a*b)%mod;\n }\n int power(int x,int n){\n int ans=1;\n int part=x;\n while(n){\n if(n&1){\n ans=multi(ans,part);\n }\n part=multi(part,...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
0
{ "code": "class Solution {\npublic:\n \n int countOfPairs(vector<int>& nums) {\n int mod=1e9+7;\n int dp[2001][1001];\n memset(dp,-1,sizeof(dp));\n int n=nums.size();\n long long int dpprefix[2001][1001];\n memset(dpprefix,0,sizeof(dpprefix));\n\n for(int j=0;j<1...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
0
{ "code": "class Solution {\npublic:\n typedef long long ll;\n ll mod=1e9+7;\n ll dp[2000][1001];\n int countOfPairs(vector<int>& nums) {\n memset(dp,0,sizeof(dp));\n for(int k=0;k<=1000;k++){\n if(nums.size()==1)dp[0][k]=nums[0]+1;\n else{\n int ans=0;\n...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
0
{ "code": "#define ll long long\nll dp[2000][1001];\nll preDp[2000][1001];\nconst ll M=1e9+7;\nll sum(int l,int r,int i){\n if(r<l) return 0;\n if(l==0) return preDp[i-1][r];\n return (preDp[i-1][r]-preDp[i-1][l-1]+M)%M;\n}\nclass Solution {\npublic:\n int countOfPairs(vector<int>& a) {\n memset(dp...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
0
{ "code": "#define ll long long\nll mod=1e9+7;\nll dp[2001][1002];\nll pref[2001][1002];\nll f(int ind,int prev1,vector<int>& nums)\n{\n int n=nums.size();\n if(dp[ind][prev1]!=-1) return dp[ind][prev1];\n if(ind==n) return 1;\n int prev2=1001;\n if(ind!=0)\n prev2=nums[ind-1]-prev1;\n ll cnt=0;\...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n long long int n = nums.size();\n long long int mod = 1000000007;\n vector <long long int> diff(n, 0);\n for (long long int i=1; i<n; i++){\n diff[i] = nums[i] - nums[i-1];\n }\n long ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "const int MOD = 1e9 + 7;\ntypedef long long ll;\nconst int UB = 2001;\nclass Solution {\npublic:\n\n int countOfPairs(vector<int>& a) {\n int n = a.size();\n ll dp[n][UB];\n ll sum[UB];\n\n for(int i=0; i<n; i++){\n for(int j=0; j<UB; j++){\n dp[i][j...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "auto fast = (ios::sync_with_stdio(0), cout.tie(0), cin.tie(0), false);\nconstexpr int kMod = 1000000007;\nstruct CountsByEnd {\n int offset;\n vector<int> counts;\n};\nCountsByEnd kEmptyCounts{.offset = 0};\nstruct Solution {\n CountsByEnd helper(const vector<int>& nums, int end_index) {\n ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n vector<long long> fact;\n vector<long long> inv;\n long long mod;\n void precompute()\n {\n fact[0]=1;\n inv[1]=1;\n inv[0]=1;\n for(int i=1;i<=3001;i++)\n {\n fact[i] = (i*fact[i-1])%mod;\n if(i>=2)\n ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "const int N = 2010, MOD = 1e9 + 7;\nlong long dp[N][N];\nlong long p[N][N];\n\nclass Solution {\npublic:\n int countOfPairs(vector<int>& a) {\n int n = a.size();\n int mx = 0;\n for(int i : a) mx = max(mx, i);\n for(int i = 0; i < n; i++) {\n for(int j = 0; j <= mx...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "const int N = 2010, MOD = 1e9 + 7;\nlong long dp[N][N];\nlong long p[N][N];\n\nclass Solution {\npublic:\n int countOfPairs(vector<int>& a) {\n int n = a.size();\n int mx = 0;\n for(int i : a) mx = max(mx, i);\n for(int i = 0; i < n; i++) {\n for(int j = 0; j <= mx...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "#define ll long long\nll mod=1e9+7;\nclass Solution {\npublic:\n int countOfPairs(vector<int>& v) {\n int n=v.size();\n ll dp [3000][2000];\n memset(dp,0,sizeof(dp));\n for(int i=1;i<=n;i++){\n for(int j=0;j<=v[i-1];j++){\n if(i==1){\n ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "#define ll long long\nll mod=1e9+7;\nclass Solution {\npublic:\n int countOfPairs(vector<int>& v) {\n int n=v.size();\n ll dp [3000][2000];\n memset(dp,0,sizeof(dp));\n for(int i=1;i<=n;i++){\n for(int j=0;j<=v[i-1];j++){\n if(i==1){\n ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n typedef long long ll;\n const int mo=1000000007;\n int countOfPairs(vector<int>& a) {\n vector<ll> prev,cur;\n for(int i=0;i<=a[0];i++){\n prev.push_back(i+1);\n }\n \n for(int i=1;i<a.size();i++){\n cur.clear();\...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n \n int n = nums.size(), m = 1e9+7, out = 0;\n queue<vector<int>> q;\n vector<unordered_map<int, int>> psum(2), dp(2);\n for(int i = 0;i<=nums[0];i++){\n q.push({\n 0, i, nums[...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "namespace modarith {\n static constexpr unsigned modulo = 1000000000+7;\n //static constexpr unsigned modulo = 998244353;\n // a, b \\in [0, modulo)\n static constexpr void addmod(unsigned &a, unsigned b) { // a += b\n static_assert(modulo - 1 <= std::numeric_limits<decltype(b)>::max() -...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "namespace modarith {\n static constexpr unsigned modulo = 1000000000+7;\n //static constexpr unsigned modulo = 998244353;\n // a, b \\in [0, modulo)\n static constexpr void addmod(unsigned &a, unsigned b) { // a += b\n static_assert(modulo - 1 <= std::numeric_limits<decltype(b)>::max() -...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n int mod = 1e9 + 7;\n int n = nums.size();\n const int MAX = 1001;\n\n vector<vector<long long>> dp(MAX, vector<long long>(3, 0));\n for(int l = 0, r = nums.back(); r >= 0; l++, r--) {\n dp[l...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\n const int MOD = 1'000'000'000 + 7;\n \n void print_dyn(const vector<vector<long long>> &dyn) {\n cout << \"DYN START\" << endl;\n for (auto row: dyn) {\n for (auto col: row) {\n cout << col << \" \";\n }\n cout << end...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n int n=nums.size(),mod=1e9+7;\n vector<long long> dp(1001),next(1001);\n for(int i=0;i<=nums[n-1];++i){\n dp[i]++;\n }\n for(int i=n-2;i>=0;--i){\n for(int j=0;j<=1000;++j) next[j]...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "int mod = 1e9 + 7;\nint p[1002], nt[1002];\nclass Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n int n = nums.size();\n for (int i = 0; i < 1002; i++)\n p[i] = 1;\n for (int ind = n - 1; ind >= 0; ind--) {\n int ans = 0;\n if ( ind == ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "#include <ranges>\n\nclass Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n const int M = 1e9 + 7;\n for (int i = 0; i < nums.size(); ++i) ++nums[i];\n int n = nums[0];\n vector<int> cnt(n, 1);\n for (int n2: ranges::drop_view{nums, 1}) {\n vect...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n const int MOD = 1e9 + 7;\n int countOfPairs(vector<int>& nums) {\n int n = nums.size();\n vector<int> dp(nums[0]+1, INT_MIN);\n\n for (int i = 0; i <= nums[0]; ++i) {\n dp[i] = i + 1;\n }\n\n for (int i = 1; i < n; ++i) {\n ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "#define ll int64_t \n\nclass Solution {\npublic:\n ll add(ll a, ll b){\n return (a%mod + b%mod)%mod;\n }\n const int mod = 1e9 + 7;\n int countOfPairs(vector<int>& nums) {\n ll n = nums.size();\n ll max_val = 1000;\n vector<vector<ll>> vec(max_val + 1, vector<ll> (2,...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "#define ll int64_t \n\nclass Solution {\npublic:\n ll add(ll a, ll b){\n return (a%mod + b%mod)%mod;\n }\n const int mod = 1e9 + 7;\n int countOfPairs(vector<int>& nums) {\n ll n = nums.size();\n ll max_val = 1000;\n vector<vector<ll>> vec(max_val + 1, vector<ll> (2,...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n int n = nums.size();\n vector<int> ar = nums;\n vector<int> v;\n v.push_back(0);\n int last = nums[0];\n for(int i=1; i<n; i++){\n int ts = v.back();\n if(nums[i]<ts) retur...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\nint mod=1e9+7;\n int solve(int idx,vector<int>&nums,int a1,vector<vector<int>>&dp){\n if(idx==nums.size()){\n return 1;\n }\n if(dp[idx][a1]!=-1) return dp[idx][a1];\n long long a=0;\n for(int i=a1;i<=nums[idx];i++){\n i...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int mod = 1e9 + 7;\n int solve(int idx, vector<int>& nums, int a1, vector<vector<int>>& dp) {\n if (idx == nums.size()) {\n return 1;\n }\n if (dp[idx][a1] != -1)\n return dp[idx][a1];\n long long a = 0;\n for (int i...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\nint mod=1e9+7;\nint solve(int idx,vector<int>& nums,int a1,vector<vector<int>>&dp){\nif(idx==nums.size()){\nreturn 1;\n}\nif(dp[idx][a1]!=-1) return dp[idx][a1];\nlong long a=0;\nfor(int i=a1;i<=nums[idx];i++){\nif(i>=a1 && nums[idx]-i<=nums[idx-1]-a1){\na+=solve(idx+1,nums,i,dp)...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n\t\tconst int MOD = 1e9+7;\n\t\tint size = nums.size();\n\t\tvector<int> dp(nums[0] + 1, 1);\n\n\t\tint last = nums[0];\n\t\tfor (int index = 1; index < size; index++) {\n\t\t\tint num = nums[index];\n\t\t\tvector<int> new_dp(num + 1, 0)...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n int n = nums.size();\n const int Mod = 1e9 + 7;\n vector<int> dp(nums[0] + 1, 1);\n \n for (int i = 1; i < n; i++) {\n vector<int> dp2(nums[i] + 1);\n for (int j = 1; j <= nums[i ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& k) {\n int n=k.size();\n vector<int>dp;\n \n int ans=0;\n int M=1e9+7;\n for(int i=0;i<n;i++){\n vector<int>dp1(k[i]+2);\n for(int j=0;j<=k[i];j++){\n if(i==0){dp1[j+1...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n constexpr int mod = 1e9 + 7;\n int n = nums.size();\n int limit = nums[n-1];\n nums.push_back(limit);\n vector<int> dp(limit + 2, 1);\n\n for(int i=0; i<n; i++) {\n vector<int> prefix...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int mod=1e9+7;\n int countOfPairs(vector<int>& nums) {\n int n=nums.size(),sum=0;\n int maxx=nums[nums.size()-1];\n vector<vector<int>>dp(nums.size(),vector<int>(maxx+1,0));\n for(int i=0;i<=min(maxx,nums[0]);i++){\n dp[0][i]=1;\n ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n vector<vector<int>> numPairs(nums.size(), vector<int>(nums.back() + 1, -1));\n\n return countOfPairs(0, 1000, 0, nums, numPairs);\n }\n \nprivate:\n int countOfPairs(int prev1, int prev2, int pos, vector<int>& num...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n vector<vector<int>> numPairs(nums.size() + 1, vector<int> (nums.back() + 1, 0));\n\n for (int prev1 = nums.back(); prev1 >= 0; --prev1) numPairs[nums.size()][prev1] = 1;\n\n for (int prev1 = nums.back(); prev1 >= 0;...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "// 13:43\n\nclass Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n int n = nums.size();\n int maxv = nums[n-1];\n int md = 1000000007;\n vector<vector<int>> dp(n+1, vector<int>(maxv+1, 0));\n for (int x=0; x<=min(maxv, nums[0]); x++) {\n dp[0][x...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n constexpr int MOD = 1e9 + 7;\n int maxe = *max_element(nums.begin(), nums.end());\n vector<int> dp(maxe + 1, 1);\n int n = nums.size();\n\n for (int i = 1; i < n; i++)\n {\n vector<in...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n const int MOD = 1e9+7;\n int n = *max_element(nums.begin(), nums.end());\n vector<int> prev(n+1, 0);\n \n prev[0] = 1;\n for (int i = 1; i <= n; i++) {\n if (i <= nums[0]) prev[i] = p...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n const int MOD = 1e9+7;\n int n = *max_element(nums.begin(), nums.end());\n vector<int> prev(n+1, 0);\n \n prev[0] = 1;\n for (int i = 1; i <= n; i++) {\n if (i <= nums[0]) prev[i] = p...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n const int MOD = 1e9 + 7;\n int n = nums.size();\n int maxi = *max_element(nums.begin(), nums.end());\n\n vector<vector<int>> dp(n + 1, vector<int>(maxi + 3, 0));\n\n for (int prev1 = 0; prev1 <= maxi +...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "/*\nn = 2e3\nx = 1e3\nn*x\n*/\n\nclass Solution {\nprivate:\n int solve(vector<int> &nums) {\n int n = nums.size();\n int maxval = INT_MIN;\n for (int num: nums) maxval = max(maxval,num); \n\n vector<vector<int>> DP(n+1,vector<int>(maxval+1,0));\n vector<long long> pre...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\n int mod = 1e9 + 7;\npublic:\n int countOfPairs(vector<int>& nums) {\n int m = *max_element(nums.begin(), nums.end());\n int n = nums.size();\n\n vector<vector<int>> dp(vector<vector<int>>(m+1, vector<int>(n+1, 0)));\n dp[nums[n-1]][n-1] = 1;\n for...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution \n{\n public:\n \n int const MOD = 1e9 + 7;\n\n int countOfPairs(vector<int>& nums)\n {\n int const n = nums.size();\n int maxEl = *max_element(nums.begin(), nums.end());\n \n vector<vector<int>> dp(maxEl + 1, vector<int>(n, 0));\n dp[0][n-1]...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "#include <iostream>\n#include <random>\n#include <array>\n#include <vector>\n#include <string>\n#include <map>\n#include <unordered_map>\n#include <set>\n#include <unordered_set>\n#include <algorithm>\n#include <functional>\n#include <queue>\n#include <stack>\n#include <bitset>\n\n#include <math.h>\n\nusin...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "#include <iostream>\n#include <random>\n#include <array>\n#include <vector>\n#include <string>\n#include <map>\n#include <unordered_map>\n#include <set>\n#include <unordered_set>\n#include <algorithm>\n#include <functional>\n#include <queue>\n#include <stack>\n#include <bitset>\n\n#include <math.h>\n\nusin...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n #define ll long long\n int countOfPairs(vector<int>& nums) {\n const ll mod = 1e9 + 7;\n int n=nums.size();\n ll dp[n+1][1001];\n memset(dp,0,sizeof(dp));\n for(int i=0;i<=nums[0];i++){\n dp[0][i]=1;\n }\n for(int...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "using namespace std;\n#include<bits/stdc++.h>\n#define ll long long\n#define pb push_back\n#define all(x) x.begin(), x.end()\n#define float long double\n#define double long double\n#define sortall(x) sort(all(x))\n#define sz(a) (int)(a).size()\nconst int mod = 1e9+7;\n//<-----------------------------------...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "#define ll long long \n\nnamespace atcoder {\n\nnamespace internal {\n\n// @param m `1 <= m`\n// @return x mod m\nconstexpr long long safe_mod(long long x, long long m) {\n x %= m;\n if (x < 0) x += m;\n return x;\n}\n\n// Fast modular multiplication by barrett reduction\n// Reference: https://en....
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n#define ll long long int\n#define mod 1000000007\n\nvector<vector<ll>> dp;\nll f(vector<int> &arr, int i, int prevS, int prevG)\n{\n if(i>=arr.size())\n return 1;\n\n if(dp[i][prevS]!=-1)\n return dp[i][prevS];\n\n ll ans = 0;\n for(int j=0;j<=arr[i];j++)\n {...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "#include <bits/stdc++.h>\n#pragma GCC optimize(2)\n#define rep(i, a, b) for (int i = (a); i < (b); ++i)\n#define rep_(i, a, b) for (int i = (a); i > (b); i--)\n#define mst(x, a) memset(x, a, sizeof(x))\n#define all(a) begin(a), end(a)\n#define lowbit(x) ((x) & (-(x)))\n#define bitcnt(x) (__builtin_popcount...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "#define MOD 1000000007\n#define ll long long\nclass Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n vector<ll> pSum(nums[0]+1);\n for(int i=0; i<=nums[0]; ++i){\n pSum[i] = i+1;\n }\n for(int i=1; i<nums.size(); ++i){\n vector<ll> pSumNext(...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n int n=nums.size();\n int mini=INT_MAX;\n long long int mod=1e9+7;\n \n vector<int>v[n];\n v[0].push_back(0);\n for(int i=1;i<n;i++)\n {\n if(nums[i]<=nums[i-1])\n ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "#define ll long long \nconst ll M = 1e9 + 7 ;\nclass Solution {\npublic:\n \n int countOfPairs(vector<int>& nums) {\n int n = nums.size() ;\n int mx = *max_element(nums.begin(),nums.end()) ;\n vector<int>dp(mx+1) ;\n for(int i =0;i<=nums[0];i++){\n dp[i] = 1 ;\n...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "#define ll long long \nconst ll M = 1e9 + 7 ;\nclass Solution {\npublic:\n \n int countOfPairs(vector<int>& nums) {\n int n = nums.size() ;\n int mx = *max_element(nums.begin(),nums.end()) ;\n vector<int>dp(mx+1) ;\n for(int i =0;i<=nums[0];i++){\n dp[i] = 1 ;\n...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "const int M = 1e9 + 7 ;\nclass Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n int n = nums.size() ;\n int mx = *max_element(nums.begin(),nums.end()) ;\n vector<int>dp(mx+1) ;\n for(int i =0;i<=nums[0];i++){\n dp[i] = 1 ;\n }\n int ans =...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n const int MOD = 1e9 + 7;\n\n int countOfPairs(vector<int>& nums) {\n int n = nums.size();\n int max_value = *max_element(nums.begin(), nums.end());\n vector<vector<int>> dp(n, vector<int>(max_value + 1, 0));\n\n // Initialize base case for dp[0]...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\n #define MOD 1000000007\n void print(vector<int>& v)\n {\n for (int n: v) {\n cout << n << \" \";\n }\n cout << \"\\n\";\n }\npublic:\n int countOfPairs(vector<int>& nums) {\n vector<int> pre(nums.back()+1, 1);\n\n //print(pre);...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& a) {\n int n=a.size();\n int dp[n+1][2010];\n memset(dp,0,sizeof(dp));\n dp[1][0]=1;\n for(int i=1;i<=a[0];i++){\n dp[1][i]=1+dp[1][i-1];\n }\n int MOD=1e9+7;\n for(int i=2;i<=n;i...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n long long MOD = 1e9+7;\n int n = (int)nums.size();\n vector<vector<long long>> dp(n);\n dp[0].resize(nums[0] + 1);\n for (int i = 0; i<=nums[0]; ++i)\n dp[0][i] = 1;\n \n for (...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n long long MOD = 1e9+7;\n int n = (int)nums.size();\n vector<vector<long long>> dp(n);\n dp[0].resize(nums[0] + 1);\n for (int i = 0; i<=nums[0]; ++i)\n dp[0][i] = 1;\n \n for (...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n long long MOD = 1e9+7;\n int n = (int)nums.size();\n vector<vector<long long>> dp(n);\n dp[0].resize(nums[0] + 1);\n for (int i = 0; i<=nums[0]; ++i)\n dp[0][i] = 1;\n \n for (...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int mod=1e9+7;\n int countOfPairs(vector<int>& nums) {\n int n=nums.size();\n int m=nums[n-1];\n vector<vector<long long>>dp(m+1, vector<long long>(n));\n /* \n dp[i][j] means total number of monotonic pair till index j when the value a...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n int n = nums.size();\n int mod = 1e9 + 7;\n vector<long long> dp(nums.back()+1, 1);\n for (int i=1; i<nums.size(); i++) {\n vector<long long> tmp(dp.size(), 0);\n int df = max(0, nums[n-...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n int mod = 1e9 + 7;\n int n = nums.size();\n vector<int> dp;\n for (int i = 0; i < n; ++i) {\n vector<int> tmp;\n for (int j = 0; j <= nums[i]; ++j) {\n if (j == 0) {\n ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int cp(vector<int>& nums) {\n const int MODULO = 1e9 + 7;\n vector<int> prefix_sum(nums[0] + 1, 1);\n partial_sum(prefix_sum.begin(), prefix_sum.end(), prefix_sum.begin());\n \n auto get = [&](int k) -> int {\n return k > -1 ? pre...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n // inc: a, dec: b, target: c,\n // range: x (a -> c), c - x <= b, max(a, c-b) -> c\n // dp -> a: 0-> c\n\n int max_n = 0;\n for(auto e: nums) max_n = max(max_n, e);\n vector<vector<long long>> ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n long long mod = 1e9+7;\n int findBackSum (int pos , vector<int>&prefixSum , int target , vector<int>&nums, int back){\n \n int start = 0, end = pos;\n int ans = -1;\n while(start <= end){\n int mid = start + (end-start)/2;\n ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n const int mod = 1000000007;\n \n int countOfPairs(vector<int>& nums) {\n int n = nums.size();\n int maxNum = *max_element(nums.begin(), nums.end());\n vector<vector<long>> dp(maxNum + 1, vector<long>(n+1,-1));\n vector<long> pre(maxNum + 1,0)...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "#include <bits/stdc++.h>\n#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\n\n#define ll long long\n#define ar array\n// #define int ll\n#define sz(v) (int)(v.size())\n#define FIO ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "\ntemplate <int MOD_> struct modnum {\n static constexpr int MOD = MOD_;\n static_assert(MOD_ > 0, \"MOD must be positive\");\n using ll = long long;\n int v;\n static int minv(int a, int m) {\n a %= m;\n assert(a);\n return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n long long int n = nums.size();\n long long int mx = 0 ;\n long long int mod = 1000000007;\n for(int i = 0 ; i<n ;i++) mx = max(mx, (long long)nums[i]);\n vector<vector<long long int>>dp(n+1, vector<lon...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "typedef long long ll;\nclass Solution {\npublic:\n int M= 1e9+7;\n int countOfPairs(vector<int>& nums) {\n int n= nums.size();\n int mx=0;\n for(int i=0;i<n;i++){\n mx= max(mx, nums[i]);\n }\n vector<vector<ll>> dp(n+1, vector<ll> (mx+1,0));\n for(...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n int mod=1e9+7;\n int n=nums.size();\n int maxi=nums[0];\n for(auto it:nums) maxi=max(maxi,it);\n vector<vector<int>> dp(n,vector<int>(maxi+1,0)),pre(n,vector<int>(maxi+1));\n for(int i=0 ;i<=max...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "\ntemplate<typename T> istream& operator>>(istream &in, vector<T>& a) { for(auto &x:a) in >> x; return in; }\ntemplate<typename F,typename S> istream& operator>>(istream &in, pair<F,S>& a) { in >> a.first >> a.second; return in; }\ntemplate<typename T> ostream& operator<<(ostream &out, vector<T>& a) { for...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\npublic:\n int countOfPairs(vector<int>& nums) {\n int mod = 1e9 + 7;\n int n = nums.size(); int m = *max_element(nums.begin(), nums.end());\n long long dp[n + 1][m + 1]; // ith index & increasing value is j\n for (int i = 0; i <= n; i++)\n for (in...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "class Solution {\n int mod = 1e9 + 7;\npublic:\n int countOfPairs(vector<int>& nums) {\n int m = *max_element(nums.begin(), nums.end());\n int n = nums.size();\n\n vector<vector<int>> dp(vector<vector<int>>(m+1, vector<int>(n+1, 0)));\n\n for (int j = n; j >= 0; j--) {\n ...
3,536
<p>You are given an array of <strong>positive</strong> integers <code>nums</code> of length <code>n</code>.</p> <p>We call a pair of <strong>non-negative</strong> integer arrays <code>(arr1, arr2)</code> <strong>monotonic</strong> if:</p> <ul> <li>The lengths of both arrays are <code>n</code>.</li> <li><code>arr1</...
1
{ "code": "const int M = 1e9 + 7;\nclass SegmentTree{\n int n;\n vector<int> Seg;\n int query(int i, int sL, int sR, int qL, int qR){\n if(sL > qR || sR < qL) return 0;\n if(sL >= qL && sR <= qR) return Seg[i];\n\n int left_sum = query(2 * i + 1, sL, (sL + sR) / 2, qL, qR);\n int ...