Deanamic_Programming's blog

By Deanamic_Programming, history, 7 years ago, In English

Hello Codeforces, I've been trying to learn how to run a DP with the convexhull optimization and I have seen this code for a line container (KTH pdf):

struct Line {
	mutable long long k, m, p;
	bool operator<(const Line& o) const {
		return Q ? p < o.p : k < o.k;
	}
};

struct LineContainer : multiset<Line> {..}

So depending in the value of Q the comparator function will do different things, how does multiset cope with this? and how does it affect the complexity of this container?

Thank you very much for the help!

Full text and comments »

By Deanamic_Programming, history, 7 years ago, In English

Hello everyone.
On yesterday's contest I implemented a exponentiation function.

long long pow(long long n, long long k) {  
        n %= MOD;  
	if(k == 0) return 1;  
	if(k&1) return (n*(pow(n*n, k/2))%MOD)%MOD;  
	return pow(n*n, k/2) %MOD;  
}  

long long get(long long n) {  
	long long t = (n * pow(2, n-1));  
	t %= MOD;  
	return t;  
}  

Which for some reason it returning a double when the exponent is high enough.
Why could this be?

Full text and comments »