-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
896feab
commit 6b0b17e
Showing
22 changed files
with
190 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.vscode |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,142 +1,142 @@ | ||
#include<iostream> | ||
#include<algorithm> | ||
#include<vector> | ||
#include<set> | ||
#include<map> | ||
const long long INT_MAX = 1e5 + 10; | ||
|
||
using namespace std; | ||
|
||
void vectorDemo() { | ||
// std::vector | ||
|
||
// NOTES: | ||
// 1. std::vector is a sequence container and also known as Dynamic Array or Array List. | ||
// 2. Its size can grow and shrink dynamically, and no need to provide size at compile time. | ||
|
||
// ELEMENT ACCESS | ||
// at(), [], front(), back(), data() | ||
|
||
// MODIFIERS: | ||
// insert(), emplace(), push_back(), emplace_back(), pop_back(), resize(), swap(), erase(), clear() | ||
|
||
vector<int> A = {1, 2, 3, 8, 4, 9, 10, 0}; | ||
sort(A.begin(), A.end()); | ||
|
||
cout << binary_search(A.begin(), A.end(), 3); //O(NlogN) | ||
A.push_back(100); | ||
A.push_back(100); | ||
A.push_back(100); | ||
A.push_back(100); | ||
A.push_back(123); | ||
|
||
vector<int>::iterator itr = upper_bound(A.begin(), A.end(), 100);//> | ||
auto itr2 = lower_bound(A.begin(), A.end(), 100); //>= | ||
cout << itr - itr2 <<"\n"; //Occurence count | ||
|
||
//Traversing using itr...tradition method | ||
for(itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " "; | ||
|
||
cout <<"\n"; | ||
//third method | ||
for(int &x : A) { //&x for globally changing the values | ||
x++; | ||
cout << x <<" "; | ||
} | ||
|
||
cout << "\nAuto Traversing"; | ||
//Traversing using auto keyword | ||
for(auto &itr : A) cout << itr <<" "; | ||
} | ||
|
||
void setDemo() { | ||
/*SET is used when: | ||
Consider we need a container with the following features: | ||
add an element, but do not allow duples [duplicates?] - O(logN) | ||
remove elements - O(logN) | ||
get count of elements (distinct elements) - O(1) | ||
check whether elements are present in set - O(logN) | ||
*/ | ||
|
||
set<int> S; | ||
S.insert(1); | ||
S.insert(3); | ||
S.insert(2); | ||
S.insert(-2); | ||
S.insert(-10); | ||
|
||
for(int x: S) cout << x <<" ";//O(logN) //-10 -2 1 2 3 | ||
//Sorted order...no sort reqd as compared to vectors | ||
cout <<"\n"; | ||
|
||
auto itr = S.find(100); | ||
if(itr == S.end()) cout <<"Not Present\n"; | ||
else { | ||
cout << "Present\n"; | ||
cout << *itr <<"\n"; | ||
} | ||
|
||
auto itr2 = S.lower_bound(-1111); | ||
auto itr3 = S.upper_bound(2); | ||
cout << *itr2 <<" " << *itr3<<"\n"; | ||
|
||
if(itr3 == S.end()) cout << "End!"; | ||
|
||
S.erase(-2); | ||
S.erase(0);//no runtime error given. just ignores | ||
for(int x: S) cout << x <<" "; | ||
} | ||
|
||
void mapDemo() { | ||
map<int, int> A; //Mapping takes O(logN) time | ||
A[1] = 100; | ||
A[2] = 200; | ||
A[4] = 400; | ||
|
||
map<char, int> cnt; | ||
string x = "Saurav"; | ||
|
||
for(char c: x) { | ||
cnt[c]++; | ||
} | ||
cout << cnt['a'] <<"\n"; | ||
} | ||
|
||
void PowerOfStl() { | ||
/* | ||
add[10, 100] | ||
add[250, 300] | ||
give me the interval of 267 | ||
*/ | ||
set< pair<int, int> > S; | ||
S.insert({401, 450}); | ||
S.insert({10, 20}); | ||
S.insert({30,400}); | ||
S.insert({2,3}); | ||
|
||
int point = 11; | ||
|
||
auto itr = S.upper_bound({point, INT_MAX}); | ||
if(itr == S.begin()) { | ||
cout <<"Not in range\n"; | ||
return 0; | ||
} | ||
|
||
itr--; | ||
pair<int, int> current = *itr; | ||
if(current.first <= point && point <= current.second) { | ||
cout <<"Present " << current.first <<" " << current.second<<'\n'; | ||
} | ||
else { | ||
cout <<"Not Present"; | ||
} | ||
} | ||
|
||
int main() { | ||
|
||
return 0; | ||
} | ||
#include<iostream> | ||
#include<algorithm> | ||
#include<vector> | ||
#include<set> | ||
#include<map> | ||
const long long INT_MAX = 1e5 + 10; | ||
|
||
using namespace std; | ||
|
||
void vectorDemo() { | ||
// std::vector | ||
|
||
// NOTES: | ||
// 1. std::vector is a sequence container and also known as Dynamic Array or Array List. | ||
// 2. Its size can grow and shrink dynamically, and no need to provide size at compile time. | ||
|
||
// ELEMENT ACCESS | ||
// at(), [], front(), back(), data() | ||
|
||
// MODIFIERS: | ||
// insert(), emplace(), push_back(), emplace_back(), pop_back(), resize(), swap(), erase(), clear() | ||
|
||
vector<int> A = {1, 2, 3, 8, 4, 9, 10, 0}; | ||
sort(A.begin(), A.end()); | ||
|
||
cout << binary_search(A.begin(), A.end(), 3); //O(NlogN) | ||
A.push_back(100); | ||
A.push_back(100); | ||
A.push_back(100); | ||
A.push_back(100); | ||
A.push_back(123); | ||
|
||
vector<int>::iterator itr = upper_bound(A.begin(), A.end(), 100);//> | ||
auto itr2 = lower_bound(A.begin(), A.end(), 100); //>= | ||
cout << itr - itr2 <<"\n"; //Occurence count | ||
|
||
//Traversing using itr...tradition method | ||
for(itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " "; | ||
|
||
cout <<"\n"; | ||
//third method | ||
for(int &x : A) { //&x for globally changing the values | ||
x++; | ||
cout << x <<" "; | ||
} | ||
|
||
cout << "\nAuto Traversing"; | ||
//Traversing using auto keyword | ||
for(auto &itr : A) cout << itr <<" "; | ||
} | ||
|
||
void setDemo() { | ||
/*SET is used when: | ||
Consider we need a container with the following features: | ||
add an element, but do not allow duples [duplicates?] - O(logN) | ||
remove elements - O(logN) | ||
get count of elements (distinct elements) - O(1) | ||
check whether elements are present in set - O(logN) | ||
*/ | ||
|
||
set<int> S; | ||
S.insert(1); | ||
S.insert(3); | ||
S.insert(2); | ||
S.insert(-2); | ||
S.insert(-10); | ||
|
||
for(int x: S) cout << x <<" ";//O(logN) //-10 -2 1 2 3 | ||
//Sorted order...no sort reqd as compared to vectors | ||
cout <<"\n"; | ||
|
||
auto itr = S.find(100); | ||
if(itr == S.end()) cout <<"Not Present\n"; | ||
else { | ||
cout << "Present\n"; | ||
cout << *itr <<"\n"; | ||
} | ||
|
||
auto itr2 = S.lower_bound(-1111); | ||
auto itr3 = S.upper_bound(2); | ||
cout << *itr2 <<" " << *itr3<<"\n"; | ||
|
||
if(itr3 == S.end()) cout << "End!"; | ||
|
||
S.erase(-2); | ||
S.erase(0);//no runtime error given. just ignores | ||
for(int x: S) cout << x <<" "; | ||
} | ||
|
||
void mapDemo() { | ||
map<int, int> A; //Mapping takes O(logN) time | ||
A[1] = 100; | ||
A[2] = 200; | ||
A[4] = 400; | ||
|
||
map<char, int> cnt; | ||
string x = "Saurav"; | ||
|
||
for(char c: x) { | ||
cnt[c]++; | ||
} | ||
cout << cnt['a'] <<"\n"; | ||
} | ||
|
||
void PowerOfStl() { | ||
/* | ||
add[10, 100] | ||
add[250, 300] | ||
give me the interval of 267 | ||
*/ | ||
set< pair<int, int> > S; | ||
S.insert({401, 450}); | ||
S.insert({10, 20}); | ||
S.insert({30,400}); | ||
S.insert({2,3}); | ||
|
||
int point = 11; | ||
|
||
auto itr = S.upper_bound({point, INT_MAX}); | ||
if(itr == S.begin()) { | ||
cout <<"Not in range\n"; | ||
return 0; | ||
} | ||
|
||
itr--; | ||
pair<int, int> current = *itr; | ||
if(current.first <= point && point <= current.second) { | ||
cout <<"Present " << current.first <<" " << current.second<<'\n'; | ||
} | ||
else { | ||
cout <<"Not Present"; | ||
} | ||
} | ||
|
||
int main() { | ||
|
||
return 0; | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,47 @@ | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
|
||
typedef long long ll; | ||
|
||
typedef pair<int, int> pii; | ||
typedef pair<ll,ll> pll; | ||
|
||
typedef vector<int> vi; | ||
typedef vector<ll> vll; | ||
typedef vector<pii> vpii; | ||
typedef vector<pll> vpll; | ||
|
||
#define FOR(i, a, b) for (int i=a; i<(b); i++) | ||
#define F0R(i, a) for (int i=0; i<(a); i++) | ||
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--) | ||
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--) | ||
|
||
#define ALL(s) (s).begin(),(s).end() | ||
#define ALLn(s,n) s,s+n | ||
#define F first | ||
#define S second | ||
#define pb push_back | ||
#define tc(t) int t; cin >> t; while(t--) | ||
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL); | ||
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; } | ||
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; } | ||
|
||
const ll MOD = 1e9 + 7; | ||
const ll MAXN = 1e6 + 7; | ||
const ll INF = INT_MAX; | ||
|
||
void solve() { | ||
|
||
} | ||
|
||
int32_t main() {_ | ||
//auto t1 = std::chrono::high_resolution_clock::now(); | ||
tc(t) | ||
solve(); | ||
//Running time check | ||
//auto t2 = chrono::high_resolution_clock::now(); | ||
//auto duration = chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count(); | ||
//cout << duration <<" ms"; | ||
} | ||
|
||
|
||
#include<bits/stdc++.h> | ||
using namespace std; | ||
|
||
typedef long long ll; | ||
|
||
typedef pair<int, int> pii; | ||
typedef pair<ll,ll> pll; | ||
|
||
typedef vector<int> vi; | ||
typedef vector<ll> vll; | ||
typedef vector<pii> vpii; | ||
typedef vector<pll> vpll; | ||
|
||
#define FOR(i, a, b) for (int i=a; i<(b); i++) | ||
#define F0R(i, a) for (int i=0; i<(a); i++) | ||
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--) | ||
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--) | ||
|
||
#define ALL(s) (s).begin(),(s).end() | ||
#define ALLn(s,n) s,s+n | ||
#define F first | ||
#define S second | ||
#define pb push_back | ||
#define tc(t) int t; cin >> t; while(t--) | ||
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL); | ||
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; } | ||
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; } | ||
|
||
const ll MOD = 1e9 + 7; | ||
const ll MAXN = 1e6 + 7; | ||
const ll INF = INT_MAX; | ||
|
||
void solve() { | ||
|
||
} | ||
|
||
int32_t main() {_ | ||
//auto t1 = std::chrono::high_resolution_clock::now(); | ||
tc(t) | ||
solve(); | ||
//Running time check | ||
//auto t2 = chrono::high_resolution_clock::now(); | ||
//auto duration = chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count(); | ||
//cout << duration <<" ms"; | ||
} | ||
|
||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.