Skip to content

Commit 2105579

Browse files
committed
Initial commit
0 parents  commit 2105579

24 files changed

+2095
-0
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Ignore all
2+
*
3+
# Unignore all with extensions
4+
!*.*
5+
# Unignore all dirs
6+
!*/
7+
8+
*.txt

bit.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
// const int maxn = 1010101;
6+
7+
template <typename T, const int maxn>
8+
struct bit
9+
{
10+
T v[maxn];
11+
12+
void add(int x, const T& d)
13+
{
14+
for (int i = x; i < maxn; i += i&-i)
15+
v[i] += d;
16+
}
17+
18+
T get(int x)
19+
{
20+
T ans{};
21+
for (int i = x; i > 0; i -= i&-i)
22+
ans += v[i];
23+
return ans;
24+
}
25+
};
26+
27+
bit<long long, 1010101> b;
28+
29+
int main()
30+
{
31+
32+
}

choose.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
typedef long long ll;
6+
7+
const ll mod = 1e9 + 7;
8+
const int maxn = 1e6 + 10;
9+
10+
ll fac[maxn];
11+
ll inv[maxn];
12+
ll invfac[maxn];
13+
14+
void init()
15+
{
16+
fac[0] = 1ll;
17+
for (ll i = 1; i < maxn; i++)
18+
fac[i] = fac[i-1] * i % mod;
19+
20+
inv[1] = 1ll;
21+
for (ll i = 2; i < maxn; i++)
22+
inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;
23+
24+
invfac[0] = 1ll;
25+
for (ll i = 1; i < maxn; i++)
26+
invfac[i] = invfac[i-1] * inv[i] % mod;
27+
}
28+
29+
ll choose(int n, int k)
30+
{
31+
return (fac[n] * invfac[k]) % mod * invfac[n-k] % mod;
32+
}
33+
34+
int main()
35+
{
36+
init();
37+
38+
int n, k;
39+
cin >> n >> k;
40+
41+
cout << choose(n, k) << "\n";
42+
}

convexhulltrick.cpp

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
typedef long double ld;
6+
// double tambem funciona na maioria dos casos
7+
8+
typedef long long ll;
9+
10+
struct line
11+
{
12+
char type;
13+
// type = 0 : linha do envelope
14+
// type = 1 : query no x (interseccao das linha) no envelope
15+
16+
ld x;
17+
// x das interseccoes
18+
19+
ll m, b;
20+
// m : coeficiente angular
21+
// b : constante
22+
};
23+
24+
bool operator< (const line &a, const line &b)
25+
{
26+
if (a.type + b.type > 0) return a.x < b.x;
27+
return a.m > b.m;
28+
// para maximo inverter o sinal do ultimo return
29+
}
30+
31+
typedef set<line>::iterator sit;
32+
set<line> env;
33+
34+
bool has_prev(sit it)
35+
{
36+
return (it != env.begin());
37+
}
38+
39+
bool has_next(sit it)
40+
{
41+
return (it != env.end() and ++it != env.end());
42+
}
43+
44+
bool bad(line i, line j, line k)
45+
{
46+
return (k.b-i.b)*(i.m-j.m) < (j.b-i.b)*(i.m-k.m);
47+
// para maximo inverter o sinal
48+
}
49+
50+
ld intersect(sit i, sit j)
51+
{
52+
return (ld)(i->b-j->b)/(j->m-i->m);
53+
}
54+
55+
void calc_x(sit i)
56+
{
57+
if (has_prev(i)) {
58+
59+
line l = *i;
60+
61+
l.x = intersect(prev(i), i);
62+
env.erase(i);
63+
env.insert(l);
64+
}
65+
}
66+
67+
void add(ll m, ll b)
68+
{
69+
sit it;
70+
71+
line l = {0, 0, m, b};
72+
73+
it = env.lower_bound(l);
74+
75+
76+
// checa linhas colineares
77+
if (it != env.end() and it->m == m)
78+
{
79+
if (it->b <= b) env.erase(it);
80+
else return;
81+
}
82+
83+
env.insert(l);
84+
it = env.find(l);
85+
86+
// checa se a linha colocada deve ser removida
87+
if (has_prev(it) and has_next(it) and bad(*prev(it), *it, *next(it))) {
88+
89+
env.erase(it);
90+
return;
91+
}
92+
93+
// retira linhas da direta irrelevantes
94+
while (has_next(it) and has_next(next(it)) and bad(*it, *next(it), *next(next(it))))
95+
env.erase(next(it));
96+
97+
// retira linhas da esquerda irrelevantes
98+
while (has_prev(it) and has_prev(prev(it)) and bad(*prev(prev(it)), *prev(it), *it))
99+
env.erase(prev(it));
100+
101+
// salva o x das interseccoes dele com o anterior e o proximo
102+
if (has_next(it)) calc_x(next(it));
103+
calc_x(it);
104+
}
105+
106+
ll query(ll x)
107+
{
108+
sit it = env.upper_bound({1, (ld)x, 0, 0});
109+
it--;
110+
111+
return it->m*x + it->b;
112+
}
113+
114+
int main()
115+
{
116+
117+
}

