Skip to content

Commit

Permalink
Added Lecture 1
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharsk committed Dec 25, 2018
0 parents commit 30294d8
Show file tree
Hide file tree
Showing 18 changed files with 764 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Lecture_1/extended.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ll x,y;
template<class T> T gcd(T a,T b)
{
if(a==0)
{
x=0,y=1; return b;
}
T gc=gcd(b%a,a);
T temp;
temp=x;
x=y-(b/a)*temp;
y=temp;
return gcd;
}
Binary file added Lecture_1/functors
Binary file not shown.
151 changes: 151 additions & 0 deletions Lecture_1/functors.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define pb push_back
#define f first
#define s second
#define mp make_pair
#define SZ(x) ((int)(x.size()))
#define FOI(i, a, n) for( i = int(a); i <= int(n); i++)
#define FOD(i, a, n) for( i = int(a); i >= int(n); i--)
#define IN(x, y) ((y).find(x) != (y).end())
#define ALL(t) t.begin(),t.end()
#define MSET(tabl,i) memset(tabl, i, sizeof(tabl))
#define PSET(x,y) fixed<<setprecision(y)<<lf(x)
#define DBG(c) cout << #c << " = " << c << endl;
#define RTIME ((double)clock()/(double)CLOCKS_PER_SEC)
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define Mod 1000000007

typedef long long int ll;
typedef long double lf;
typedef pair < ll, ll > pii;
typedef pair < ll, ll > pll;
typedef vector < ll > vi;
typedef vector<vi> vvi;
typedef complex<double> base;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << std::endl;
//use cerr if u want to display at the bottom
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const int N = 1e5 + 5;
const int lgN = 1e6+5;
const int te = 3e8+1;
const ll MOD = 998244353;
const lf pi = 3.141592653589793238462643383;
const ll IMAX = 1e9 + 5;
const double PI = 3.141592653589793;


template<class T>
using max_pq = priority_queue<T>;
template<class T>
using min_pq = priority_queue<T,vector<T>,greater<T>>;
template<class T>
using OST = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll x,y;
template<class T> T gcd(T a,T b){ if(a==0) {x=0,y=1; return b;}T gc=gcd(b%a,a);T temp;temp=x;x=y-(b/a)*temp;y=temp;return gc;}

//(a^x)%m
ll po(ll a, ll x,ll m){ if(x==0){return 1;}ll ans=1;ll k=1; while(k<=x) {if(x&k){ans=((ans*a)%m);} k<<=1; a*=a; a%=m; }return ans; }

ll modInverse(ll A, ll M)
{
gcd(A,M);
return (x%M+M)%M; //x may be negative
}



#include<iostream>
#include<queue>
#include<vector>
using namespace std;

class Compare{
public:
bool operator()(pair<ll,ll> a,pair<ll,ll> b){


if(a.f<b.f)
return true;

if(a.f==b.f)
{
if(a.s<b.s)
return true;
}
return false;

}

};

int main(){

//priority_queue<int> maxHeap;

priority_queue<pair<ll,ll> ,vector<pair<ll,ll> >,Compare> q; //Min Heap

ll n,i;
cin>>n;

vector<pair<ll,ll> > v(n);
FOI(i,0,n-1)
{
cin>>v[i].f;
cin>>v[i].s;
}
for(int i=0;i<n;i++){
q.push(v[i]);
}

//Remove
while(!q.empty()){
cout<<q.top().f<<" "<<q.top().s<<"\n";
q.pop();
}

return 0;
}

/*int main()
{
ll n;
cin>>n;
ll i,x;
priority_queue<c,vector<c> , functors > pq;
FOI(i,0,n-1)
{
cin>>x;
pq.push(x);
}
while(!pq.empty())
{
x=pq.top();
pq.pop();
cout<<x<<"\n";
}
return 0;
}*/

2 changes: 2 additions & 0 deletions Lecture_1/input.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
5
7 6 9 166 38
5 changes: 5 additions & 0 deletions Lecture_1/output.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
7 6
9 166
38 0
0
0
Binary file added Lecture_1/searching
Binary file not shown.
99 changes: 99 additions & 0 deletions Lecture_1/searching.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define pb push_back
#define f first
#define s second
#define mp make_pair
#define SZ(x) ((int)(x.size()))
#define FOI(i, a, n) for( i = int(a); i <= int(n); i++)
#define FOD(i, a, n) for( i = int(a); i >= int(n); i--)
#define IN(x, y) ((y).find(x) != (y).end())
#define ALL(t) t.begin(),t.end()
#define MSET(tabl,i) memset(tabl, i, sizeof(tabl))
#define PSET(x,y) fixed<<setprecision(y)<<lf(x)
#define DBG(c) cout << #c << " = " << c << endl;
#define RTIME ((double)clock()/(double)CLOCKS_PER_SEC)
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define Mod 1000000007

typedef long long int ll;
typedef long double lf;
typedef pair < ll, ll > pii;
typedef pair < ll, ll > pll;
typedef vector < ll > vi;
typedef vector<vi> vvi;
typedef complex<double> base;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cout << name << " : " << arg1 << std::endl;
//use cerr if u want to display at the bottom
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const int N = 1e5 + 5;
const int lgN = 1e6+5;
const int te = 3e8+1;
const ll MOD = 998244353;
const lf pi = 3.141592653589793238462643383;
const ll IMAX = 1e9 + 5;
const double PI = 3.141592653589793;


template<class T>
using max_pq = priority_queue<T>;
template<class T>
using min_pq = priority_queue<T,vector<T>,greater<T>>;
template<class T>
using OST = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll x,y;
template<class T> T gcd(T a,T b){ if(a==0) {x=0,y=1; return b;}T gc=gcd(b%a,a);T temp;temp=x;x=y-(b/a)*temp;y=temp;return gc;}

//(a^x)%m
ll po(ll a, ll x,ll m){ if(x==0){return 1;}ll ans=1;ll k=1; while(k<=x) {if(x&k){ans=((ans*a)%m);} k<<=1; a*=a; a%=m; }return ans; }

ll modInverse(ll A, ll M)
{
gcd(A,M);
return (x%M+M)%M; //x may be negative
}


// #include<algorithm>
int main()
{
ll n,i;
cin>>n;
vector<ll> v(n);
FOI(i,0,n-1)
cin>>v[i];

ll x;
cin>>x;
if(binary_search(v.begin(),v.end(),x))
{
cout<<"found\n";
}
// lower_bound()

vector<ll>::iterator it=upper_bound(v.begin(),v.end(),x);
int p=(it-v.begin());
cout<<p<<"\n";

return 0;
}
Binary file added Lecture_1/set
Binary file not shown.
Empty file added Lecture_1/set.cp
Empty file.
Loading

0 comments on commit 30294d8

Please sign in to comment.