This file contains hidden or 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 <algorithm> | |
#include <cstring> | |
#include <string> | |
#include <cstdio> | |
#include <stack> | |
#include <vector> | |
#include <cmath> | |
#include <unordered_map> | |
#include <utility> |
This file contains hidden or 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
#define MAXBIT 1000000 | |
#define lowbit(x) (x & -x) | |
struct BIT { | |
int bit[MAXBIT]; | |
int M; | |
void clear(int M) { | |
memset(bit, 0, sizeof(bit)); | |
this->M = M; |
This file contains hidden or 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
#!/bin/bash | |
while : | |
do | |
bypy -v download todownload . | |
sleep 10 | |
done |
This file contains hidden or 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
import heapq | |
# min-heap | |
class PriorityQueue: | |
def __init__(self): | |
self._queue = [] | |
self._index = 0 | |
def push(self, item, priority): | |
heapq.heappush(self._queue, (priority, self._index, item)) # -priority if max-heap |
This file contains hidden or 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 <cstdio> | |
#include <cstring> | |
#include <algorithm> | |
#include <queue> | |
using namespace std; | |
const int MAXN = 100; | |
const int INF = 100000000; |
This file contains hidden or 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 <cstring> | |
#include <algorithm> | |
#include <vector> | |
#include <queue> | |
using namespace std; | |
#define MAXN 1000+1 | |
#define MAXE 2*10000 |
This file contains hidden or 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 <cstring> | |
#include <algorithm> | |
using namespace std; | |
#define MAXN 1000+1 | |
#define INF 100000000 | |
int N; |
This file contains hidden or 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
#define MAXU 100000 | |
struct UnionFind { | |
int f[MAXU]; | |
int rank[MAXU]; | |
void clear() { | |
memset(f, -1, sizeof(f)); | |
memset(rank, 0, sizeof(rank)); | |
} |
This file contains hidden or 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
// return <gcd(a, b), <x, y>> such that ax + by = gcd(a, b) | |
pair< int, pair<int, int> > extended_euclidean(int a, int b) { | |
if (b == 0) return make_pair(a, make_pair(1, 0)); | |
pair< int, pair<int, int> > next = extended_euclidean(b, a % b); | |
int y = next.second.first, x = next.second.second; | |
y = y - (a / b) * x; | |
return make_pair(next.first, make_pair(x, y)); | |
} | |
// p is prime, return b such that a * b = 1 (mod p) |
This file contains hidden or 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
// return x^y mod p | |
int repeated_squaring(int x, int y, int p) { | |
if (y <= 0) return 1; | |
int ret = 1; | |
for (int base = x; y; base = (base * base) % p, y >>= 1) | |
if ((y & 1) == 1) ret = (ret * base) % p; | |
return ret; | |
} |
NewerOlder