forked from tusharsk/Coding-Blocks-CP-Dwarka-Dec-2018
-
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
0 parents
commit 30294d8
Showing
18 changed files
with
764 additions
and
0 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,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 not shown.
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,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; | ||
}*/ | ||
|
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,2 @@ | ||
5 | ||
7 6 9 166 38 |
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,5 @@ | ||
7 6 | ||
9 166 | ||
38 0 | ||
0 | ||
0 |
Binary file not shown.
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,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 not shown.
Empty file.
Oops, something went wrong.