Skip to content

Commit a485b8f

Browse files
Merge branch 'master' into master
2 parents 15c6d89 + 58797ac commit a485b8f

38 files changed

+1291
-2
lines changed

CONTRIBUTORS.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,14 @@ These are the list of contributors to this project **who have completed 5 proble
116116
117117
> <img src="https://avatars0.githubusercontent.com/u/53379005?s=400&u=a852e463c8cbae7653bf7651c0844b384ab7a7d8&v=4" width="50"> [Utkarsh Shankar](https://github.com/UtkarshShankar)
118118
119+
> <img src="https://avatars0.githubusercontent.com/u/52209941?s=460&u=10cdd32a6dffc5d10e4dfd6d46821e59fbff5ca6&v=4" width="50"> [Saurabh Nikam](https://github.com/saurabh-nikam/)
120+
121+
> <img src="https://avatars1.githubusercontent.com/u/53162729?s=400&u=16783675e602b7de353919c32357c7e12bc69ee3&v=4" width="50"> [Sahil Agarwal](https://github.com/agarwalsahil0210)
122+
123+
> <img src="https://avatars1.githubusercontent.com/u/53288567?s=400&u=affbca75ed842d8471ee39b7ff0e80987607f359&v=4" width="50"> [Sonu Kumar Sharma](https://github.com/Sharma-chanism)
124+
125+
> <img src="https://avatars0.githubusercontent.com/u/21211904?s=460&v=4" width="50"> [Ayush Sharma](https://github.com/ayush933)
126+
127+
> <img src="https://avatars2.githubusercontent.com/u/53346605?s=400&u=3123e8b1d21be6142c5250360fc1ccd6939bbd61&v=4" width="50"> [Sudeep Swain](https://github.com/Sudeep25022000)
128+
119129
> <img src="https://avatars1.githubusercontent.com/u/53577764?s=400&u=2efa2f97e039e28e8024495dfa71966fdc551089&v=4" width="50"> [Sanket Nayak](https://github.com/SanketKN)
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// author: 4yush933
2+
// problem: https://cses.fi/problemset/task/1651/
3+
// Sol: https://cses.fi/problemset/result/1103946/
4+
// Question: Standard application of segment tree
5+
6+
7+
8+
// Problem: Range Update Queries
9+
// Contest: CSES - CSES Problem Set
10+
// URL: https://cses.fi/problemset/task/1651
11+
// Memory Limit: 512 MB
12+
// Time Limit: 1000 ms
13+
//
14+
// Powered by CP Editor (https://cpeditor.org)
15+
16+
#pragma GCC optimize("O3")
17+
#include <bits/stdc++.h>
18+
#include <fstream>
19+
using namespace std;
20+
typedef long long ll;
21+
#define F first
22+
#define pii pair<int,int>
23+
#define S second
24+
#define endl "\n"
25+
#define gcd(a,b) __gcd(a,b)
26+
#define lcm(a,b) a/gcd(a,b)*b
27+
#define mem(z,i) memset(z,i,sizeof(z))
28+
#define eps 1e-7
29+
#define I (int)
30+
#define mod 1000000007
31+
#define pb push_back
32+
const long long INF = 1000000000000000000LL;
33+
template <typename Type>
34+
ostream &operator<<(ostream &out, vector<Type> &vec) {
35+
for (auto val : vec)
36+
out << val << " ";
37+
return out;
38+
}
39+
//const int WASTE=∞
40+
const int N=2e5+5;
41+
#define int ll
42+
int t[2 * N],n;
43+
void build() { // build the tree
44+
for(int x=n-1;x>0;x--) t[x]=t[x*2]+t[x*2+1];
45+
}
46+
void modify(int l,int r,int value) { // set value at position p
47+
for(l+=n,r+=n+1;l<r;l/=2,r/=2){
48+
if(l&1) t[l++]+=value;
49+
if(r&1) t[--r]+=value;
50+
}
51+
}
52+
int query(int p) { // sum on interval [l, r]
53+
int res = 0;
54+
for(p+=n;p;p/=2) res+=t[p];
55+
return res;
56+
}
57+
signed main() {
58+
ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
59+
// cout<<fixed;
60+
// cout.precision(10);
61+
// ofstream cout (".out");
62+
// ifstream cin (".in");
63+
// #define int ll
64+
int q;
65+
cin>>n>>q;
66+
for(int x=0;x<n;x++) cin>>t[x+n];
67+
//build();
68+
while(q--){
69+
int i;
70+
cin>>i;
71+
if(i==1){
72+
int l,r,v;
73+
cin>>l>>r>>v;
74+
modify(--l,--r,v);
75+
}
76+
else{
77+
cin>>i; cout<<query(--i)<<endl;
78+
}
79+
}
80+
81+
82+
83+
84+
85+
86+
87+
88+
89+
90+
return 0;
91+
}
92+
// Profile:https://cses.fi/user/13405
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Building Roads","group":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1666","interactive":false,"memoryLimit":512,"timeLimit":1000,"tests":[{"id":1601085870725,"input":"4 2\n1 2\n3 4\n","output":"1\n2 3\n"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BuildingRoads"}},"srcPath":"/media/zcruz/Data/Study/CPLibrary/Problems/CSES/Graph/Building_Roads.cpp"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Building Teams","group":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1668","interactive":false,"memoryLimit":512,"timeLimit":1000,"tests":[{"id":1601357601408,"input":"5 3\n1 2\n1 3\n4 5\n","output":"1 2 2 1 2\n"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"BuildingTeams"}},"srcPath":"/media/zcruz/Data/Study/CPLibrary/Problems/CSES/Graph/Building_Teams.cpp"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Counting Rooms","group":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1192","interactive":false,"memoryLimit":512,"timeLimit":1000,"tests":[{"id":1601085822567,"input":"5 8\n########\n#..#...#\n####.#.#\n#..#...#\n########\n","output":"3\n"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"CountingRooms"}},"srcPath":"/media/zcruz/Data/Study/CPLibrary/Problems/CSES/Graph/Counting_Rooms.cpp"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Labyrinth","group":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1193","interactive":false,"memoryLimit":512,"timeLimit":1000,"tests":[{"id":1601085858617,"input":"5 8\n########\n#.A#...#\n#.##.#B#\n#......#\n########\n","output":"YES\n9\nLDDRRRRRU\n"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"Labyrinth"}},"srcPath":"/media/zcruz/Data/Study/CPLibrary/Problems/CSES/Graph/Labyrinth.cpp"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Message Route","group":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1667","interactive":false,"memoryLimit":512,"timeLimit":1000,"tests":[{"id":1601106441000,"input":"5 5\n1 2\n1 3\n1 4\n2 3\n5 4\n","output":"3\n1 4 5\n"}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"MessageRoute"}},"srcPath":"/media/zcruz/Data/Study/CPLibrary/Problems/CSES/Graph/Message_Route.cpp"}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"files.associations": {
3+
"iostream": "cpp"
4+
}
5+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
void DFS_util(int node,vector<vector<int>>&mat,vector<bool>&visited)
4+
{
5+
visited[node]=true;
6+
for(auto v:mat[node])
7+
{
8+
if(!visited[v])
9+
DFS_util(v,mat,visited);
10+
}
11+
}
12+
int main()
13+
{
14+
ios_base::sync_with_stdio(false);
15+
cin.tie(NULL);
16+
int n,m;
17+
cin>>n>>m;
18+
vector<vector<int>>g(n);
19+
for(int i=0;i<m;i++)
20+
{
21+
int u,v;
22+
cin>>u>>v;
23+
g[u-1].push_back(v-1);
24+
g[v-1].push_back(u-1);
25+
}
26+
vector<bool>visited(n,false);
27+
vector<int>cities;
28+
int comp=0;
29+
for(int i=0;i<n;i++)
30+
{
31+
if(!visited[i])
32+
{
33+
cities.push_back(i);
34+
DFS_util(i,g,visited);
35+
comp++;
36+
}
37+
}
38+
int start=cities[0]+1;
39+
cout<<comp-1<<endl;
40+
for(int i=1;i<cities.size();i++)
41+
{
42+
cout<<start<<" "<<cities[i]+1<<endl;
43+
}
44+
45+
46+
return 0;
47+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
#define endl "\n"
4+
5+
bool DFS_color(int node,int col, vector<int>&color,vector<vector<int>>&g)
6+
{
7+
8+
color[node]=col;
9+
bool res=true;
10+
for(auto v:g[node])
11+
{
12+
13+
if(color[v]==0)
14+
{
15+
16+
res= res&DFS_color(v,(col^3),color,g);
17+
}
18+
if(color[node]==color[v])
19+
return false;
20+
21+
}
22+
return res;
23+
}
24+
25+
int main()
26+
{
27+
ios_base::sync_with_stdio(false);
28+
cin.tie(NULL);
29+
30+
int n,m;
31+
cin>>n>>m;
32+
vector<vector<int>> g(n);
33+
vector<int>color(n,0);
34+
35+
for(int i=0;i<m;i++)
36+
{
37+
int u,v;
38+
cin>>u>>v;
39+
g[u-1].push_back(v-1);
40+
g[v-1].push_back(u-1);
41+
}
42+
bool res=true;
43+
for(int i=0;i<n;i++)
44+
{
45+
if(color[i]==0)
46+
{
47+
res=res&DFS_color(i,1,color,g);
48+
}
49+
}
50+
if(res)
51+
{
52+
for(int i=0;i<n;i++)
53+
cout<<color[i]<<" ";
54+
cout<<endl;
55+
}
56+
else
57+
{
58+
cout<<"IMPOSSIBLE\n";
59+
}
60+
61+
return 0;
62+
}

0 commit comments

Comments
 (0)