id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n vector<int>bad_indexes;\n\n int n = colors.size();\n\n for(int i = 0;i<n;i++)colors.push_back(colors[i]);\n\n for(int i = 1;i<2*n;i++){\n if(colors[i] == colors[i - 1])bad_ind... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n int n = colors.size();\n for (int i = 0; i < n; i++) \n colors.push_back(colors[i]); \n\n set<int> invalids; \n int ans = 0;\n \n for (int i = 1; i < k; i++) {\n... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "#define ll long long \nclass Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n int n=colors.size();\n int ans=0;\n int cnt=1;\n int last=colors[0];\n for(int i=1;i<n;++i){\n if(colors[i]!=last){\n cnt++;\n ... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n\n vector<int> pref;\n int prev = -1;\n int count = 0;\n int ans = 0;\n\n for(int i = 0; i<colors.size(); i++){\n if(prev != colors[i]){\n prev = colors[i];... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& c, int k) {\n int n=c.size();\n for(int i=0;i<n;i++){\n c.push_back(c[i]);\n }\n c.push_back(c[0]);\n // int ans=0;\n priority_queue <int, vector<int>, greater<int> >q;\n for(... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "using vi = vector<int>;\nclass Solution {\npublic:\n int n;\n vi color;\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n \n this->color = colors;\n\n for(int i=0; i<=k-2; i++) color.push_back(color[i]);\n\n n = color.size();\n\n int ans = 0;\n\n ... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n vector<int>cols = colors;\n for (int i=0; i<k-1; i++) cols.push_back(colors[i]);\n\n int ans = 0;\n int i=0, j=1;\n\n while (j<cols.size()) {\n if (cols[j-1]==cols[j]) ... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n \n vector<int> extendedColors = colors;\n \n for (int i = 0; i < k - 1; ++i){\n extendedColors.push_back(colors[i]);\n }\n \n int ans = 0;\n int c... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n int maxlength=1;\n int ans=0;\n int n=colors.size();\n // if(n==3){\n // if(colors[1]!=colors[0] && colors[1]!=colors[2]){\n // return 1;\n // }\n ... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "class Solution {\npublic:\n const int mod=1e9+7;\n \n long long get_hash(vector<int>& a) {\n long long h=0;\n long long p=1;\n int n=a.size();\n for(int i=n-1;i>=0;i--) {\n h=(h+(a[i]+1)*p*1ll)%mod;\n p=(p*31*1ll)%mod;\n }\n return h;... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& nums, int k) {\n int i = 0, prev = nums[i], j = 1, n = nums.size(), cnt = 0,idx=n;\n if(nums[0]==nums[n-1]) {\n idx=0;\n }\n else{\n for(int i=0; i<n-1; i++){\n if(nums[i]=... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "class Solution {\npublic:\n\n int numberOfAlternatingGroups(std::vector<int>& c, int k) {\n c.insert(c.end(), c.begin(), c.begin() + k);\n int n = c.size();\n int count = 0;\n std::vector<int> vec(n + 1, 0);\n for (int i = 1; i < n; ++i) {\n vec[i] = vec[i -... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "static const int __ = [](){\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return 0;\n}();\nclass Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& c, int k) {\n int res=0;\n c.insert(c.end(),c.begin(),c.begin()+k);\n int n=... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& c, int k) {\n for(int i=0;i<k-1;i++)\n c.push_back(c[i]);\n int n=c.size();\n int i=0,j=1;\n vector<int>val(n,0);\n val[0]=c[0];\n for(int i=1;i<n;i++)\n val[i]+=c[i]+val[i-1];\... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n int n = colors.size();\n int l = 0, r = 0;\n int ret = 0;\n vector<int> v(colors.begin(), colors.end());\n v.insert(v.end(), colors.begin(), colors.end());\n while (l < n) ... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "class Solution \n{\npublic:\n int numberOfAlternatingGroups(vector<int>& color, int k) \n {\n vector<int> colors=color;\n colors.insert(colors.end(),color.begin(),color.end());\n int ans=0, len=1, prev=colors[0];\n for(int x=1; x<=color.size()-1+k-1; x++)\n {\n ... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n for(int j=0;j<k-1;j++)\n colors.push_back(colors[j]);\n int ans=0;\n int sz=colors.size();\n vector<int> dp(sz,1);\n for(int i=1;i<sz;i++)\n {\n if(co... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "class Solution {\n bool func(vector<pair<int,int>>& vec, int left, int right)\n {\n pair<int,int> temp = {right, INT_MIN};\n int idx = lower_bound(vec.begin(), vec.end(), temp) - vec.begin();\n int mn = INT_MIN;\n \n if (idx > 0) {\n idx--;\n m... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& v, int k) {\n int n = v.size();\n\n for (int i = 0; i < k - 1; i++)\n v.push_back(v[i]);\n\n int m = v.size();\n vector<int> pref(m, 0);\n for (int i = 1; i < m; i++) {\n pref[... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "class Solution {\npublic:\n// n-k+1\n bool check(int i,int j,vector<int>& colors){\n for(int x=i+1;x<=j;x++){\n if(colors[x]==colors[x-1])return false;\n }\n return true;\n }\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n vector<int> vec(... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n colors.insert(colors.end(), colors.begin(), colors.begin() + k-1);\n int n = colors.size();\n deque<int> q;\n int count = 0;\n\n for (int i=0; i<n; i++){\n bool same = ... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n int i=0;\n \n while(i<k-1){\n colors.push_back(colors[i++]);\n }\n \n i=0;\n \n deque<int> dq;\n int cnt=0;\n int n=colors.size();\n ... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "class Solution {\n private:\n int solver(vector<int>&temp,int k){\n return temp.size()-k+1;\n }\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n int n=colors.size();\n vector<vector<int>> arr;\n for(int i=0;i<n;i++){\n vector<int>tem... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "#define pb push_back\nclass Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n int n=colors.size();\n\n for(int i=0;i<k-1;i++){\n colors.pb(colors[i]);\n }\n\n int res=0,i=0;\n while(i<n){\n queue<int> q;\n ... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "#define pb push_back\nclass Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n int n=colors.size();\n\n for(int i=0;i<k-1;i++){\n colors.pb(colors[i]);\n }\n\n int res=0,i=0;\n while(i<n){\n queue<int> q;\n ... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n vector<int> arr;\n int n=colors.size();\n for(int i=n-k+1;i<n;i++){\n \n arr.push_back(colors[i]);\n }\n\n for(int i=0;i<n;i++){\n arr.push_back(colo... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n int n=colors.size();\n vector<int> v;\n for(int i=0; i<n; i++){\n v.push_back(colors[i]);\n }\n for(int i=0; i<k-1; i++){\n v.push_back(colors[i]);\n ... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n \n int n = colors.size();\n\n vector<int> v;\n for(int i=0;i<n;i++) v.push_back(colors[i]);\n for(int i=0;i<k-1;i++) v.push_back(colors[i]);\n\n vector<int> size; // stores... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n int ans = 0;\n colors.insert(colors.begin(), colors.begin(), colors.end());\n \n int n = colors.size();\n int next_bad = INT_MAX;\n vector<int> bad_to_right(n, INT_MAX);\n ... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors2, int k) {\n int c=1;\n int n=colors2.size();\n vector<int>colors;\n for(int i=0;i<n;i++){\n colors.push_back(colors2[i]);\n }\n for(int i=0;i<k-1;i++){\n ... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "\nclass Solution\n{\npublic:\n\tint numberOfAlternatingGroups(vector<int> &colors, int k)\n\t{\n\t\tint n = colors.size();\n\t\tvector<int> oddsum(2 * n);\n\t\tvector<int> evensum(2 * n);\n\n\t\tevensum[0] = colors[0] == 1;\n\n\t\tfor (int i = 1; i < 2 * n; i++)\n\t\t{\n\t\t\toddsum[i] = oddsum[i - 1];\n\t... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& colors, int k) {\n int n = colors.size();\n vector<int> extended_colors(colors);\n extended_colors.insert(extended_colors.end(), colors.begin(), colors.begin() + k - 1);\n\n vector<int> pref(extended_color... |
3,483 | <p>There is a circle of red and blue tiles. You are given an array of integers <code>colors</code> and an integer <code>k</code>. The color of tile <code>i</code> is represented by <code>colors[i]</code>:</p>
<ul>
<li><code>colors[i] == 0</code> means that tile <code>i</code> is <strong>red</strong>.</li>
<li><code>... | 3 | {
"code": "class Solution {\npublic:\n int numberOfAlternatingGroups(vector<int>& a, int k) {\n int n = a.size();\n for(int i=0;i<n;i++)a.push_back(a[i]);\n vector<int> p(2*n);\n p[0]=0;\n for(int i=1;i<2*n;i++){\n p[i] = p[i-1]+((a[i]==a[i-1])?0:1);\n }\n ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 0 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n long long res = 0;\n int lo = 0, hi = 0;\n for (int i = 0; i < nums.size(); ++i) {\n int x = nums[i];\n for (int j = i - 1; j >= 0 && (nums[j] & x) != nums[j]; --j) {\n ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 0 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n long long res = 0;\n int n = nums.size();\n int cnt = 0;\n for (int r = 0; r < n; ++r) {\n cnt += nums[r] == k;\n for (int l = r - 1; l >= 0; --l) {\n if ((... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 1 | {
"code": "class Solution {\npublic:\n\n // limit for array size\n const int N = 100001;\n\n int n; // array size\n\n // Max size of tree\n int tree[2 * 100001];\n\n // function to build the tree\n void build( vector<int> arr)\n {\n // insert leaf nodes in tree\n for (int i=0; i<... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 1 | {
"code": "\n\nclass Solution {\npublic:\n\n // limit for array size\n const int N = 100001;\n\n int n; // array size\n\n // Max size of tree\n int tree[2 * 100001];\n\n // function to build the tree\n void build( vector<int> arr)\n {\n // insert leaf nodes in tree\n for (int i=0... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 1 | {
"code": "const int max_logn=20;\nconst int maxn=1e5+5;\ntemplate<typename T>\nstruct SparseTable{\n int log[maxn];\n T dp[max_logn][maxn];\n T combine(T a,T b){\n return a&b;\n }\n SparseTable(){\n log[1] = 0;\n for (int i = 2; i < maxn; i++)\n log[i] = log[i/2] + 1;\n }\n void build(vector<T> ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 1 | {
"code": "#define ll long long\nclass Solution {\npublic:\n long long countSubarrays(vector<int>& arr, int k) {\n int n=(int)arr.size();\n int lg[n+1];\n lg[1]=0;\n for(int i=2;i<=n;i++)\n {\n lg[i]=lg[i/2]+1;\n }\n int pre[25][n+1];\n copy(arr.be... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 1 | {
"code": "#include <bits/stdc++.h>\n#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\n#pragma GCC optimize (\"Ofast\")\n//#pragma GCC optimize \"trapv\" // to detect overflow\n\n#define ll long long\n#define ar array\n#define sz(v) ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 1 | {
"code": "#include <bits/stdc++.h>\n#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\n#pragma GCC optimize (\"Ofast\")\n//#pragma GCC optimize \"trapv\" // to detect overflow\n\n#define ll long long\n#define ar array\n#define sz(v) ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 1 | {
"code": "class SegmentTree {\n private:\n int N;\n vector<int> v, Tree;\n int base;\n int ll;\n int rr;\n \n int update(int a, int b){\n return a&b;\n }\n\n void buildTree(int tidx, int lo, int hi){\n if(lo==hi){\n ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 1 | {
"code": "using i64 = long long;\nclass Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int n = nums.size();\n unordered_map<int,int> mp;\n i64 res = 0;\n for (int i = 0; i < n; i++){\n mp[nums[i]]++;\n int cur = nums[i];\n ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 1 | {
"code": "using i64 = long long;\nclass Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int n = nums.size();\n map<int,int> mp;\n i64 res = 0;\n for (int i = 0; i < n; i++){\n mp[nums[i]]++;\n int cur = nums[i];\n for (int j... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 1 | {
"code": "class Solution {\npublic:\n \n vector<long long> tree ;\n\n\n void buildSegmentTree(int nodeIndex, int nodeRangeLeft, int nodeRangeRight, vector<int>&A){\n if(nodeRangeLeft == nodeRangeRight){\n // leaf node\n tree[nodeIndex] = A[nodeRangeLeft];\n return ;\n ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 1 | {
"code": "class Solution {\npublic:\n \n vector<long long> tree ;\n\n\n void buildSegmentTree(int nodeIndex, int nodeRangeLeft, int nodeRangeRight, vector<int>&A){\n if(nodeRangeLeft == nodeRangeRight){\n // leaf node\n tree[nodeIndex] = A[nodeRangeLeft];\n return ;\n ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 1 | {
"code": "class Solution {\npublic:\n \n vector<long long> tree ;\n\n\n void buildSegmentTree(int nodeIndex, int nodeRangeLeft, int nodeRangeRight, vector<int>&A){\n if(nodeRangeLeft == nodeRangeRight){\n // leaf node\n tree[nodeIndex] = A[nodeRangeLeft];\n return ;\n ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 1 | {
"code": "#define ll long long\n\nstruct node {\n ll val;\n};\n\nclass segmentTree {\n public:\n vector<node> seg;\n vector<int> nums;\n int n;\n\n segmentTree(vector<int>& v1) {\n n = v1.size();\n nums = v1;\n seg.resize(4 * n);\n }\n\n node merge(node n1, node n2) { \n ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 1 | {
"code": "#define ll long long\ntemplate<typename Node, typename Update>\nstruct SegTree {\n\tvector<Node> tree;\n\tvector<ll> arr; // type may change\n\tint n;\n\tint s;\n\tSegTree(int a_len, vector<ll> &a) { // change if type updated\n\t\tarr = a;\n\t\tn = a_len;\n\t\ts = 1;\n\t\twhile(s < 2 * n){\n\t\t\ts = s << ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 1 | {
"code": "// Vanilla Segment Tree\n// O(n log n) preprocessing, O(log n) query, O(log n) update\nstruct SumInt {\n using T = long long;\n const T e = 0;\n T f(T a, T b) const { return a + b; }\n};\nstruct MaxInt {\n using T = long long;\n const T e = LLONG_MIN;\n T f(T a, T b) const { return max(a,... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 1 | {
"code": "class Solution {\npublic:\n #define ll long long int\n void build(vector<ll>&seg, vector<ll>&vec, ll ind , ll lo, ll hi)\n{\n if (lo == hi)\n {\n seg[ind] = vec[lo];\n return;\n }\n ll mid = (lo + hi) / 2;\n build(seg, vec, 2 * ind + 1, lo, mid);\n build(seg, vec, 2 * ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 1 | {
"code": "#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long\n\nclass segment_tree{\npublic:\n \n vector<ll> tree;\n segment_tree(int n)\n {\n tree.resize(4 * n +1);\n }\n\n void build(vector<int>& arr, int node, int start,int end)\n {\n if (start == end) {\n ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 1 | {
"code": "#include<bits/stdc++.h>\nusing namespace std;\n#define ll long long\n\nclass segment_tree{\npublic:\n \n vector<ll> tree;\n segment_tree(int n)\n {\n tree.resize(4 * n +1);\n }\n\n void build(vector<int>& arr, int node, int start,int end)\n {\n if (start == end) {\n ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 1 | {
"code": "class Solution {\npublic:\n int mrg(int a,int b){//EDIT\n return (a&b);\n }\n vector<vector<int>>SP;\n void build(const vector<int>&arr){\n int n = arr.size();\n SP[0]=arr;\n for(int msk = 1; (1<<msk)<=n; ++msk){\n for(int i=0; i+(1<<msk)<=n; ++i){\n ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 1 | {
"code": "class SparseTable{\n int n, m;\n vector<vector<int>> dp;\npublic:\n SparseTable(vector<int> &a) {\n n = a.size();\n m = ceil(log2(n));\n dp.resize(m, vector<int>(n));\n for (int i = 0 ; i < n ; i++) dp[0][i] = a[i];\n for (int i = 1 ; i < m ; i++) {\n ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 1 | {
"code": "typedef long long int ll;\nconst int N = 1e5+10;\nvector<int>Log(N);\nbool logBuilt = false;\nvoid buildLog(){\n for(int i=2;i<N;i++)Log[i]=Log[i/2]+1;\n}\nclass SparseTable{\n const int ID = 0;\npublic:\n int n;\n int logn;\n vector<vector<int>>dp;\n SparseTable(int _n){\n n = _n;... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 1 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n vector<int>a=nums;\n int n=a.size();\n long long ans=0;\n int p=0,x=1;\n while(x<n){\n p++;\n x*=2;\n }\n vector<vector<int>>t(p+1,vector<int>(n));\n ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 1 | {
"code": "class SparseTable\n{\n public:\n vector<vector<int>> table;\n\n SparseTable(vector<int> a)\n {\n int n = a.size();\n int k = 22; \n\n table.resize(k,vector<int>(n));\n\n for (int i = 0; i < n; i++)\n {\n table[0][i] = a[i];\n }\n\n for... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 1 | {
"code": "#include<bits/stdc++.h>\nusing namespace std;\n\n#define ll long long\ntemplate<class T, class U>\n// T -> node, U->update.\nstruct Lsegtree{\n vector<T>st;\n vector<U>lazy;\n ll n;\n T identity_element;\n U identity_update;\n Lsegtree(ll n, T identity_element, U identity_update)\n {\n... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n const int n = nums.size();\n // count[i][j] = num of elements of nums[0:i] such that the jth bit of each element is 1\n std::vector<std::array<int, 32>> count(n);\n for (int i = 0; i < n; ++i) ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n const int n = nums.size();\n std::vector<std::array<int, 32>> count(n);\n for (int i = 0; i < n; ++i) {\n if (i > 0) {\n count[i] = count[i - 1];\n }\n ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& a, int k) {\n long long ret = 0;\n\n int n = a.size();\n vector<array<int, 32>> nx(n + 1);\n nx[n].fill(n);\n for (int i = n - 1; i >= 0; i--)\n {\n nx[i] = nx[i + 1];\n for ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "int speedup = [] {ios::sync_with_stdio(0); cin.tie(0); return 0;}();\n\n\nclass Solution {\npublic:\n long long countSubarrays(vector<int>& a, int k) {\n long long ret = 0;\n\n int n = a.size();\n vector<array<int, 32>> nx(n + 1);\n nx[n].fill(n);\n for (int i = n - 1;... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "#include <bits/stdc++.h>\n#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\n#pragma GCC optimize (\"Ofast\")\n//#pragma GCC optimize \"trapv\" // to detect overflow\n\n#define ll long long\n#define ar array\n#define sz(v) ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "#include <bits/stdc++.h>\n#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\n#pragma GCC optimize (\"Ofast\")\n//#pragma GCC optimize \"trapv\" // to detect overflow\n\n#define ll long long\n#define ar array\n#define sz(v) ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<int>>sparseTable;\n int n;int LOG;\n vector<int>bin_log;\n int query(int l,int r){\n int k = bin_log[r-l+1];\n return sparseTable[l][k]&sparseTable[r-(1<<k)+1][k];\n }\n bool check(int l,int r,int k,int type){\n if(type)return... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& a, int k) {\n a.insert(a.begin(), 0);\n int n = (int) a.size() - 1;\n \n vector<int> log(n + 1);\n for (int i = 2; i <= n; i++) log[i] = log[i / 2] + 1;\n const int lg = log[n];\n vector<ve... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n long long ans = 0;\n vector<pair<int, int>> cur;\n for (int i = 0; i < nums.size(); ++i) {\n vector<pair<int, int>> nCur;\n for (auto [value, j]: cur) {\n value &=... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int n = (int)nums.size();\n vector<vector<int>>pre(32,vector<int>(n,0));\n for(int i = 0; i < n; ++i) {\n int x = nums[i];\n for(int bit = 0; bit<32; ++bit) {\n pr... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "#define ll long long\nclass Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int n = nums.size();\n ll ans = 0;\n vector<vector<int>>pref(32, vector<int>(n + 1, 0));\n for(int i = 0; i < n; i++){\n for(int j = 0; j < 32; j++)\n ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class Solution {\npublic:\n void pre_compute(vector<vector<int>>& st, vector<int>& nums) {\n for (int i = 0; i < nums.size(); ++i) {\n st[0][i] = nums[i];\n }\n\n for (int j = 1; (1 << j) <= nums.size(); ++j) {\n for (int i = 0; i + (1 << j) - 1 < nums.size(); ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "//BEGIN\n\n\ntypedef long long LL;\nstatic const int INF = 1000000000;\nstatic const int P = 1000000007;\n\n#define REP(i,n) for(int i=0;i<(n);i++)\n#define FOR(i,a,b) for(int i=(a);i<=(b);i++)\n#define FORD(i,a,b) for(int i=(a);i>=(b);i--)\n#define pb push_back\n#define ALL(a) a.begin(), a.end()\n#define ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n unordered_map<int , int> count;\n long long ans =0;\n if(nums[0]==k)\n ans++;\n count.insert({nums[0],1});\n unordered_map<int ,int >curr;\n for(int i=1;i<nums.size();i... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class Solution {\npublic:\n using ll = long long;\n long long countSubarrays(vector<int>& n, int k) {\n int size = n.size();\n vector<int> v(size, 0);\n for (int i = 0; i < size; ++i) {\n if ((n[i] & k) == k) {\n v[i] = 1;\n } \n }\n ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "// Range Maximum/Minimum Query with sparse table\n// O(n log n) preprocessing, O(1) query\nstruct MaxInt {\n using T = long long;\n const T e = LLONG_MIN;\n T f(T a, T b) const { return max(a, b); }\n};\nstruct MinInt {\n using T = long long;\n const T e = LLONG_MAX;\n T f(T a, T b) const... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n unordered_map<int, int> m1, m2;\n long long int count = 0;\n for(int num : nums){\n m1[INT_MAX] = 1;\n for(auto [key, value] : m1){\n //cout<<key<<\" \"<<value<<en... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int n=nums.size();\n long long ans=0;\n map<int,int>mp;\n for(int i=0;i<n;i++){\n map<int,int>temp;\n if((nums[i]&k)==k){\n temp[nums[i]]=1;\n ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class Solution {\npublic:\n // int and_num(vector<int>&freq_bit,int len){\n // int ans=0;\n // for(int i=0;i<32;i++){\n // if(freq_bit[i]==len) ans+=(1<<i);\n // }\n // return ans;\n // }\n // long long count_sub(vector<int>&nums,int k){\n // long ans=... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class Solution {\npublic:\n // int and_num(vector<int>&freq_bit,int len){\n // int ans=0;\n // for(int i=0;i<32;i++){\n // if(freq_bit[i]==len) ans+=(1<<i);\n // }\n // return ans;\n // }\n // long long count_sub(vector<int>&nums,int k){\n // long ans=... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class Solution {\npublic:\n\nbool check(int a,int b){\n for(int bit = 0;bit < 30;bit++){\n if( b & (1 << bit) ){\n if( !(a & (1 << bit))){ \n return false;\n }\n }\n }\n return true;\n}\n\nlong long solve(vector<int>& p,int k){\n\n int n = p.si... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "using LL = long long;\nclass Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int n = nums.size();\n unordered_map<LL, int> numsMap, temp;\n\n LL count = 0;\n for (int i = 0; i < n; i++) {\n for (const auto& [v, c] : numsMap) {\n ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n unordered_map<int, long long>mp, temp;\n\n long long ret = 0;\n for (int i=0; i<nums.size(); i++) {\n for (auto [k, count]: mp)\n temp[k&nums[i]] += count;\n temp[... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n unordered_map<int, long long>mp, temp;\n\n long long ret = 0;\n for (int i=0; i<nums.size(); i++) {\n for (auto [k, count]: mp)\n temp[k&nums[i]] += count;\n temp[... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n vector<int>v(32);\n int n=nums.size();\n map<int,int>mp;\n\n for(int i=0;i<32;i++)\n {\n int bit= (1<<i)&k;\n\n if(bit)\n {\n v[i]=1;\n ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n map<int,long long>mpp;\n long long ans=0;\n for(auto x: nums){\n map<int,long long>mpp1;\n if((x&k) == k){\n for(auto [a,b]: mpp){\n mpp1[a&x]+=... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class Solution {\n using LL = long long;\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n // goal : find the number of subarrays s.t. their bitwise and values are\n // equal to k\n \n // 1. cal the value of subarrays end at i, 0 <= i < n \n ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "using LL=long long;\nclass Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int n=nums.size();\n LL ret=0;\n unordered_map<int,LL> tmp,mp;\n for(int i=0;i<n;i++){\n for(auto [num,cnt]:mp)\n tmp[num&nums[i]]+=cnt;\n ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class SparseTable {\n vector<vector<long>> st;\n vector<long > log_table;\n long siz;\n\npublic:\n SparseTable(const vector<int>& arr) {\n siz = arr.size();\n int max_log = log2(siz) + 1;\n st.resize(siz, vector<long >(max_log));\n log_table.resize(siz + 1);\n\n\n ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class SparseTable {\n vector<vector<long>> st;\n vector<long > log_table;\n long n;\n\npublic:\n SparseTable(const vector<int>& arr) {\n n = arr.size();\n int max_log = log2(n) + 1;\n st.resize(n, vector<long >(max_log));\n log_table.resize(n + 1);\n\n\n log_... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n // AND will only go decreasing, at most 32 ANDS are possible -> store the pevious ANDS and then calculate all the ANDS possible with current number, and count the number of k in the map\n unordered_map<long ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>&v, int k) {\n int n=v.size();\n vector<vector<int>> pre(n+1,vector<int>(32,0));\nfor(int i=0;i<n;i++){\n for(int j=0;j<32;j++){\n if((v[i]>>j)&1){\n pre[i+1][j] = 1;\n }\n }\n}\nfor(int i=1;i<=n;i++){... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& a, int k) {\n long long int n = a.size();\n map<long long int, long long int> mp;\n vector<pair<long long int, long long int>> prev;\n for (long long int i = 0; i < n; i++) {\n vector<pair<long long ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& a, int k) {\n long long int n = a.size();\n map<long long int, long long int> mp;\n vector<pair<long long int, long long int>> prev;\n for (long long int i = 0; i < n; i++) {\n vector<pair<long long ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "#define ll long long\nclass Solution {\npublic:\n long long countSubarrays(vector<int>& v, int k) {\n ll n = v.size(), ans = 0;\n map<int, int> mp, nmp;\n for(auto x: v){\n nmp.clear();\n for(auto e: mp) nmp[e.first & x] += e.second;\n nmp[x]++;\n ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class Solution {\npublic:\n long long GetKCntFromMap(map<int,long long> &m, int k) {\n if(m.find(k) != m.end()) return m[k];\n return 0;\n }\n long long countSubarrays(vector<int>& nums, int k) {\n map<int,long long> possibleVal[2];\n possibleVal[0][nums[0]] = 1;\n ... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "#include<bitset>\nclass Solution {\npublic:\n\n int get(vector<vector<int>>& bit , int i , int j){\n if(i > j){\n return (1<<30) - 1;\n }\n int num = 0;\n for(int k = 0 ; k < 32 ; k++){\n if( bit[j+1][k] - bit[i][k] == 0 ){\n // cout<<i<<\... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n vector<vector<int>> indexes(30, vector<int>());\n vector<int> pick;\n vector<int> unpick;\n for(int d=0; d < 30; d++){\n indexes[d].push_back(-1);\n if (((1<<d) & k )== 0)... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n long long ans = 0;\n map<int, int> prev;\n for (auto num: nums) {\n map<int, int> curr;\n for (auto [key ,value] : prev) {\n curr[key & num]+=value;\n }\n... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "class Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n long long ans = 0;\n map<int, int> prev;\n for (auto num: nums) {\n map<int, int> curr;\n for (auto [key ,value] : prev) {\n curr[key & num]+=value;\n }\n... |
3,466 | <p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return the number of <span data-keyword="subarray-nonempty">subarrays</span> of <code>nums</code> where the bitwise <code>AND</code> of the elements of the subarray equals <code>k</code>.</p>
<p> </p>
<p><strong class="example">Example... | 2 | {
"code": "#define ll long long\nclass Solution {\npublic:\n long long countSubarrays(vector<int>& nums, int k) {\n int n = nums.size();\n ll ans=0;\n map<int,int> prev_and;\n for(auto it:nums){\n map<int,int> cur_and;\n for(auto [val,cnt]:prev_and){\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.