id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
3,517 | <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:\nint help(vector<int> grid[], int n)\n{\n \n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;\n vector<int>vis(n,0);\n vis[0]=1;\n pq.push({0,0});\n int ans=1e9;\n while(!pq.empty()){\n auto tp=pq.top... |
3,517 | <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<vector<int>> adj;int n;\n int bfs()\n {\n queue<int> q;\n q.push(0);\n vector<int> res(n);\n map<int,int> vis;\n vis[0]=1;\n while(!q.empty())\n {\n int at=q.front();q.pop();\n int f=0;\n ... |
3,517 | <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 unordered_map<int,vector<int>> m;\n vector<int> res;\n for (int i = 0; i < queries.size(); i++) {\n m[queries[i][0]].push_back(queries[i][1]);\n res.pu... |
3,517 | <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": "typedef pair<int,int> p;\nclass Solution {\nprivate: \n int n;\n vector<vector<int>> adj;\n\n int func(int start,int end)\n {\n adj[start].push_back(end);\n\n priority_queue<p,vector<p>,greater<p>> pq;\n pq.push({0,0});\n //dist,node\n unordered_set<int> st... |
3,517 | <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 unordered_map<int, vector<int>> adj;\n \n for (int i = 0; i < n - 1; ++i) {\n adj[i].push_back(i + 1);\n }\n\n\n auto bfs = [&](int start, int end) -> int {\n qu... |
3,517 | <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 bfs(unordered_map<int,vector<int>>& graph,int n) {\n queue<int> q;\n unordered_set<int> vis;\n q.push(0);\n\n vis.insert(0);\n int dis = 0;\n while(!q.empty()) {\n int size = q.size();\n for(int i = 0;i < siz... |
3,517 | <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\nclass Solution {\npublic:\n \n void prepare(int n, vector<vector<int>>& adj) {\n for (int i = 0; i < n - 1; ++i) {\n adj[i].push_back(i + 1); // Linear connections\n }\n }\n\n // Updated getMinDist function using pair<in... |
3,517 | <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\nclass Solution {\npublic:\n \n void prepare(int n, vector<vector<int>>& adj) {\n for (int i = 0; i < n - 1; ++i) {\n adj[i].push_back(i + 1); // Linear connections\n }\n }\n\n // Updated getMinDist function using pair<in... |
3,517 | <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 get_min_distance(vector<vector<int>> &graph, int n){\n queue<pair<int, int>> q;\n q.push({0, 0});\n\n int ans = INT_MAX;\n vector<int> visited(n, 0);\n while(!q.empty()){\n auto [node, depth] = q.front();\n q.pop();... |
3,517 | <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:\nint minim(unordered_map<int,list<int>>&adj,int& n){\n int mini=-1;\n queue<pair<int,int>>q;\n q.push({0,0});\n unordered_map<int,bool>vis;\n vis[0]=true;\n while(!q.empty()){\n auto pa=q.front();\n int dis=pa.first;\n int node=pa.second;\n ... |
3,517 | <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 unordered_map<int, vector<int>> map;\n vector<int> disttoend (n, 0);\n\n for(int i = 0; i < n - 1; i++){\n disttoend[i] = n-1-i;\n }\n\n for(int i =... |
3,517 | <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 bfs(vector<vector<int>>&graph,int n,int s,int t)\n {\n set<int>visit;\n queue<int>q;\n q.push(s);\n visit.insert(s);\n int ans=1;\n while(!q.empty())\n {\n int sz=q.size();\n while(sz--)\n ... |
3,517 | <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> result;\n graph.resize(n);\n for (int i = 0; i < n; ++i) {\n graph[i].push_back(i + 1);\n }\n\n for (const auto& q: queries) {\n ... |
3,517 | <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> result;\n graph.resize(n);\n for (int i = 0; i < n; ++i) {\n graph[i].push_back(i + 1);\n }\n\n for (const auto& q: queries) {\n ... |
3,517 | <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 bfs(int st,int end,map<int,vector<int>>&m){\n queue<pair<int,int>> q;\n map<int,int> vis;\n q.push({st,0});\n vis[st]=1;\n while(q.front().first!=end){\n \n for(auto i:m[q.front().first]){\n if(vis[i]... |
3,517 | <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<vector<int>> graph;\n int bfs(int n){\n queue<int> q;\n q.push(0);\n vector<int> dist(n, 1e9);\n unordered_set<int> visited;\n visited.insert(0);\n dist[0] = 0;\n while(! q.empty()){\n int node = q.front();\n ... |
3,517 | <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<vector<int>>graph;\n int bfs(int n){\n unordered_set<int>visited;\n visited.insert(0);\n vector<int>dist(n,1e9);\n dist[0]=0;\n queue<int>q;\n q.push(0);\n while(q.size()>0){\n int node = q.front();\n ... |
3,517 | <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<vector<int>> adj(n,vector<int>());\n for(int i=0;i<n-1;i++){\n adj[i].push_back(i+1);\n }\n vector<int> ans;\n for(auto i:queries){\n ... |
3,517 | <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 unordered_map<int,vector<int>>mapping;\n vector<int>ans;\n for(int i=1;i<n;i++)\n {\n mapping[i].push_back(i-1);\n }\n for(int i=0;i<... |
3,517 | <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,\n vector<vector<int>>& queries) {\n std::vector<std::vector<int>> maps(n);\n for (int i = 0; i < n - 1; i++)\n maps[i].push_back({i + 1});\n\n std::vect... |
3,517 | <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 findMinPath(unordered_map<int, unordered_set<int>> &mp, int s, int e, unordered_map<int, int> &dp) {\n if(s==e) return 0;\n if(dp.find(s) != dp.end())\n return dp[s];\n int minPath{INT_MAX-1};\n for(auto x: mp[s]) {\n ... |
3,517 | <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 bfs(vector<vector<int>>&edges,int n){\n queue<int>q;\n unordered_set<int>st;\n st.insert(0);\n q.push(0);\n int count=0;\n int ans=n;\n while(q.size()>0){\n int s=q.size();\n count++;\n whil... |
3,517 | <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:\nint n;\n\nint l;\nint dik(vector<vector<int>>&g){\nvector<int> d(l,1e9);\npriority_queue<vector<int>> q;\nd[0]=0;\nq.push({0,0});\nwhile(!q.empty()){\n \nint dis=-q.top()[0];\nint cur=q.top()[1];\nq.pop();\nfor(int i:g[cur]){\n \n if(d[i]>dis+1){\n // cout<<\"S\"<<... |
3,517 | <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<vector<int> > adj;\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n adj.resize(n, vector<int>(n, 0));\n for(int i = 0; i < n-1; i++) {\n adj[i][i+1] = 1;\n }\n vector<int> ret;\n for(au... |
3,517 | <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 void bfs(queue<pair<int, int>> q, vector<int> adj[], vector<int>& vis, int& ans){\n q.push({0, 0});\n int n = vis.size() - 1;\n while(!q.empty()){\n int node = q.front().first;\n vis[node] = 1;\n int dist = q.front().secon... |
3,517 | <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[500];\n int bfs(int n){\n vector<int>par(n);\n vector<int>vis(n,0);\n queue<int>q;\n q.push(0);\n int f=0;\n for(auto i:g)sort(i.begin(),i.end());\n while(!q.empty()){\n int x=q.front();\n ... |
3,517 | <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 {\nprivate: \n void dsk(unordered_map<int,vector<int>>& adj,vector<int>& shortest_path,int n){\n vector<int> visited(n);\n vector<long long> distance(n,1e9);\n queue<pair<int,int>> q;\n distance[0] = 0;\n q.push({0,0});\n\n while(q.size() > 0){\n ... |
3,517 | <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>* getPathBFS(int** edges, int n, int sv, int ev, bool* visited) {\n queue<int> q;\n q.push(sv);\n visited[sv] = true;\n vector<int>* ans = new vector<int>;\n int flag = 0;\n map<int, int> map;\n while(!q.empty()) {\n int front = q.front(... |
3,517 | <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 findShortest(vector<vector<int>>&adj,int node,int end){\n queue<pair<int,int>>q;\n unordered_map<int,bool>visited;\n\n\n\n q.push({0,0});\n\n while(!q.empty()){\n auto itr = q.front();\n int frontnode = itr.first;\n ... |
3,517 | <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 findShortest(vector<vector<int>>&adj,int node,int end){\n queue<pair<int,int>>q;\n unordered_map<int,bool>visited;\n\n\n\n q.push({0,0});\n\n while(!q.empty()){\n auto itr = q.front();\n int frontnode = itr.first;\n ... |
3,517 | <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 {\n map<int, vector<pair<int, int>>> adjList; //nei, dist\n for(int i=0; i<n-1; i++)\n {\n adjList[i].push_back({i+1, 1});\n }\n // print(adjList)... |
3,517 | <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 int solve(unordered_map<int ,list<int> > & adj ,int n ){\n\n unordered_map<int ,bool > visited(n) ;\n vector<int> parent(n,-1) ;\n\n queue<int> q ;\n q.push(0) ;\n visited[0] = true ;\n\n while(! q.empty() ){\n\n int f = q.front()... |
3,517 | <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 usingBFS(int sou,int dest,unordered_map<int,vector<int> > &mp){\n unordered_map<int,bool> visited;\n int count=1;\n deque<int> q;\n deque<int> temp;\n q.push_back(sou);\n temp.push_back(sou);\n while(!temp.empty()){\n q=tem... |
3,517 | <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": "#define pii pair<int,int>\n#define vi vector<int>\n#define vii vector<pair<int,int>>\n#define pb push_back\n#define mod 998244353\n#define MOD 1000000007\n#define ll long long\n#define inf INT_MAX\n#define for0(i,n) for(int i=0;i<n;i++)\n#define for1(i,n) for(int i=1;i<=n;i++)\n#define all(x) begin(x),end(... |
3,517 | <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 \n \n vector<pair<int,int>>adj[n+1];\n for(int i=0;i<n;i++){\n if(i+1<n){\n adj[i].push_back({i+1,1});\n }\n }\n ve... |
3,517 | <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 void traverse(vector<vector<int>>graph,vector<int>& dis){\n for(int i =0;i<graph.size();i++){\n for(int j = 0;j<graph[i].size();j++){\n // cout<<i<<\" \"<<j<<\" \"<<dis[graph[i][0]]<<\" \";\n dis[graph[i][j]] = min(dis[graph[i][... |
3,517 | <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 unordered_map<int, vector<int>> graph;\n for (int i = 0; i < n - 1; ++i) {\n graph[i].push_back(i + 1);\n }\n for (const auto& qu... |
3,517 | <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": "#define ll long long\nclass Solution {\npublic:\n vector<vector<ll>> gra;\n \n ll func(ll n){\n priority_queue<ll,vector<ll>,greater<ll>>pq;\n pq.push(0);\n vector<ll> dis(510,INT_MAX);\n dis[0] = 0;\n while(pq.size()>0){\n ll head = pq.top();\n ... |
3,517 | <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,\n vector<vector<int>>& queries) {\n std::vector<std::vector<int>> maps(n);\n for (int i = 0; i < n - 1; i++)\n maps[i].push_back({i + 1});\n\n std::vect... |
3,517 | <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 const int INF=1e9;\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n vector<int> ans;\n vector<vector<pair<int,int>>> g(n);\n for(int i=0; i<n-1; i++){\n g[i].emplace_back(i+1,1);\n }\n vector<... |
3,517 | <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:\nconst int MAX_NODES = 501;\nvector<pair<int,int>> gr[501];\n\n int bfs(int s,int e){\n queue<pair<int,int>> q;\n vector<int> distance(MAX_NODES, -1);\n vector<int> parent(MAX_NODES, -1);\n q.push({0,0});\n distance[0]=0;\n while(q.empty()=... |
3,517 | <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 dijkstra(vector<int> adj[],int n){\n set<pair<int,int>> st;\n vector<int> dist(n,1e9);\n\n dist[0]=0;\n st.insert({0,0});\n\n while(st.size()){\n int currDist=(*st.begin()).first;\n int node=(*st.begin()).second;\n ... |
3,517 | <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> dijkstra(int V, vector<vector<int>> &adj, int S){\n // priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;\n set<pair<int,int>>st;\n vector<int>dist(V,1e9);\n // for(int i=0;i<V;i++)dist[i]=1e9;\n st.in... |
3,517 | <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#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,517 | <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\nclass Solution {\npublic:\n int dijkstra(map<int, list<int>>& adj, int vertices, int source) {\n vector<int> dis(vertices, INT_MAX);\n set<pair<int, int>> st;\n\n dis[source] = 0;\n st.insert({0, source});\n\n while (!s... |
3,517 | <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 vector<vector<pair<int,int>>>adj(n+1);\n for (int i=0;i<n;i++){\n adj[i].push_back({i+1,1});\n }\n vector<int>ans;\n for (int i=0;i<q.size();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": "int speedup = []{ios::sync_with_stdio(0); cin.tie(0); return 0;}();\nint nx[100000];\n\nclass Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n iota(nx, nx+n, 1);\n vector<int> res; res.reserve(size(queries));\n int d = 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": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n int nx[100000];\n iota(nx, nx + n, 1);\n\n vector<int> result;\n result.reserve(queries.size());\n\n int d = n - 1;\n for (const auto& q : 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 Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n int nxt[n+1];\n for (int i(1); i < n; ++i) nxt[i-1] = i;\n nxt[n] = 0;\n\n vector<int> res;\n for (auto& q : queries) {\n int i = q[0], j = 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 < ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n int next[n];\n bool f[n];\n vector<int> ans;\n for (int i=0;i<n;i++) {\n next[i]=i+1;\n f[i]=true;\n }\n int dist=n-1;\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 int m(1);\n while (m < n) m<<=1;\n int seg[2*m];\n bool lzy[2*m];\n memset(lzy,0,sizeof(lzy));\n function<int(int,int,int)> bld =[&](int x, int l, int r... |
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 m(1);\n while (m < n) m<<=1;\n int seg[2*m];\n bool lzy[2*m];\n memset(lzy,0,sizeof(lzy));\n function<int(int,int,int)> bld =[&](int x, int l, int r... |
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 st[400005];\n int lz[400005];\n \n void update_range(int si, int ss, int se, int qs, int qe, int v) {\n if (lz[si] != -1) {\n st[si] = (se - ss + 1)*lz[si];\n \n if (ss != se) {\n lz[2*si + 1] = lz[si];\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 const static int MAXN=1e5+5;\n struct Node{\n int sum=0;\n int tag=-1;\n };\n Node seg[4*MAXN]={};\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n modify(1,1,n,1,n,1);\n int q=queries.size();\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> arr(n);\n for(int i = 0; i < n; i++)\n {\n arr[i] = i;\n }\n \n vector<int> ans(queries.size());\n \n for(int 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 < ... | 0 | {
"code": "class UF {\npublic:\n vector<int> p;\n UF(int n) {\n p.resize(n);\n for (int i = 0; i < n; i++) {\n p[i] = i;\n }\n }\n int find(int x) {\n if (p[x] != x) {\n p[x] = find(p[x]);\n }\n return p[x];\n }\n void merge(int a, 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\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n vector<int> m(n,0);\n for(int i=0;i<n;i++){\n m[i] = i+1;\n }\n int dist = n-1;\n vector<int> ans;\n\n for(auto& q : 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 int size(Node *head){\n int n=0;\n while(head!=NULL){\n n++;\n head=head->next;\n }\n return... |
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 // For a query[i] = [u_i, v_i], if there exists a query[j] = [u_j, v_j] such that\n // (1) j < i\n // (2) u_j <= u_i <= v_i <= v_j\n // then adding a unidirectional r... |
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> nxt(n);\n iota(nxt.begin(), nxt.end(), 1);\n vector<unsigned char> vis(n);\n int s = n - 1;\n vector<int> ans;\n for (const auto& query : qu... |
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 mx 100005\nint seg[4*mx];\nint lz[4*mx];\nvoid build(vector<int>&v,int high,int low=0,int ind=0){\n if(low==high){\n seg[ind]=v[low];\n return ;\n }\n int m=(low+high)>>1;\n build(v,high,m+1,ind*2+2);\n build(v,m,low,ind*2+1);\n seg[ind]=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 int fa[100005];\n \n int find_fa(int p){\n int j, k;\n j = p;\n while (fa[j] != -1) j = fa[j];\n while (p != j){\n k = fa[p];\n fa[p] = j;\n p = k;\n }\n \n return j;\n }\n \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": "#define ll long long\nclass Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& q) {\n vector<int>arr(n,0);\n int m=q.size();\n vector<int>ends(n,-1);\n ends[n-1]=n+1;\n ll prev=n-1;\n vector<int>ans(m,0);\n for(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": "\n\n\nclass Solution {\npublic:\n int t[401110] = {0};\n\nvoid build (int v, int tl, int tr) {\n\tif (tl == tr)\n\t\tt[v] = 1;\n\telse {\n\t\tint tm = (tl + tr) / 2;\n\t\tbuild (v*2, tl, tm);\n\t\tbuild ( v*2+1, tm+1, tr);\n\t\tt[v] = t[v*2] + t[v*2+1];\n\t}\n}\n\nvoid push (int v) {\n\tif (t[v] == 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 < ... | 0 | {
"code": "class Solution {\npublic:\n map<int,int> route; // <start, end>\n int distance;\n bool IsIncludedInRoute( map<int,int>::iterator startIter, const int startNode, const int endNode) {\n if(startIter == route.end() || startIter->first > startNode) {\n if(startIter == route.begin(... |
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 map<int,int> route; // <start, end>\n int distance;\n bool IsIncludedInRoute( map<int,int>::iterator startIter, const int startNode, const int endNode) {\n if(startIter == route.end() || startIter->first > startNode) {\n if(startIter == route.begin(... |
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> shortestDistanceAfterQueries0(int n, vector<vector<int>>& queries) {\n int edge = n-1;\n vector<int> ans;\n map<int, int> mp;\n for(const auto& q : queries) {\n int a = q[0], b = q[1];\n int remove = b-a-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> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n int dist = n - 1;\n vector<int> res;\n\n set<pair<int, int>> segments;\n for (int q = 0; q < queries.size(); q++) {\n int l = queries[q][0], r = queries[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 < ... | 0 | {
"code": "class Solution {\npublic:\n vector<int> nodes;\n\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n nodes.resize(n - 1, 0);\n for (int i = 0; i < nodes.size(); i++) {\n nodes[i] = i;\n }\n vector<int> res;\n int count = 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>v(n);\n for(int i=0; i<n; i++){\n v[i]=i;\n\n }\n vector<int>ans;\n for(auto it: queries){\n auto it1=lower_bound(v.begin(), 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 vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n map<int, int> intv;\n vector<int> ans;\n int shortcut = 0;\n int cur_cnt = n-1;\n for(auto& q: queries) {\n if (intv.find(q[0]) != intv.end()) {\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 std::vector<int> shortestDistanceAfterQueries(int n, std::vector<std::vector<int>>& queries) {\n std::vector<int> ans;\n std::set<std::pair<int, int>> removedIntervals;\n int size = n;\n \n for (const auto& q : queries) {\n int 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 < ... | 0 | {
"code": "struct BIT {\n vector<int> arr;\n int n = 0;\n\n BIT(int n): arr(n+1), n{n} {}\n\n void update(int idx, int value) {\n idx++;\n\n while (idx <= n) {\n arr[idx] += value;\n idx += idx & (-idx);\n }\n }\n\n int sum(int idx) {\n 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> ret(queries.size());\n // starting idces of the queries\n set<int> roads;\n map<int, int> query_map;\n auto final_sz = n - 1;\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 can greedily take every bridge\n */\n vector<int> result;\n result.reserve(queries.size());\n vector<int> next(n);\n iota(next.begin(), ne... |
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 k= q.size(), dis= n-1, sub= 0;\n vector<int> ans;\n vector<int> v(n, -1);\n set<int> s; \n for(int i=0; i<k; i++){\n int from= q[i][0], to= q[i][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> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n vector<int> res;\n int cur_dist = n - 1;\n vector<int> next, valid(n, 1);\n for (int i = 0; i < n - 1; ++i) {\n next.push_back(i + 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 SegmentTree{\n public:\n vector<int>tree;\n SegmentTree(int n){ \n tree.assign(4*n,1);\n build(1,0,n-1);\n }\n int build(int node,int l,int r)\n {\n if(l==r)return tree[node];\n int mid = l+(r-l)/2;\n int ls = build(2*node,l,mid);\n int rs =... |
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#pragma GCC optimize(2)\n#define rep(i, a, b) for (int i = (a); i < (b); ++i)\n#define rep_(i, a, b) for (int i = (a); i > (b); i--)\n#define mst(x, a) memset(x, a, sizeof(x))\n#define all(a) begin(a), end(a)\n#define lowbit(x) ((x) & (-(x)))\n#define bitcnt(x) (__builtin_popcount... |
3,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 insert(map<int,int> & mp, int from, int to, int ans) {\n auto iter = mp.lower_bound(from);\n if(iter != mp.begin() and !mp.empty()) iter--;\n for(auto it = iter; it != mp.end(); it++) {\n if(it->second <= from) continue;\n else 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": "template <typename Node>\nstruct BottomUpSegmentTree {\n std::size_t n{};\n std::vector<Node> nodes;\n\n BottomUpSegmentTree() = default;\n\n explicit BottomUpSegmentTree(std::size_t n_) { init(std::vector(n_, Node())); }\n\n BottomUpSegmentTree(std::size_t n_, Node&& node) {\n init(std::vector(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>v,ans;\n for(int i=0;i<n;i++){\n v.push_back(i);\n }\n for(auto it:queries){\n int u = it[0];\n int x = it[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> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n int ans=n-1;\n map<int,int> m;//right,left\n vector<int> res;\n for(auto q : queries){\n int u=q[0],v=q[1];\n // cout<<u<<\" \"<<v<<endl;\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>ans;set<pair<int,int>>s;int val=n-1;\n for(auto x:queries){\n s.insert({x[0],x[1]});val-=(x[1]-x[0]-1);\n auto it=s.lower_bound({x[0],-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": "const double eps = 1e-6;\n#define ll long long\ntypedef long double ld;\n#define pb push_back // for vector\n#define pi pair \n#define all(a) a.begin(), a.end()\n#define rep(i, a, b) for (ll i = a; i < b; i++)\n#define ff first\n#define ss second\n#define vt vector\n#define vi vt<ll>\n#define ub upper_boun... |
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 pb push_back\n#define f first\n#define s second \n#define pii pair<int,int>\nclass Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n vector<int>ans;\n set<pii>s;\n int sum = n-1;\n for(int i=0;i<queries.size();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": "#include<bits/stdc++.h>\nusing namespace std;\nclass Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n set<pair<int,int>> s1;\n set<pair<int,int>> s2;\n int dis = n-1;\n vector<int> ans;\n for(auto i : 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 Solution {\npublic:\n vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {\n vector<int> ans;\n vector<int> dist(n),dist2(n);\n for(int i=0;i<n;i++){\n dist[i]=i;\n dist2[n-i-1]=i;\n }\n vector<int> st;\n fo... |
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 vector<int> dist(n),dist2(n);\n for(int i=0;i<n;i++){\n dist[i]=i;\n dist2[n-i-1]=i;\n }\n vector<int> st;\n fo... |
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> ans;\n int temp=n-1;\n\n set<int> s1;\n map<int,int> m1;\n \n for(auto it:queries){\n if(it[1]-it[0]==1){\n ans.... |
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 deb(x) cout << #x << \": \" << x << '\\n'\n#define debl(x) cout << #x << \": \" << x << ' '\n#define rep(i,n) for(int i = 0; i<n; ++i)\n\nclass Solution {\npublic:\nstruct SegmentTree{\n int df, n; vector<int> t, lz;\n int combine(int a, int b){return a+b;}\n\n void build(vector<int> A){ \n d... |
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;\nusing i64 = long long;\n\n#ifdef LOCAL\n#include \"algo/debug.h\"\n#else\n#define debug(...)\n#endif\n\n/*\n * @author jiangly\n * https://codeforces.com/profile/jiangly\n */\ntemplate <class Info, class Tag>\nstruct LazySegmentTree {\n int n;\n std::ve... |
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;\n void build(const std::vector<int>& arr, int node, int start, int end) {\n if (start == end)\n tree[node] = arr[start];\n else {\n int mid = (start + end) / 2;\n build(arr, 2 * node + 1, start, mid);\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 set<vector<int>>st;\n int ans = n-1;\n vector<int>fans;\n for(auto &x : queries){\n if(st.size()==0){\n ans -= (x[1]-x[0]);\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 getSubinterval(vector<int> q, set<pair<int, int>>& st){\n int start = q[0];\n int end = q[1];\n int res = 0;\n auto it = st.lower_bound({q[0], 0});\n // if(it != st.begin()) it--;\n \n while(it != st.end()){\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 \n \n struct ms{\n \n vector<int> t;\n \n int size = 1;\n \n void init(int n){\n \n while(size < n )\n size *= 2;\n \n t.resize(2*size, 0);\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 Solution {\npublic:\n int shortest(vector<vector<int>>& graph) {\n int n = graph.size();\n queue<pair<int, int>> bfs;\n vector<bool> visited(n, false);\n bfs.push({0, 0});\n visited[0] = true;\n while (!bfs.empty()) {\n auto [node, dist] = bfs.front(); bfs.pop();\n if (no... |
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 map<int,int>start_last;\n map<int,int>last_start;\n int ans = n-1;\n vector<int>ret;\n for(auto it:queries){\n if(start_last.empty()){\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 {\n vector<int> tree, lazy;\n int n;\npublic:\n SegmentTree(int size) : n(size) {\n tree.resize(4 * n, 0);\n lazy.resize(4 * n, 1);\n }\n\n void build(int node, int start, int end) {\n if (start == end) {\n tree[node] = 1;\n } else {\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 class ST {\n public:\n vector<int> st,lazy;\n int n;\n\n ST(int n) {\n this->n = n;\n st.resize(4*n,0);\n lazy.resize(4*n,-1);\n buildTree(0,0,n-1);\n }\n\n void update(int left, int right) {\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.