id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "template <typename T>\nstruct segTree // 1-based indexing.\n{\n int size, n;\n vector<T> st, lazy;\n int NO_OPERATION=LLONG_MAX-1;\n segTree(int sizeOfTree)\n {\n n = sizeOfTree;\n size = 1;\n while (size < sizeOfTree)\n size <<= 1;\n\n size <<= 1;\n ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> tree, lazy;\n\n void build(vector<int>& arr, int start, int end, int node){\n if (start == end){\n tree[node] = arr[start];\n return;\n }\n int mid = start + (end - start) / 2;\n build(arr, start, mid, node * 2 ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\n struct segtree {\n int n;\n vector <int> a;\n segtree (int m) {\n n = m;\n a.assign(4 * n, -1);\n }\n void update (int i, int v, int x, int lx, int rx) {\n if (rx - lx == 1) {\n a[x] = v;\n ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n int n;\n void calc(auto& m, auto& ans, int l, int r, int pt) {\n if(l > r) return;\n if(m[l].size()==0) return calc(m,ans,l+1,r,pt);\n if(m[l].back().first > r) return;\n auto rb = m[l].back(); \n m[l].pop_back();\n if(rb.second > ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "struct segmenttree {\n\tint n;\n\tvector<int> st, lazy;\n\n\tvoid init(int _n) {\n\t\tthis->n = _n;\n\t\tst.resize(4 * n, 0);\n\t\tlazy.resize(4 * n, -1);\n\t}\n\n\tvoid build(int start, int ending, int node, vector<int> &v) {\n\t\tif (start == ending) {\n\t\t\tst[node] = v[start];\n\t\t\treturn;\n\t\t}\n\... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "namespace atcoder\n{\n \ntemplate <class S, S (*op)(S, S), S (*e)(), class F, S (*mapping)(F, S), F (*composition)(F, F), F (*id)()>\nstruct lazy_segtree {\n int ceil_pow2(int n)\n {\n int x = 0;\n while ((1U << x) < (unsigned int) (n))\n x++;\n return x;\n }\n \n ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class SegmentTree {\nprivate:\n vector<int> tree; // Segment tree\n vector<int> lazy; // Lazy propagation array\n vector<bool> lazySet; // Lazy set propagation array\n int size; // Size of the input array\n\n // Recursively build the segment tree\n void build(const vector<int>&... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\n vector<int> dist;\n unordered_set<int> rem;\n int bfs(vector<int> &G, int s, int e){\n int cnt=0;\n int n = G.size()-1;\n for(int j=s;j!=e;){\n j=G[j];\n cnt+=1;\n if(j!=e){\n rem.insert(j);\n }\n ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& q) {\n // Initialize the necessary variables\n int temp = n - 1;\n int maxi = q[0][1];\n int mini = q[0][0];\n temp -= (maxi - mini - 1);\n \n // Initialize t... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n vector<int>ans;\n\n unordered_map<int,int>ma;\n vector<int>reachingTo(n+1,-1);\n\n int shortestDis = n-1;\n\n int firstQS = queries[0][0];\n int firstQD... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n vector<int>ans;\n\n unordered_map<int,int>ma;\n vector<int>reachingTo(n+1,-1);\n\n int shortestDis = n-1;\n\n int firstQS = queries[0][0];\n int firstQD... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n \n map<int,int>mp;\n int m = queries.size();\n int mini = queries[0][0];\n int maxi = queries[0][1];\n vector<int>v(n,-1);\n v[mini] = maxi;\n ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n \n int temp=n-1;\n int mini=queries[0][0];\n int maxi=queries[0][1];\n temp-=(maxi-mini-1);\n vector<int>v(n,-1);\n map<int,int>mp;\n v[mi... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& q) {\n vector<int> ans;\n vector<int> v(n, -1);\n v[q[0][0]] = q[0][1];\n int temp = n - (q[0][1]-q[0][0]);\n ans.push_back(temp);\n map<int,bool> mp;\n for(i... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& q) {\n set<int> mis;\n vector<int> ans;\n int temp=n-1;\n vector<int> v(n+1, n);\n for(int i=0 ; i<n-1 ; i++) v[i]=i+1;\n // for(int i=0 ; i<n-1 ; i++) cout<<v[i]<... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "#define vi vector<int>\n#define vvi vector<vi>\n\nclass Solution {\n\n\n void updateTree (vi& sTree, vi& lazy, int idx, int start, int end, int qs, int qe, int num) {\n if (lazy[idx] != 0) {\n if (start != end) {\n lazy[2*idx+1] = lazy[2*idx+1] + lazy[idx];\n ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n vector<int> sTree(4*n+5, 0), lazy(4*n+5, 0);\n vector<int> ans;\n\n \n set<pair<int,int>> overlap;\n for (auto& query : queries) {\n pair<int,int> c... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class SGTree {\npublic:\n int n;\n vector<int> seg, lazy;\n\n SGTree(vector<int>& a) {\n n = (int) a.size();\n seg.resize(4 * n + 1);\n lazy.resize(4 * n + 1, -1);\n Build(a);\n }\n\n int merge(int left, int right) {\n return (left + right);\n }\n\n v... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class ST {\n\tvector<int> seg, lazy; \npublic: \n\tST(int n) {\n\t\tseg.resize(4 * n+1); \n\t\tlazy.resize(4 * n+1); \n\t}\npublic: \n\tvoid build(int ind, int low, int high, vector<int> &arr) {\n\t\tif(low == high) {\n\t\t\tseg[ind] = arr[low];\n\t\t\treturn; \n\t\t}\n\t\tint mid = (low + high) >> 1; \n\t... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n unordered_map<int,int>mp;\n // int ans=0;\n int temp= n - 1;\n vector<int>path(n+1,-1),ans;\n\n for(auto q:queries){\n int u = q[0];\n in... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n unordered_map<int, int> notReqNodes;\n vector<int> nodesPath(n, -1);\n int shortestDist = n - 1;\n vector<int> shortestDistance;\n\n for(auto query : queries){... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "template<typename S, typename T>\nstruct segtree {\n public:\n segtree(vector<S> a) {\n n = a.size();\n size = 4 * n + 10;\n t = vector<S> (size);\n lazy = vector<T> (size);\n build(a, 0, n - 1, 1);\n }\n \n void build(vector<S>& a, int l, int r, int v) {\n if (l == ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "\n// COPY ALL MACROS BELOW\n\ntypedef long long LL;\n#define MP make_pair\n#define PB push_back\n#define F first\n#define S second\n#define LB lower_bound\n#define UB upper_bound\n#define SZ(x) ((int)x.size())\n#define LEN(x) ((int)x.length())\n#define ALL(x) begin(x), end(x)\n#define RSZ resize\n#define A... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n vector<int>ans;\n int tmp = n-1;\n map<int, int>mp;\n vector<int>dist(n, -1);\n for(auto it : queries){\n int x = it[0], y = it[1];\n if(... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n vector<int> ans;\n\n\n map<int, int> mp; //marking useless nodes\n vector<int> v(n, -1); //which max node can be reached from a given index\n\n int dist = n-1;\n\n ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n vector<pair<int, int>> adj(n + 1); // dest, src\n unordered_set<int> visited;\n for (int i = 0; i < n; i++) {\n adj[i].first = i + 1;\n adj[i + 1].seco... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Node{\n public:\n int value;\n Node* next;\n};\nclass Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n vector<Node*> arr(n+1, new Node());\n Node* nxt = nullptr;\n Node* curr = nullptr;\n for(int i=... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n \n vector<int> v(n-1);\n for(int i=0; i<n-1; i++) v[i] = i+1;\n\n int currD = n-1;\n\n unordered_map<int, bool> meaningless;\n\n vector<int> ans;\n\n ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "/*This is a boiler plate template created by Hardik Aswal*/\n\n/* Including all the libraries*/\n#include<iostream>\n#include<vector>\n#include<string>\n#include<queue>\n#include<unordered_map>\n#include<set>\n#include<cmath>\n#include<algorithm>\n#include<climits>\n#include<deque>\n#include<unordered_set>... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "#include <bits/stdc++.h>\n#define nfs cin.tie(NULL)->sync_with_stdio(false)\nusing namespace std;\nusing ll=long long;\nusing u32=unsigned int;\nusing u64=unsigned long long;\ntemplate <class T>\nusing pi=pair<T,T>;\n#define INT(...) int __VA_ARGS__; IN(__VA_ARGS__)\n#define LL(...) ll __VA_ARGS__; IN(__VA... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "#include <bits/stdc++.h>\n#define nfs cin.tie(NULL)->sync_with_stdio(false)\nusing namespace std;\nusing ll=long long;\nusing u32=unsigned int;\nusing u64=unsigned long long;\ntemplate <class T>\nusing pi=pair<T,T>;\n#define INT(...) int __VA_ARGS__; IN(__VA_ARGS__)\n#define LL(...) ll __VA_ARGS__; IN(__VA... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class SegmentTree {\nprivate:\n int n;\n vector<long long> tree, lazy;\n vector<bool> lazySet;\n\n void build(int node, int start, int end) {\n if (start == end) {\n tree[node] = 0; // Initial value for leaf nodes (adjust if needed)\n } else {\n int mid = (s... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n vector<Node*> list(n, nullptr);\n for (int i = 0; i < n; i++) {\n list[i] = new Node;\n list[i]->val = i;\n if (i > 0) {\n list[i]->... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "/**\n * Time Complexity: O(n + n_queries)\n * Space Complexity: O(n)\n * where `n_queries` is the length of the vector `queries`\n */\nclass Solution {\n public:\n vector<int> shortestDistanceAfterQueries(const int n, const vector<vector<int>> &queries) {\n list<int> adjacent_cities;\n list<int>::it... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n vector<int> g1,g2;\n map<int,int> m1,m2;\n int ans=n-1;\n vector<int> ans1;\n for(auto it:queries){\n \n if(m2[it[0]]==1){\n ans1.p... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n int q = queries.size();\n vector<int> res(q);\n\n vector<int> adj[n];\n for(int i = 0 ; i < n-1 ; i++){\n adj[i].push_back(i+1);\n }\n\n int ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n int q = queries.size();\n vector<int> res(q);\n\n vector<int> adj[n];\n for(int i = 0 ; i < n-1 ; i++){\n adj[i].push_back(i+1);\n }\n\n int ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n int q = queries.size();\n vector<int> res(q);\n\n vector<int> adj[n];\n for(int i = 0 ; i < n-1 ; i++){\n adj[i].push_back(i+1);\n }\n\n int ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> g[100001];\n vector<int> shortestDistanceAfterQueries(int n,\n vector<vector<int>>& queries) {\n for (int i = 0; i < n - 1; ++i) {\n g[i + 1].push_back(i);\n }\n int mx = n - 1;\n ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "///////////////////////////////////////////////////\n\nusing grid_t = vector<vector<int>>;\nusing edge_t = vector<vector<int>>;\n\nusing ull = unsigned long long int;\nusing lint = long long int;\n\nnamespace my {\ntemplate <class T>\nclass SegTree {\n public:\n using get_value_t = function<T(T, T)>;\... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\nstruct ListNode{\n int val;\n ListNode* next;\n ListNode(int v): val(v), next(nullptr){}\n};\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n ListNode* preHead = new ListNode(-1);\n ListNode* pre = preHead;\n vec... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Node { \npublic: \n int data; \n Node* next; \n \n // Default constructor \n Node() \n { \n data = 0; \n next = NULL; \n } \n\n // Parameterised Constructor \n Node(int data) \n { \n this->data = data; \n this->next = NULL; \n } \n}; \nclass ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n #define pii pair<int,int>\n class segtree{\n public:\n vector<pii>tree;\n segtree(int n){\n tree.assign(4*n,{-1,-1});\n }\n void upd(int tidx,int tl,int tr,int idx,int val){\n if(tl==tr){\n tree[tidx]=... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class SegmentTree {\nprivate:\n int n;\n vector<long long> tree, lazy;\n vector<bool> lazySet;\n\n void build(int node, int start, int end) {\n if (start == end) {\n tree[node] = 0; // Initial value for leaf nodes (adjust if needed)\n } else {\n int mid = (s... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n // lets try to change the range value to 0 -> for that\n // lets try lazy propagation;\n#define ll long long\nclass SegmentTree {\npublic:\n vector<ll> sgt;\n vector<ll> lazy;\n\n SegmentTree(ll n) {\n sgt.resize(4 * n, 0);\n lazy.resize(4 * n, -1); ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "typedef long long ll;\nclass SegmentTree\n{\n private:\n int n;\n vector<ll> tree, lazy;\n ll MOD;\n\n void clean(int lo, int hi, int cur)\n {\n if (lo == hi)\n {\n tree[cur] = max(tree[cur], min(lazy[cur], 1LL));\n }\n ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n unordered_map<int,int>has;\n for (int i=0;i<n-1;i++){\n has[i]=i;\n }\n vector<int> res;\n for (const auto& query : queries) {\n int a = ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n void eraseNode(int node,int final,vector<vector<int>>&g,int &cnt){\n int to = g[node][0];\n if(to!=final)eraseNode(to, final,g,cnt);\n g[node].pop_back();\n cnt++;\n }\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& que... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries (int N, vector<vector<int>> &Q) {\n int M = size(Q); vector<int> R(M);\n vector<int> A(N); for (int i = 0; i < N - 1; i++) A[i] = i + 1;\n\n unordered_set<int> B;\n for (int i = 0; i < N; i++) B.insert(i);\n... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\n public:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n unordered_map<int, int> mp;\n for (int i = 0; i < n - 1; ++i) {\n mp[i] = i + 1;\n }\n v... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n// Custom comparator\nstruct CustomCompare {\n bool operator()(const std::vector<int>& a, const std::vector<int>& b) const {\n // Compare first elements in ascending order\n if (a[0] != b[0])\n return a[0] < b[0];\n // Compare second elements in... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n// Custom comparator\nstruct CustomCompare {\n bool operator()(const std::vector<int>& a, const std::vector<int>& b) const {\n // Compare first elements in ascending order\n if (a[0] != b[0])\n return a[0] < b[0];\n // Compare second elements in... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n unordered_map<int, int> graph;\n\n for(int i = 0; i < n-1; i++){\n graph[i] = i+1;\n }\n\n vector<int> res;\n for(auto& query: queries){\n ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "class Node{\n public:\n int val;\n Node *next;\n Node(int val){\n this->val=val;\n next=NULL;\n }\n};\n\nclass Solution {\npublic:\n // vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n // vector<int> ans;\n // unordered_map<int,... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n#pragma GCC optimize(\"O3\")\n#pragma GCC optimize(\"Ofast\", \"inline\", \"unroll-loops\", \"no-stack-protector\")\n#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native\", \"f16c\")\n#define ll long long\n#define bigInt __int128_... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 0 | {
"code": "int speedup = []{ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); return 0;}();\n\nclass Solution {\n void eraseMiddle(set<int> &s, int l, int r){\n auto start = s.lower_bound(l);\n auto end = s.upper_bound(r);\n s.erase(start, end);\n }\npublic:\n vector<int> shortestDis... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 2 | {
"code": "#define all(a) a.begin(),a.end()\ntypedef long long int ll;\n\ntemplate<typename Node, typename Update>\nstruct LazySGT {\n vector<Node> tree;\n vector<bool> lazy;\n vector<Update> updates;\n vector<ll> arr; // type may change\n int n;\n int s;\n LazySGT(int a_len, vector<ll> &a) { // ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 2 | {
"code": "#include <vector>\n#include <set>\n\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n multiset<int> positions;\n for (int i = 0; i < n; ++i) {\n positions.insert(i);\n }\n deque<in... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 2 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& q) {\n vector<vector<int>> g(n);\n for (int i = 0; i < n - 1; ++i) {\n g[i].push_back(i+1);\n }\n \n int ans = n-1;\n vector<int> d(n, 0);\n auto u... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 2 | {
"code": "class Solution {\n private : \n const int MAXN = 100000+1;\n int seg[4*100000];\n int lazy[4*100000];\n \n void build(int si, int ss, int se, int a[]){\n lazy[si]=0;\n if(ss == se){\n seg[si]=a[ss];\n return;\n }\n int mid = (ss+se)/2;\n ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 2 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& q) {\n vector<int> dist(n, 0);\n for (int i = 1; i < n; ++i) {\n dist[i] = dist[i - 1] + 1;\n }\n\n set<int> pos;\n for (int i = 0; i < n; ++i) {\n po... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 2 | {
"code": "#define ASSERT(x)\n\n// y-comb\ntemplate <class Func> class YCombResult {\npublic:\n explicit YCombResult(Func&& func) : func_(std::forward<Func>(func)) {}\n\n template <class... Args> decltype(auto) operator()(Args&&... args) {\n return func_(std::ref(*this), std::forward<Args>(args)...);\n ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 2 | {
"code": "class Solution {\npublic:\nvoid getCheck(unordered_map<int,bool>&m1,int index1,int index2,vector<int>&arr){\n if(index1>=arr.size()){\n return;\n }\n arr.erase(arr.begin()+index1,arr.begin()+index2);\n}\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 2 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n unordered_map<int, int> m;\n for(int i =0; i< n-1; i++){\n m[i] = i+1;\n }\n\n vector<int> res;\n for(auto q : queries){\n int x = q[0], ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 2 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n unordered_map<int,int> mp;\n for(int i=0;i<n-1;i++){\n mp[i]=i+1;\n }\n vector<int> res;\n for(auto q: queries){\n int l=q[0],r=q[1];\n ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 2 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& q) {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n vector<int>ans;\n set<int>s;\n for(int i=0;i<n;++i)s.insert(i);\n for(auto i:q){\n auto l=s.lowe... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 2 | {
"code": "class Solution {\n void solve(set <int> &st,int a,int b){\n auto l=st.lower_bound(a);\n auto r=st.upper_bound(b);\n st.erase(l,r);\n }\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n ios::sync_with_stdio(0); cout.tie(0); cin.... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 3 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n vector<int> ans;\n set<int> s;\n for(int i=0;i<n;i++) {\n s.insert(i);\n }\n int x,y;\n set<int>::iterator it, it2;\n stack<int> tmp;\... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 3 | {
"code": "\n#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\nusing namespace __gnu_pbds;\nnamespace chh{\n template<typename T>\n class _multiset : public tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>{\n public:\n auto operator[](int ind){\... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 3 | {
"code": "#include <iostream>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\n/****************** Aliases **********************/ \nusing ll= long long;\nusing lld= long double;\nusing ull= unsigned long long;\n\n/****************** Constants **********************/\nconst lld pi= 3.141592653589793238;\nconst l... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 3 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n vector<int> ans,vis[n];\n set<int> st;\n for(int i=0;i<n;i++)st.insert(i);\n int count=0,mini=0;\n for(auto it:queries)\n {\n auto l=st.lower... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 3 | {
"code": "class Solution {\npublic:\n\n int t[4*100005];\n void build(int a[], int v, int tl, int tr) {\n if (tl == tr) {\n t[v] = a[tl];\n } else {\n int tm = (tl + tr) / 2;\n build(a, v*2, tl, tm);\n build(a, v*2+1, tm+1, tr);\n t[v] = t[v... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 3 | {
"code": "class Solution {\n map<int,int>mp;\n int add(int r, int l){\n auto it=mp.lower_bound(r);\n if((it!=mp.begin() && prev(it)->second>=l) || (it!=mp.end() && it->first<=r && it->second>=l)) return 0;\n int cnt=l-r-1; //Difference between link removed and link added (1), absolute numb... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 3 | {
"code": "class Solution {\npublic:\n int queryseg(vector<int>&seg, vector<int>&lazy, int s1, int s2, int si, int l, int r){\n // cout<<si<<\"\\n\";\n if(lazy[si]!=0){\n seg[si] = 0;\n lazy[2*si+1] = 1;\n lazy[2*si+2] = 1;\n }\n if(s1>=l && s2 <= r){\n ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 3 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n#define vii vector<vector<int>>\n#define vi vector<int>\n#define pb push_back\n#define fi first\n#define se second\n#define s(v) sort(v.begin(), v.bpp())\n#define r(v) reverse(v.begin(), v.bpp())\nclass Solution\n{\npublic:\n vector<int> shortestDistanceAf... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 3 | {
"code": "class Solution {\npublic:\n\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n set<int> f;\n for(int i = 0;i<=n;i++){\n f.insert(i);\n }\n\n vector<int> res;\n for(auto& q : queries){\n int a = q[0];\n i... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 3 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n vector<int> ans;\n set<int> st;\n map<int, int> mp;\n for (int i = 0; i < n; i++) {\n st.insert(i);\n }\n for (auto it : queries) {\n ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 3 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& q) {\n int m = q.size();\n vector<int> d(n), ans(m);\n iota(d.begin(), d.end(), 0);\n set<int> g(d.begin(), d.end());\n for (int i = 0; i < m; ++i) {\n int a = q... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 3 | {
"code": "class Solution {\npublic:\n vector<int> g[100005];\n int dp[100005];\n void bfs(int u, int v){\n if(dp[u] + 1 < dp[v]){\n dp[v] = dp[u] + 1;\n }\n else return;\n queue<int> q;\n q.push(v);\n while(!q.empty()){\n int node = q.front();\... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 3 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n vector<int> dp(n);\n set<int> st;\n\n for(int i = 0; i + 1 < n; i++) dp[i] = i + 1, st.insert(i);\n\n vector<int> ans;\n\n for(auto &q: queries) {\n int u = q[0], v = q[1];\n\n... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 3 | {
"code": "class Solution {\npublic:\n vector<int> tree;\n\n void update(int node, int start, int end, int idx, int val)\n {\n if(start == end)\n {\n tree[node] += val;\n }\n else\n {\n int mid = (start + end) / 2;\n if(start <= idx and idx ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 3 | {
"code": "#include <bits/stdc++.h>\n#include <bits/extc++.h>\nusing namespace std;\nusing namespace __gnu_pbds;\n\ntemplate<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;\n\n\nclass Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vecto... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 3 | {
"code": "#include <ext/pb_ds/assoc_container.hpp> \n#include <ext/pb_ds/tree_policy.hpp> \nusing namespace __gnu_pbds; \n \n#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> \nclass Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vecto... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 3 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n map<int, int>mp;\n for(int i=0;i<n-1;i++)\n {\n mp[i]=i+1;\n }\n vector <int> ans;\n for(auto query:queries)\n {\n if(mp.fi... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 3 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n set<pair<int,int>>st;\n vector<int>ans;\n for(int i=0;i<n-1;i++) st.insert({i,i+1});\n for(auto x:queries){\n int l=x[0],r=x[1];\n auto it=st.lo... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 3 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);\n set<int> st; vector<int> res;\n for ( int i = 0; i<n; i++ ) st.insert(i);\n for ( auto i : queries ... |
3,514 | <p>You are given an integer <code>n</code> and a 2D integer array <code>queries</code>.</p>
<p>There are <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. Initially, there is a <strong>unidirectional</strong> road from city <code>i</code> to city <code>i + 1</code> for all <code>0 <= i < ... | 3 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);\n set<int> st; vector<int> res;\n for ( int i = 0; i<n; i++ ) st.insert(i);\n for ( auto i : queries ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>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 <... | 0 | {
"code": "int speedup = []{ios::sync_with_stdio(0); cin.tie(0); return 0;}();\nint st[1 << 17], fwd[50000], cnts[50000], sums[50000], B, N, C;\n\nvoid fillbt(int *b) {\n for (int i = 0, n = N; i < n; ++i) {\n int j = i | (i+1);\n if (j < n) b[j] += b[i];\n }\n}\n\nvoid init(const vector<int>& col... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>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 <... | 0 | {
"code": "int speedup = []{ios::sync_with_stdio(0); cin.tie(0); return 0;}();\nint st[1 << 17], fwd[50000], cnts[50000], sums[50000], B, N, C;\n\nvoid fillbt(int *b) {\n for (int i = 0, n = N; i < n; ++i) {\n int j = i | (i+1);\n if (j < n) b[j] += b[i];\n }\n}\n\nvoid init(const vector<int>& col... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>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 <... | 0 | {
"code": "class Solution {\npublic:\n vector<int> numberOfAlternatingGroups(vector<int>& colors, vector<vector<int>>& queries) {\n const int N = colors.size();\n map<int, int> counts;\n map<int, int> parts;\n auto get_next = [&](int i) {\n auto next = parts.upper_bound(i);\n... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>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 <... | 0 | {
"code": "template <class B> struct BIT {\n int n;vector<B> s; BIT(int n):n(n),s(n+1){}\n void add(int i,const B&v){for(i++;i<=n;i+=i&-i)s[i]+=v;}\n B sum(int i){B ans{};for(;i;i-=i&-i)ans+=s[i];return ans;}\n B sum(int l,int r){return sum(r)-sum(l);}\n};\nclass Solution {\npublic:\n vector<int> numbe... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>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 <... | 0 | {
"code": "class Solution {\npublic:\n vector<int> numberOfAlternatingGroups(vector<int>& colors, vector<vector<int>>& queries) {\n int i, j = 0, n = colors.size(), m = n + 1, sum, cnt, st1[100005]{}, st2[100005]{};\n map<int, int> range;\n vector<int> ans;\n for (i = 1; i < n; i++) {\n... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>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 <... | 0 | {
"code": "class Lengths {\n unordered_map<int, int> l{};\n\npublic:\n void Add(int len) {\n // cout << \"add len \" << len << endl;\n assert(len > 0);\n l[len] += 1;\n }\n void Remove(int len) {\n // cout << \"del len \" << len << endl;\n assert(len > 0);\n l[len... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>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 <... | 0 | {
"code": "class Solution {\npublic:\n vector<int> numberOfAlternatingGroups(vector<int>& colors, vector<vector<int>>& queries) {\n set<int> bound;\n map<int, int> count;\n int n = colors.size(), m = queries.size();\n // init\n for(int i = 0; i < n;) {\n int j = i;\n ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>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 <... | 0 | {
"code": "#include <array>\n#include <iterator>\n#include <set>\n#include <vector>\n\nnamespace FenwickTree {\n\n template <typename P>\n auto forLvls(int sz, P p) {\n\n auto idx = 0;\n\n for (auto i = 31 - __builtin_clz(sz); i >= 0; --i) {\n const auto n_idx = idx | 1 << i;\n ... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>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 <... | 0 | {
"code": "class Solution {\npublic:\n const bool gdb = 0;\n vector<array<int, 2>> f;\n int lb(int x) {\n return x & -x;\n }\n void _update(int size, int op) {\n if (gdb)\n cout << \"xx \" << size << \" \" << op << endl;\n for (int i = f.size() - size; i < f.size(); i += lb(... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>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 <... | 0 | {
"code": "typedef pair<int, int> pii;\n\nclass FenwickTree {\n vector<array<int, 2>> tree;\npublic:\n FenwickTree(int n) : tree(n + 1) {}\n \n void update(int size, int op)\n {\n for (int i = tree.size() - size; i < tree.size(); i += i & -i) {\n tree[i][0] += op;\n tree[i]... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>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 <... | 0 | {
"code": "// Time: O(nlogn + qlogn)\n// Space: O(n)\n\n// sorted list, freq table, bit, fenwick tree\nclass Solution {\nprivate:\n class BIT {\n public:\n BIT(int n) : bit_(n + 1) { // 0-indexed\n }\n \n void add(int i, int val) {\n ++i;\n for (; i < size(bit... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>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 <... | 0 | {
"code": "// Time: O(nlogn + qlogn)\n// Space: O(n)\n\n// sorted list, freq table, bit, fenwick tree\nclass Solution {\nprivate:\n class BIT {\n public:\n BIT(int n) : bit_(n + 1) { // 0-indexed\n }\n \n void add(int i, int val) {\n ++i;\n for (; i < size(bit... |
3,527 | <p>There are some red and blue tiles arranged circularly. You are given an array of integers <code>colors</code> and a 2D integers array <code>queries</code>.</p>
<p>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 <... | 0 | {
"code": "class Fenwick {\n vector<int> cnts, vals; \npublic: \n Fenwick(int n) {\n cnts.resize(n+1); \n vals.resize(n+1); \n }\n \n void add(int k, int v) {\n for (int i = k+1; i < cnts.size(); i += i & -i) {\n cnts[i] += v; \n vals[i] += v*k; \n }\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.