id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
3
{ "code": "#define ll long long int\nclass Solution {\npublic:\n int maxValue(vector<int>& nums, int k) {\n ll n=nums.size();\n set<pair<ll,ll>> s;\n vector<ll> adj1[n];\n s.insert({0,0});\n map<ll,ll> store;\n for(ll i=0;i<n;i++){\n vector<pair<ll,ll>> v;\n ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
3
{ "code": "class Solution {\npublic:\n vector<vector<vector<int>>>calc(vector<int>& nums, int k) \n {\n int n=nums.size();\n vector<vector<vector<int>>>dp(n+2,vector<vector<int>>(k+2,vector<int>(129,0)));\n dp[0][0][0]=1;\n for(int i=0;i<n;i++)\n {\n for(int l=0;l<=...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
3
{ "code": "class Solution {\npublic:\n\n void dfs(vector<int> &nums,vector<vector<vector<int>>> &dp,int k)\n {\n int n = nums.size();\n dp[0][1][nums[0]]=1;\n dp[0][0][0] = 1;\n for(int i=1;i<n;i++){\n dp[i][0][0] = 1;\n dp[i][1][nums[i]]=1;\n for(int...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
3
{ "code": "\nclass Solution {\npublic:\n vector<vector<vector<int>>> pos(vector<int>nums,int k)\n {\n int n = nums.size();\n vector<vector<vector<int>>> dp(\n n, vector<vector<int>>(k + 1, vector<int>(129)));\n dp[0][1][nums[0]] = 1;\n dp[0][0][0] = 1;\n\n for (int ...
3,575
<p>You are given an integer array <code>nums</code> and a <strong>positive</strong> integer <code>k</code>.</p> <p>The <strong>value</strong> of a sequence <code>seq</code> of size <code>2 * x</code> is defined as:</p> <ul> <li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 *...
3
{ "code": "class Solution {\npublic:\n\n void dfs1(vector<int> &nums,vector<vector<vector<int>>> &dp,int k){\n int n = nums.size();\n // vector<vector<vector<int>>> dp(\n // n, vector<vector<int>>(k + 1, vector<int>(129)));\n dp[0][1][nums[0]] = 1;\n dp[0][0][0] = 1;\n\n ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
0
{ "code": "const int _fast_io = []() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); return 0; }();\nclass Solution {\n void insertLIS(vector<int>& s, int y) {\n auto iter = lower_bound(s.begin(), s.end(), y);\n if(iter == s.end()) {\n s.push_back(y);\n } else {\n ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
0
{ "code": "bool custom(vector<int> &a,vector<int> &b){\n if(a[0]==b[0]) return a[1]>b[1];\n return a[0]<b[0];\n}\nclass Solution {\npublic:\n int maxPathLength(vector<vector<int>>& coordinates, int k) {\n int x=coordinates[k][0],y=coordinates[k][1],n=coordinates.size(),found=0,lwrsz=0;\n sort(c...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
0
{ "code": "class Solution {\npublic:\n int maxPathLength(vector<vector<int>>& C, int k) {\n int kx = C[k][0], ky = C[k][1];\n int n = C.size();\n\n sort(C.begin(), C.end(), [&](auto &a, auto &b) {\n if(a[0] == b[0]) return (a[1] > b[1]);\n return (a[0] < b[0]);\n }...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
0
{ "code": "class Solution {\npublic: \n const int N = 1e5 + 1;\n typedef pair<int, int> ii;\n typedef pair<ii, int> iii;\n int n;\n iii q[100001];\n int tmp[100001];\n\n struct BITx {\n int bit[100001];\n int n;\n void init(int m) {\n n = m;\n for(int i...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
1
{ "code": "class Solution {\npublic:\n int LIS(vector<pair<int,int>> &arr)\n {\n int n=arr.size();\n vector<int> dp(n+1, INT_MAX);\n dp[0]=INT_MIN;\n int ans=0;\n for(int i=0; i<arr.size(); i++)\n {\n int val=-arr[i].second;\n int l = upper_bound(d...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
1
{ "code": "class Solution {\npublic:\n int maxPathLength(vector<vector<int>>& coordinates, int k) {\n int X = coordinates[k][0];\n int Y = coordinates[k][1];\n vector<pair<int,int>>A;\n for(auto &x : coordinates) {\n if(x[0] < X && x[1] < Y) {\n A.push_back({x[...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
1
{ "code": "#define F first\n#define S second\n\nclass Solution {\npublic:\n static bool cmp(pair<int,int>a, pair<int,int>b) {\n if(a.F == b.F) return a.S > b.S;\n return a.F < b.F;\n }\n\n int LIS (vector<pair<int,int>> &points)\n {\n vector<int> lis;\n vector<int> arr;\n ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
1
{ "code": "class Solution {\npublic:\n static bool cmp(pair<int,int>a,pair<int,int>b) // if x coordinates differ then keep the smaller x first else keep greater y first\n {\n if(a.first==b.first) return a.second>b.second;\n return a.first<b.first;\n }\n int LIS (vector<pair<int,int>> &points...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
1
{ "code": "class Solution {\npublic:\n int lis(vector<int>& a) {\n vector<int> dp(a.size() + 1, INT_MAX);\n dp[0] = INT_MIN;\n \n for (int i = 0; i < a.size(); ++i) {\n int l = upper_bound(dp.begin(), dp.end(), a[i]) - dp.begin();\n if (a[i] > dp[l-1] && a[i] < dp[...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
1
{ "code": "\nbool comp(vector<int>&a, vector<int>&b){\n if(a[0]==b[0]){\n return a[1]>b[1];\n }\n\n return a[0]<b[0];\n}\n\nclass Solution {\npublic:\n\n int bs2(vector<vector<int>>&temp, vector<int>&x, int y){\n int st=0, ed=y-1;\n\n while(st<=ed){\n int mid=(st+ed)>>1;\n...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
1
{ "code": "class Solution {\npublic:\n\n int lis(vector<int>&arr){\n int n = arr.size();\n vector<int>temp;\n temp.push_back(arr[0]);\n for(int i=1; i<n; i++){\n if(arr[i]>temp.back()){\n temp.push_back(arr[i]);\n }\n else{\n ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
1
{ "code": "class Solution {\npublic:\n\n int liscal(vector<int>& arr){\n for(auto it:arr) cout<<it<<\" \";\n cout<<endl;\n vector<int> lis;\n lis.push_back(arr[0]);\n\n for(int i=1;i<arr.size();i++){\n int last=lis.back();\n if(arr[i]<=lis[0]) continue;\n\n ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
1
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n\n// Fenwick Tree (Binary Indexed Tree) for Range Maximum Queries\nstruct FenwickTree {\n int size;\n vector<int> tree;\n\n FenwickTree(int n) : size(n), tree(n + 1, 0) {}\n\n // Update the tree with the maximum value at position idx\n void upd...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
1
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n\n// Fenwick Tree (Binary Indexed Tree) for Range Maximum Query\nstruct FenwickTree {\n int size;\n vector<int> tree;\n\n FenwickTree(int n) : size(n), tree(n + 1, 0) {}\n\n // Update the tree at position 'idx' with value 'val'\n void update_tr...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
1
{ "code": "template <class Info>\nstruct SegmentTree {\n#define lson(p) (p << 1)\n#define rson(p) ((p << 1) | 1)\n\n static const int MAXN = 100004 << 2;\n\n int L[MAXN], R[MAXN];\n Info nodes[MAXN];\n\n void build(int p, int l, int r) {\n L[p] = l, R[p] = r;\n if (l == r) {\n nodes[p] = Info();\n }...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
1
{ "code": "template <class Info>\nstruct SegmentTree {\n#define lson(p) (p << 1)\n#define rson(p) ((p << 1) | 1)\n\n static const int MAXN = 100004 << 2;\n\n int L[MAXN], R[MAXN];\n Info nodes[MAXN];\n\n void build(int p, int l, int r) {\n L[p] = l, R[p] = r;\n if (l == r) {\n nodes[p] = Info();\n }...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
2
{ "code": "class Solution {\npublic:\nstatic bool comp(vector<int> &a, vector<int> &b) {\n\tif (a[0] != b[0]) return a[0] < b[0];\n\treturn a[1] > b[1];\n}\n\nint LIS(vector<vector<int>> &arr) {\n int n = arr.size();\n vector<int> dp;\n for(int i=0; i<n; i++) {\n int y = arr[i][1];\n auto it = ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
2
{ "code": "class Solution {\npublic:\n int maxPathLength(vector<vector<int>>& coordinates, int k) {\n auto go = [&](vector<pair<int, int>>& v) {\n sort(v.begin(), v.end());\n // for (const auto& p : v) cout << p.first << ',' << p.second << ' '; cout << endl;\n map<int, int> vy;\n for (const au...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
2
{ "code": "class Solution {\npublic:\n int lis(vector<int>& a) {\n vector<int> dp(a.size() + 1, INT_MAX);\n dp[0] = INT_MIN;\n \n for (int i = 0; i < a.size(); ++i) {\n int l = upper_bound(dp.begin(), dp.end(), a[i]) - dp.begin();\n if (a[i] > dp[l-1] && a[i] < dp[...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
2
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n\nclass Solution {\npublic:\n // Binary Indexed Tree (Fenwick Tree) for Range Maximum Query\n struct FenwickTree {\n int size;\n vector<int> tree;\n\n FenwickTree(int n) : size(n), tree(n + 2, 0) {}\n\n // Update the tree at ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
2
{ "code": "class Solution {\npublic:\n int lcs(vector<pair<int, int>> A) {\n sort(A.begin(), A.end(), [](auto &l, auto &r) {\n if (l.first!=r.first) return l.first<r.first;\n return l.second>r.second;\n });\n vector<int> lcs;\n for (auto v: A) {\n int x ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
2
{ "code": "typedef pair<int,int> ppi;\n\nclass Solution {\n\nprivate:\n\nbool static comp(ppi &p1, ppi &p2){\n \n if(p1.first == p2.first) return p1.second > p2.second;\n else return p1.first < p2.first;\n}\n\nint lis(vector<ppi> &v){\n\n sort(v.begin(), v.end(), comp);\n vector<int> temp;\n for(aut...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
2
{ "code": "class Solution {\npublic:\n static bool cmp(vector<int>& a, vector<int>& b){\n if (a[0]==b[0]) return a[1] > b[1];\n return a[0] < b[0];\n }\n\n int lis (vector<vector<int>>& arr){\n vector<int> temp;\n for (auto it : arr){\n int y = it[1];\n int l...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
2
{ "code": "class Solution {\npublic:\n static bool cmp(pair<int,int>a,pair<int,int>b){\n if(a.first==b.first){\n return a.second>b.second;\n }else{\n return a.first<b.first;\n }\n }\n int maxPathLength(vector<vector<int>>& arr, int k) {\n vector<pair<int, i...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
2
{ "code": "class Solution {\npublic:\n int lis(vector<int> &arr) {\n int n = arr.size();\n vector<int> dp;\n\n for(const auto &i : arr) {\n auto it = lower_bound(dp.begin(), dp.end(), i);\n if(it == dp.end()) dp.push_back(i);\n else *it = i;\n }\n ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
2
{ "code": "/**\n * https://leetcode.com/problems/length-of-the-longest-increasing-path/solutions/5787529/double-lis/\n */\n\nclass Solution {\npublic:\n static int maxPathLength(std::vector<std::vector<int>> coordinates, int k) {\n int x = coordinates[k][0];\n int y = coordinates[k][1];\n st...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
2
{ "code": "static bool comp(const std::vector<int>& a, const std::vector<int>& b) {\n \n if (a[0] == b[0])return a[1] > b[1]; \n return a[0] < b[0];\n }\nclass Solution {\npublic:\nint func(vector<vector<int>>arr)\n{\n\n int n=arr.size();\n\n sort(arr.begin(),arr.end(),comp);\n vector...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
2
{ "code": "\n\n\nclass Solution {\n \n \n int maxEnvelopes(vector<vector<int>> envelopes) {\n if(envelopes.size()==0)return 0;\n vector<int> res;\n res.push_back(envelopes[0][1]);\n \n for(int i=1;i<envelopes.size();++i){\n if(envelopes[i][1]>res[res.size()-1])\n ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
2
{ "code": "class Solution {\npublic:\n int maxEnvelopes(vector<vector<int> >& envelopes)\n{\n // Number of envelopes\n int N = envelopes.size();\n \n if (N == 0)\n return N;\n \n // Sort the envelopes in increasing\n // order of width and decreasing order\n // of height is width is same\n ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
2
{ "code": "class Solution {\npublic:\n int maxPathLength(vector<vector<int>>& coordinates, int k) \n {\n vector<pair<int, int>> points_before_target; points_before_target.reserve(coordinates.size());\n vector<pair<int, int>> points_after_target; points_after_target.reserve(coordinates.size());\n ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
2
{ "code": "class Solution {\npublic:\n int fen[100010];\n \n int query(int idx){\n int res = 0;\n for(;idx > 0;idx -= (-idx & idx)){\n res = max(res,fen[idx]);\n }\n return res;\n }\n \n void update(int idx,int val){\n for(;idx<100010;idx += (-idx & idx)...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
2
{ "code": "class Solution {\npublic:\n static bool comp(vector<int>& v1,vector<int>&v2){\n if(v1[0]<v2[0])return true;\n else if(v1[0] == v2[0])return v1[1]>v2[1];\n return false;\n }\n int solve(vector<vector<int>>&less){\n sort(less.begin(),less.end(),comp);\n vector<int>...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "\nclass Solution {\npublic:\n static bool cmp(vector<int> & x, vector<int> & y) {\n if( x[0] == y[0]) return x[1] > y[1]; // [2,4] , [2,5] , [3,5]\n return x[0] < y[0];\n }\n int lis_cal(vector<int> arr) { // main crux of this code calcualting lis in nlogn TC\n vector<int...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\npublic:\n static bool cmp(vector<int> & x, vector<int> & y) {\n if( x[0] == y[0]) return x[1] > y[1]; // [2,4] , [2,5] , [3,5]\n return x[0] < y[0];\n }\n int lis_cal(vector<int> arr) { // main crux of this code calcualting lis in nlogn TC\n vector<int> ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\npublic:\n int rec(vector<int>&v){\n int n=v.size();\n if(n<=1)\n return n;\n vector<int>LIS(n);\n vector<int>junk;\n junk.push_back(v[0]);\n LIS[0]=1;\n for(int i=1;i<n;i++){\n if(v[i]>junk.back()){\n jun...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& nums) {\n\n int n = nums.size();\n vector<int> ans;\n\n ans.push_back(nums[0]);\n\n for (int i = 1; i < n; i++) {\n if (nums[i] > ans.back()) {\n\n ans.push_back(nums[i]);\n } else {...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "template<class S>\nstruct fenwick {\npublic:\n\tfenwick() : n(0) {}\n\texplicit fenwick(int _n) : n(_n), data(_n) {}\n\n\tvoid add(int p, S x) {\n\t\tfor(int i = p + 1; i <= n; i += i & -i) {\n\t\t\tdata[i - 1] += x;\n\t\t}\n\t}\n\n\t// [0, p)\n\tS get(int p) const {\n\t\tauto ans = S();\n\t\tfor(int i = p...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "#define ll long long\nclass Solution {\npublic:\n static bool cmp(vector<ll>& v1, vector<ll>& v2){\n if(v1[0]==v2[0])return v1[1]>v2[1];\n return v1[0]<v2[0];\n }\n int maxPathLength(vector<vector<int>>& arra, int k) {\n int n=arra.size();\n vector<vector<ll>>store;\n ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\npublic:\n \n int lis(vector<int> const& a) {\n int n = a.size();\n const int INF = 1e9;\n vector<int> d(n+1, INF);\n d[0] = -INF;\n\n for (int i = 0; i < n; i++) {\n int l = lower_bound(d.begin(), d.end(), a[i...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "\n#include <ios>\n#include <set>\nusing namespace std;\n\ntypedef pair< int, int > pii;\n\nconst int MAX = 100001;\n\nclass abc{\n public:\n set< pii > S[MAX];\n\n bool comp(set< pii > &s, pii &p) {\n set< pii >::iterator it;\n for(it=s.begin(); it!=s.end(); it++) {\n if(it-...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\npublic:\n struct SegTreeChangeOne {\n long long myGcd(long long a, long long b) {\n if (a==-1) return b;\n if (b==-1) return a;\n return std::gcd(a,b);\n }\n\n SegTreeChangeOne(int sz, string function) {\n localSz = sz;\n t.resize(4 * sz + 5)...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\npublic:\n void insert(vector<int>&tree,int idx,int s,int e,int ind,int val){\n if(s>e)return;\n if(s==e){\n tree[idx]=val;\n return;\n }\n int mid=s+(e-s)/2;\n if(ind<=mid)insert(tree,2*idx,s,mid,ind,val);\n else insert(tr...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\npublic:\n static bool comp(vector<int> &a,vector<int> &b){\n if(a[0]!=b[0])\n return a[0]<b[0];\n return a[1]>b[1];\n }\n int maxPathLength(vector<vector<int>>& cord, int k) {\n vector<vector<int>> small;\n vector<int> t = cord[k];\n ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "// Structure to represent each point with additional metadata\nstruct Point {\n int x;\n int y;\n int index;\n int y_compressed;\n};\n\n// Segment Tree for Range Maximum Query and Point Updates\nclass SegTree {\npublic:\n int size;\n vector<int> tree;\n\n SegTree(int n){\n size ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "#include <ranges>\nclass Solution {\npublic:\n int maxPathLength(vector<vector<int>>& coordinates, int k) {\n int n = coordinates.size();\n vector<int> index(n, 0);\n iota(index.begin(), index.end(), 0);\n ranges::sort(index, [&coordinates] (const int a, const int b) {\n ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\npublic:\nint lengthOfLIS(vector<vector<int>>& num)\n{\n vector<int> nums;\n for(auto i:num)nums.push_back(i[1]);\n int n = nums.size();\n vector<int> ans;\n if (n == 0) return 0; // If nums is empty, return 0 immediately\n\n ans.push_back(nums[0]);\n\n for (int i ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\npublic:\n int maxPathLength(vector<vector<int>>& coordinates, int k) {\n int n = coordinates.size();\n vector<int> ys(n);\n for (int i = 0; i < n; ++i) {\n ys[i] = coordinates[i][1];\n }\n\n // Coordinate compression for y\n vector<i...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\npublic:\n int maxPathLength(vector<vector<int>>& coordinates, int k) {\n int x = coordinates[k][0], y = coordinates[k][1], l = 0;\n map<int, vector<int>> mp;\n for (auto& c : coordinates) { mp[c[0]].push_back(c[1]); }\n vector<pair<int, int>> q;\n for...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "#define ll long long\n#define REP(i,n) FOR(i,0,n)\n#define SORT(v) sort((v).begin(),(v).end())\n#define FOR(i,a,b) for(ll i=(a);i<(b);i++)\n\nclass Solution {\npublic:\n int calc(vector<int>& v) {\n // for (auto x : v) cout << x << \" \"; cout << endl;\n vector<int> lis...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class SegTree{\n\tpublic:\n #define ll long long\n\ttypedef ll Val;\n\tstruct node{\n\t\tll sum; Val mn, mx;\n\t\tint mncnt, mxcnt;\n\t\tvoid apply(Val a, int len=1){ sum=1ll*a*len; mn=mx=a; mncnt=mxcnt=len; }\n\t};\n\tint n;\n\tvector<node> tree;\n\tvector<pair<bool,Val>> upd;\n\tvector<Val> add;\n\tve...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\n int LIS(vector<int> &nums)\n {\n int n = nums.size();\n set<int> st;\n for(int ni: nums)\n {\n auto it = st.lower_bound(ni);\n if(it == st.end())\n st.insert(ni);\n else\n {\n st.e...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\npublic:\n int maxPathLength(vector<vector<int>>& coordinates, int k) {\n int xrec = coordinates[k][0];\n int yrec = coordinates[k][1];\n\n int n = coordinates.size();\n sort(coordinates.begin(), coordinates.end());\n\n vector<vector<int>> a;\n ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "#define lli long long\nclass Solution {\npublic:\n lli update(lli ind, lli value, lli i, lli l, lli r, vector<lli> &seg)\n{\n // cout << l << \" \" << r << endl;\n lli mid = (l + r) / 2;\n if (l == ind && r == ind)\n {\n return seg[i] = value;\n }\n if (l > ind || r < ind)\n ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\nprivate:\n int lis(vector<vector<int>> A) {\n vector<int> dp;\n for (auto it : A) {\n int y = it[1];\n auto it2 = lower_bound(dp.begin(), dp.end(), y);\n if (it2 == dp.end()) {\n dp.push_back(y);\n } else {\n ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\npublic:\n int maxPathLength(vector<vector<int>>& coordinates, int k) {\n vector<int> pivot = coordinates[k];\n unordered_map<int, set<int>> points;\n set<int> keys;\n for (vector<int> & point : coordinates){\n if (point[0] == pivot[0] || point[1] ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\npublic:\n struct st {\n vector<int> mx;\n\n st(int n) {\n mx.resize(4 * n + 2);\n }\n\n void upd(int idx, int val, int v, int tl, int tr) {\n if (tl == tr) {\n mx[v] = val;\n return;\n }\n ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\npublic:\n#define ll int\n struct segtree{\n ll n;\n vector<ll>sg;\n ll query(ll l,ll r,ll start,ll end,ll node){\n // no overlap with given node range\n if(l>end || r<start) return 0;\n\n // if complete overlap\n if(start>=l && end<=r){\n ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "template <typename Monoid>\nstruct SegTree {\nprivate:\n using T = typename Monoid::value_type;\n size_t n;\n std::vector<T> V;\n\n void _set(int i, T v, int vl, int vr, int pos) {\n if (vl + 1 == vr) { V[pos] = v; return; }\n int mid = vl + (vr - vl) / 2;\n if (i < mid) _s...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\npublic:\n static bool compare1(vector<vector<int>>& a, vector<vector<int>>& b){\n if(a[1][0] == b[1][0]) return a[1][1]>b[1][1];\n return a[1][0]<b[1][0];\n }\n int LIS1(int ind, vector<vector<vector<int>>>& vec){\n vector<int> v;\n if(ind == 0) return...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "#define ff first\n#define ss second\n#define MP make_pair\nclass FW { \n public: \n int n; \n vector<vector<pair<int, int>>> root; \n FW(int n) { \n this->n = n; \n root.resize(n + 1, vector<pair<int, int>>(2, {-1, -1}));\n }\n\n void update(int id, int x, int val) { ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "struct segment {\n segment(int n) { tree.resize(4 * n); };\n \n void set(int i, int a) {\n set(i, a, 1, 0, tree.size() / 4 - 1);\n }\n\n int get(int start, int end) {\n return get(start, end, 1, 0, tree.size() / 4 - 1);\n } \n \nprivate:\n vector<int> tree;\n \n ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\npublic:\n tuple<int, int, int> a[100005];\n set<int> st;\n map<int, int> pos;\n int segtree[4 * 100005];\n \n int rmq(int l, int r, int lq, int rq, int node) {\n if (l > rq || r < lq || lq > rq) {\n return 0;\n }\n if (lq <= l && rq >= r) ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\n struct SG\n {\n int n;\n\n SG(int n_)\n {\n n = n_;\n t.resize(4 * n, 0);\n }\n\n int get(int l, int r)\n {\n auto ret = get(1, 0, n - 1, l, r);\n return ret;\n }\n\n void set(int i,...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\npublic:\n int lis(map<int, vector<int>>& nums) {\n vector<int> res;\n for(auto i:nums) {\n vector<int> &v = i.second;\n int idx=(int)v.size();\n for (int j=0; j<(int)v.size(); j++){\n auto it = std::lower_bound(res.begin(), ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\npublic:\nstatic bool cmp(vector<int>&a,vector<int>&b){\n if(a[0]!=b[0]){\n return a[0]<b[0];\n }else{\n return a[1]<b[1];\n }\n}\n\nint solve1(int i,int j, map<int,vector<int>> &m,vector<int>&v,int y){\n if(j<i)return 0;\n vector<int> a;\n vector<int> z;\n ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class SegmentTree{\n\n\nprivate:\n\n\tvector<int> tree;\n\tint N;\n\n\tvoid buildTree(int l,int r,int i,vector<int>& arr){\n\t\tif (l==r){\n\t\t\ttree[i]=arr[l];\n\t\t\treturn;\n\t\t}\n\t\tint mid = (l+r)/2;\n\t\tbuildTree(l,mid,2*i+1,arr);\n\t\tbuildTree(mid+1,r,2*i+2,arr);\n\t\ttree[i] = max(tree[2*i+1],...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\npublic:\n struct BIT {\n int N;\n vector<int> tree;\n BIT(int n) : N(n), tree(n + 2, 0) {}\n void update(int idx, int val) {\n while (idx <= N) {\n tree[idx] = max(tree[idx], val);\n idx += idx & -idx;\n }\...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "#define ll int\nconst ll INM=0;\ntemplate<typename T>\nclass Segtree{\n public:\n vector<T>seg;\n ll n;\n T comp(T a,T b){\n return max(a,b);\n }\n Segtree(ll n,vector<ll>&a){\n this->n=n;\n seg.resize(4*n+5);\n build(a,0,n-1,0);\n }\n void build(vector<ll>& ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n\nclass Solution {\npublic:\n struct BIT {\n int size;\n vector<int> tree;\n\n BIT(int n) : size(n), tree(n + 1, 0) {}\n\n // Update the BIT with the maximum value at index\n void update(int index, int value) {\n ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class BinaryIndexedTree {\nprivate:\n vector<int> bit;\n int size;\n\npublic:\n BinaryIndexedTree(int n) : size(n + 1), bit(n + 1, 0) {}\n\n void update(int index, int val) {\n index++;\n while (index < size) {\n bit[index] = max(bit[index], val);\n index += ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\npublic:\n typedef long long ll;\n int maxPathLength(vector<vector<int>> &a, int k)\n {\n ll X = a[k][0], Y = a[k][1];\n\n set<ll> s;\n for(auto i : a)\n s.insert(i[1]);\n unordered_map<ll, ll> c;\n for(auto j : s)\n c[j] = ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "#include <vector>\n#include <algorithm>\n#include <unordered_map>\n\nusing namespace std;\n\nclass SegmentTree {\npublic:\n int size;\n vector<int> tree;\n \n SegmentTree(int n) {\n size = 1;\n while(size < n) size <<= 1;\n tree.resize(size * 2, 0);\n }\n \n void u...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "#include <iostream>\n#include <vector>\n#include <algorithm>\n#include <map>\n#include <tuple>\n\nusing namespace std;\n\nclass Solution {\npublic:\n int maxPathLength(vector<vector<int>>& coordinates, int k) {\n int n = coordinates.size();\n vector<int> ys;\n vector<tuple<int, int,...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "#include <iostream>\n#include <vector>\n#include <algorithm>\n#include <map>\n#include <tuple>\n\nusing namespace std;\n\nclass Solution {\npublic:\n int maxPathLength(vector<vector<int>>& coordinates, int k) {\n int n = coordinates.size();\n vector<int> ys;\n vector<tuple<int, int,...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\npublic:\n int getR(vector<vector<int>> c){\n sort(c.begin(),c.end());\n map<int,vector<int>> mm;\n for(auto v:c){\n mm[v[0]].push_back(v[1]);\n }\n\n vector<int> pos;\n for(auto [x,v]:mm){\n vector<pair<int,int>> up;\n ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\npublic:\n static bool cmp(pair<int,int> &p1, pair<int,int> &p2){\n if(p1.first == p2.first) return p1.second > p2.second;\n return p1.first < p2.first;\n }\n \n int maxPathLength(vector<vector<int>>& coordinates, int k) {\n int n = coordinates.size();\n ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\n int calc(vector<vector<int>> &v) {\n \n if(v.empty()) return 0;\n set<int> s;\n sort(v[0].begin(),v[0].end());\n s.insert(v[0][0]);\n int i;\n for(i = 1;i<v.size();i++) {\n sort(v[i].begin(),v[i].end(),greater<int>());\n ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "#define lli long long\nclass Solution {\npublic:\n lli update(lli ind, lli value, lli i, lli l, lli r, vector<lli> &seg)\n{\n // cout << l << \" \" << r << endl;\n lli mid = (l + r) / 2;\n if (l == ind && r == ind)\n {\n return seg[i] = value;\n }\n if (l > ind || r < ind)\n ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\npublic:\n int maxPathLength(std::vector<std::vector<int>>& coordinates, int k) {\n int n = coordinates.size();\n\n std::vector<int> y_coords(n);\n for (int i = 0; i < n; ++i) {\n y_coords[i] = coordinates[i][1];\n }\n\n std::vector<int> sor...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\npublic:\n int maxPathLength(vector<vector<int>>& coordinates, int k) {\n int n = coordinates.size();\n\n vector<int> y_coords(n);\n for (int i = 0; i < n; ++i) {\n y_coords[i] = coordinates[i][1];\n }\n\n vector<int> sorted_y = y_coords;\n ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "bool cmp(vector<int> &a, vector<int> &b){\n if(a[0] == b[0]) return a[1] > b[1];\n return a[0] < b[0];\n}\n\nclass Solution {\npublic:\n int seg[4*200005];\n void build(int ind,int low,int high){\n if(low==high){\n seg[ind] = 0;\n return ;\n }\n int mi...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "\nconst int N = 1e5 + 5;\nint seg[4 * N];\nint l, r, n, pos;\nint val;\nstruct segmentTree\n{\n#define LEFT 2*p,s,(s+e)/2\n#define RIGHT 2*p+1,(s+e)/2+1,e\n#define MID (s+e)/2\n#define IN l <= s && e <= r\n#define OUT r < s || e < l\n\n\tint get(int p = 1, int s = 0, int e = n)\n\t{\n\t\n\t\tif (OUT)return...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "template<class I>\nvoid compress(I l, I r) {\n vector<int> v(l, r);\n sort(begin(v), end(v));\n v.erase(unique(begin(v), end(v)), end(v));\n map<int, int> inv;\n for (int i = 0; i < v.size(); ++i) {\n inv[v[i]] = i;\n }\n while (l != r) *(l++) = inv[*l];\n}\n\ntemplate<class T>\...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "void compress(int* l, int* r) {\n vector<int> v(l, r);\n sort(begin(v), end(v));\n v.erase(unique(begin(v), end(v)), end(v));\n map<int, int> inv;\n for (int i = 0; i < v.size(); ++i) {\n inv[v[i]] = i;\n }\n while (l != r) *(l++) = inv[*l];\n}\n\ntemplate<class T>\nstruct Tree ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\npublic:\n int maxPathLength(vector<vector<int>>& c, int k) {\n int n = c.size();\n vector<int> y;\n for (auto& p : c) y.push_back(p[1]);\n sort(y.begin(), y.end());\n y.erase(unique(y.begin(), y.end()), y.end());\n unordered_map<int, int> ym;\n...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\npublic:\n int maxPathLength(vector<vector<int>>& coordinates, int target) {\n int n = coordinates.size();\n vector<int> yValues;\n for (auto& coord : coordinates) yValues.push_back(coord[1]);\n sort(yValues.begin(), yValues.end());\n yValues.erase(uni...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\npublic:\n class segmentTree{\nvector<int>seg,a;\nint len;\npublic:\nsegmentTree(int n){\n seg.resize(4*n,0);\n len=4*n;\n}\nint getmax(int index,int low,int high,int l,int r){\n if(low>=l && high<=r){\n return seg[index];\n }\n if(high<l || low>r){return 0;}\n int mid=(low+high)/...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\npublic:\n class segmentTree{\nvector<int>seg,a;\nint len;\npublic:\nsegmentTree(int n){\n seg.resize(4*n,0);\n len=4*n;\n}\nint getmax(int index,int low,int high,int l,int r){\n if(low>=l && high<=r){\n return seg[index];\n }\n if(high<l || low>r){return 0;}\n int mid=(low+high)/...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "#include<iostream>\n#include<iomanip>\n#include<algorithm>\n#include<vector>\n#include<utility>\n#include<set>\n#include<unordered_set>\n#include<list>\n#include<iterator>\n#include<deque>\n#include<queue>\n#include<stack>\n#include<set>\n#include<bitset>\n#include<random>\n#include<map>\n#include<unordere...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "#include <iostream>\n#include <vector>\n#include <algorithm>\n#include <map>\n\nusing namespace std;\n\n// Fenwick Tree for range maximum query\nclass FenwickTree {\npublic:\n FenwickTree(int size) : tree(size + 2, 0) {}\n\n // Update the value at index idx to be max of current value and val\n voi...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "#include <vector>\n#include <set>\n#include <map>\n#include <algorithm>\n#include <cmath>\n\nusing namespace std;\n\nclass SqrtDecomposition {\npublic:\n vector<int> arr;\n vector<int> block;\n int len;\n\n SqrtDecomposition(int n) {\n len = sqrt(n) + 1;\n arr.resize(n, 0);\n ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "class Solution {\npublic:\nint func(vector<vector<int>>coor,int x,int y)\n{\n\n int n=coor.size();\n\n vector<int>dp(n,0);\n sort(coor.begin(),coor.end());\n\n set<pair<int,int>>st;\n vector<pair<int,int>>temp;\n\n\n \n\n\n\n for(int i=n-1;i>=0;i--)\n {\n\n...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n\n// Source: https://github.com/atcoder/ac-library\n\n// @param n `0 <= n`\n// @return minimum non-negative `x` s.t. `n <= 2**x`\nint ceil_pow2(int n) {\n int x = 0;\n while ((1U << x) < (unsigned int)(n)) x++;\n return x;\n}\n\ntemplate <class S, S ...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "\n\nclass Solution {\npublic:\n int t[400009];\n void build(int v, int tl, int tr, int val) {\n if (tl == tr) {\n t[v] = val;\n } else {\n int tm = (tl + tr) / 2;\n build(v*2, tl, tm, val);\n build(v*2+1, tm+1, tr, val);\n t[v] = ma...
3,571
<p>You are given a 2D array of integers <code>coordinates</code> of length <code>n</code> and an integer <code>k</code>, where <code>0 &lt;= k &lt; n</code>.</p> <p><code>coordinates[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> indicates the point <code>(x<sub>i</sub>, y<sub>i</sub>)</code> in a 2D plane.</p> <p>An <st...
3
{ "code": "struct Node {\n int max;\n\n Node() { max = 0; }\n};\n\nclass SegmentTree {\npublic:\n vector<Node> segTree;\n\n SegmentTree(int n) { segTree.resize(4 * n + 1); }\n\n void update(int ind, int low, int high, int i, int val) {\n if (low == high) {\n segTree[ind].max = val;\n ...