Skip to content

Instantly share code, notes, and snippets.

@arafatkatze
Created August 27, 2016 08:20
Show Gist options
  • Save arafatkatze/568c88c4891d9c68d27e33b7244f763b to your computer and use it in GitHub Desktop.
Save arafatkatze/568c88c4891d9c68d27e33b7244f763b to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
#define inf INFINITY
/*
const clock_t begin_time = clock();
// do something
cout << float( clock () - begin_time ) / CLOCKS_PER_SEC;
Read from a file
freopen("input.in","r",stdin);
freopen("output.out","w",stdout);
*/
void r(){};
template<typename T,typename... Args>
void r(T &a, Args&... args) { cin>>a ; r(args...); }
void p(){cout <<"\n";};
template<typename T,typename... Args>
void p(T &a, Args&... args) { cout << a << " " ; p(args...); }
template<class T> T gcd(T a, T b) { return a ? gcd (b % a, a) : b; }
template<class T> T lcm(T a, T b) { return ((a*b)/gcd (b % a, a)); }
template<class T> T binpow(T number, T power) { T result = 1; while(power) { if(power & 1) result *= number; number *= number;power /= 2;}return result;}
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
// Useful container manipulation / traversal macros
#define fa(i, begin, end) for (auto i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define fe(v, c) for(auto v :c)
#define all(a) a.begin(), a.end()
#define in(a,b) ( (b).find(a) != (b).end())
#define pb emplace_back // this will work almost always
#define fill(a,v) memset(a, v, sizeof a)
#define sz(a) ((auto)(a.size()))
#define mt make_tuple
// comparision Guys
#define maX(a,b) ( (a) > (b) ? (a) : (b))
#define abs(a) ( (a) > (0) ? (a) : (-a))
#define miN(a,b) ( (a) < (b) ? (a) : (b))
#define checkbit(n,b) ( (n >> b) & 1)
#define DREP(a) sort(all(a)); a.erase(unique(all(a)),a.end()) //deletes repeat
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
// The bit standard guys
#define bit(x,i) (x&(1<<i)) //select the bit of position i of x
#define lowbit(x) ((x)&((x)^((x)-1))) //get the lowest bit of x
#define higbit(x) (1 << ( auto) log2(x) )
#define ft first
#define sd second
#define pq priority_queue
// the data types
#define ll long long
#define st string
#define ld long double
int n;
class segtree{
public:
int *tree, *array, sz;
void initialize(int *arr, int n){ // you can't measure size of a passed pointer
sz = n;
array = new int[n];
tree = new int[4*n];
fa(i,0,n) array[i] = arr[i];
fa(i,0,4*n) tree[i] = 0;
build(1);
}
void build(int id, int l = 0, int r = n){
if(r-l < 2) {tree[id] = array[l]; return;}
int mid = (l+r)/2;
build(2*id,l,mid);build(2*id+1,mid,r);
tree[id] = tree[2*id] + tree[2*id+1];
};
};
class S{
public:
int a, b, c;
S(int n1, int n2, int n3): a(n1), b(n2), c(n3) {};
inline bool operator<(const class S other) const {return a > other.a;};
};
struct comp {
bool operator()(const tuple<char, int , string> a, const tuple<char, int , string> b)
const {
return get<1>(a) > get<1>(b);
}
};
map<tuple<char, int , string>, double, comp> v;
set<tuple<char, int , string>, comp> vrew;
int main()
{
segtree tree;
int arr[] = {2,3,4};
tree.initialize(arr,3);
n = 3;
priority_queue<S > Q;
Q.push(S(2,6,4));Q.push(S(9,12,10));Q.push(S(1,7,8));Q.push(S(3,5,7));
int i;
for(i=0;i<4;i++)
{
S top=Q.top();Q.pop();
printf("%d %d %d\n",top.a,top.b,top.c);
};
v[mt('a',534,"train")] = 343.325;
v[mt('b',143,"ring")] = 123.325;
v[mt('c',642,"string")] = 623.325;
fe(i,v)p(get<0>(i.ft), get<1>(i.ft), get<2>(i.ft), i.sd);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment