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
inline void fastRead(int n,std::vector<int> &input) | |
{ | |
for (int i = 0; i < n; ++i) | |
{ | |
int sign=1; | |
register char c=0; | |
while(c<'0' || c>'9') | |
{ | |
c=getchar_unlocked(); | |
if (c=='-') |
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
#include <vector> | |
#include <cstdlib> | |
#include <iostream> | |
#include <iomanip> | |
#include <string> | |
using namespace std; | |
typedef long long LL; | |
// base and base_digits must be consistent | |
const int base = 1000000000; | |
const int base_digits = 9; |
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
//recursive version | |
int64_t powMod(int64_t base,int64_t expo) | |
{ | |
if(expo==0) | |
{ | |
return 1; | |
} | |
else if(expo%2==0) | |
{ | |
int64_t ans=powMod(base,expo/2); |
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
//non recursive version | |
int64_t powMod(int64_t a,int64_t power) | |
{ | |
if (a==1) | |
{ | |
return 1; | |
} | |
int64_t count=0, answer=1; | |
std::vector<int64_t> powerDP; |
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
/** | |
* In this code we have a very large array called arr, and very large set of operations | |
* Operation #1: Increment the elements within range [i, j] with value val | |
* Operation #2: Get max element within range [i, j] | |
* Build tree: build_tree(1, 0, N-1) | |
* Update tree: update_tree(1, 0, N-1, i, j, value) | |
* Query tree: query_tree(1, 0, N-1, i, j) | |
* Actual space required by the tree = 2*2^ceil(log_2(n)) - 1 | |
*/ |
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
/** | |
* In this code we have a very large array called arr, and very large set of operations | |
* Operation #1: Increment the elements within range [i, j] with value val | |
* Operation #2: Get max element within range [i, j] | |
* Build tree: build_tree(1, 0, N-1) | |
* Update tree: update_tree(1, 0, N-1, i, j, value) | |
* Query tree: query_tree(1, 0, N-1, i, j) | |
* Actual space required by the tree = 2*2^ceil(log_2(n)) - 1 | |
*/ |
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
#include <iostream> | |
#include <string> | |
#include <limits> | |
#include <cstdio> | |
#include <cstdlib> | |
#include <cmath> | |
#include <vector> | |
#include <algorithm> | |
#include <utility> | |
#include <queue> |
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
#include <cstdio> | |
#include <iostream> | |
#include <string.h> | |
using namespace std; | |
#define l(n) 2*n | |
#define r(n) 2*n+1 |
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
--sample input | |
--dijkstra source dest [(n1,n2,e1),(n3,n4,e2)...] [(source,0)] | |
--dijkstra 1 4 [(1,2,5),(1,3,10),(2,4,100),(3,4,20)] [(1,0)] | |
--dijkstra 1 5 [(1,2,2), (2,3,1), (3,5,3), (4,5,4), (1,4,5), (1,3,8)] [(1,0)] | |
--ouput | |
-- a list of tuples with each tuple (n1,d1) representing the min. dist d1 of node n1 from source | |
inf = 100000 |