fast_input.cpp

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
inline int scan () {
2+
int result = 0;
3+
char ch;
4+
bool minus = false;
5+
ch = getchar_unlocked();
6+
while (true) {
7+
if (ch == '-') break;
8+
if (ch >= '0' && ch <= '9') break;
9+
ch = getchar_unlocked();
10+
}
11+
if (ch == '-') minus = true; else result = ch-'0';
12+
while (true) {
13+
ch = getchar_unlocked();
14+
if (ch < '0' || ch > '9') break;
15+
result = result*10 + (ch - '0');
16+
}
17+
if (minus) return -result;
18+
return result;
19+
}
20+
21+
22+
/*------------------------------------------*/
23+
/*-----------FUDEROSAMENTE RAPIDO-----------*/
24+
/*------------------------------------------*/
25+
26+
inline int readChar();
27+
template <class T = int> inline T readInt();
28+
template <class T> inline void writeInt( T x, char end = 0 );
29+
inline void writeChar( int x );
30+
inline void writeWord( const char *s );
31+
32+
/** Read */
33+
34+
static const int buf_size = 4096;
35+
36+
inline int getChar() {
37+
static char buf[buf_size];
38+
static int len = 0, pos = 0;
39+
if (pos == len)
40+
pos = 0, len = fread(buf, 1, buf_size, stdin);
41+
if (pos == len)
42+
return -1;
43+
return buf[pos++];
44+
}
45+
46+
inline int readChar() {
47+
int c = getChar();
48+
while (c <= 32)
49+
c = getChar();
50+
return c;
51+
}
52+
53+
template <class T>
54+
inline T readInt() {
55+
char c = readChar();
56+
T x = 0;
57+
while ('0' <= c && c <= '9')
58+
x = x * 10 + c - '0', c = getChar();
59+
return x;
60+
}
61+
62+
/** Write */
63+
64+
static int write_pos = 0;
65+
static char write_buf[buf_size];
66+
67+
inline void writeChar( int x ) {
68+
if (write_pos == buf_size)
69+
fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
70+
write_buf[write_pos++] = x;
71+
}
72+
73+
template <class T>
74+
inline void writeInt( T x, char end ) {
75+
if (x < 0)
76+
writeChar('-'), x = -x;
77+
78+
char s[24];
79+
int n = 0;
80+
while (x || !n)
81+
s[n++] = '0' + x % 10, x /= 10;
82+
while (n--)
83+
writeChar(s[n]);
84+
if (end)
85+
writeChar(end);
86+
}
87+
88+
inline void writeWord( const char *s ) {
89+
while (*s)
90+
writeChar(*s++);
91+
}
92+
93+
struct Flusher {
94+
~Flusher() {
95+
if (write_pos)
96+
fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
97+
}
98+
} flusher;

gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Ignore all
2+
*
3+
# Unignore all with extensions
4+
!*.*
5+
# Unignore all dirs
6+
!*/

meldable_heap.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
struct node
6+
{
7+
int val;
8+
9+
node *l, *r;
10+
11+
node(int val)
12+
: val(val), l(nullptr), r(nullptr) {};
13+
};
14+
15+
mt19937 rd;
16+
uniform_int_distribution<int> toss(0, 1);
17+
18+
node* meld(node *&l, node *&r)
19+
{
20+
if (!l) return r;
21+
if (!r) return l;
22+
23+
if (l->val > r->val) swap(l, r);
24+
25+
if (toss(rd)) l->l = meld(l->l, r);
26+
else l->r = meld(l->r, r);
27+
28+
return l;
29+
}
30+
31+
void insert(node *&t, int x)
32+
{
33+
node *aux = new node(x);
34+
35+
t = meld(t, aux);
36+
}
37+
38+
void pop(node *&t)
39+
{
40+
if (!t) return;
41+
42+
t = meld(t->l, t->r);
43+
}
44+
45+
int min(node *t)
46+
{
47+
return t? t->val: 0;
48+
}
49+
50+
node *t = nullptr;
51+
52+
int main()
53+
{
54+
insert(t, 2);
55+
insert(t, 3);
56+
insert(t, 4);
57+
print(t);
58+
cout << "\n";
59+
cout << min(t) << "\n";
60+
pop(t);
61+
cout << min(t) << "\n";
62+
}

0 commit comments

Comments
 (0)