bzoj3864.cc

#include #include #include using namespace std; const int mod = 1e9 + 7; const int maxs = 17; const int maxst = (1 « 15) + 3; const char deoxynucleotide[5] = “AGCT”; #define mInc(a,b) { a += b; if (a >= mod) a -= mod; } int n, m, f[2][maxst], ans[maxs]; int trv[maxst][4]; char s[maxs]; int getTrans(int i, int j) { static int fc[maxs], fd[maxs]; fc[0] = fd[0] = 0; for (int k = 0; k < n; ++ k) fc[k + 1] = fc[k] + ((i » k) & 1); for (int k = 1; k <= n; ++ k) { if (s[k] == deoxynucleotide[j]) fd[k] = fc[k - 1] + 1; else if (fc[k] > fd[k - 1]) fd[k] = fc[k]; else fd[k] = fd[k - 1]; } int sn(0); for (int k = 0; k < n; ++ k) sn |= (fd[k + 1] - fd[k]) « k; return sn; }...

May 24, 2015 · 2 min · laekov

bzoj2555.cc

#include #include #include using namespace std; #define _l (long long int) struct node { int le, sz; node *tr[27], *pt; node() { memset(tr, 0, sizeof(tr)); pt = 0; sz = 0; } }; const int maxn = 1200009; const int maxl = 4000000; char g[maxl]; int n, mask; node nbuf_arr[maxn], *nbuf(nbuf_arr), *srt, *scur; void decodeStr(char* a, int mask) { int l(strlen(a)); for (int i = 0; i < l; ++ i) { mask = (_l mask * 131 + i) % l; swap(a[i], a[mask]); } }...

May 21, 2015 · 2 min · laekov

bzoj3542.cc

#include #include #include #include using namespace std; typedef long long dint; #ifdef WIN32 #define lld “%I64d” #else #define lld “%lld” #endif #define _l (long long int) struct seg { int m, a, c; seg *ch[2]; seg() { ch[0] = ch[1] = 0, m = a = c = 0; } }; #define sgtRoot 1, n + 1 #define mp ((pl+pr)»1) #define lson pl, mp #define rson mp, pr #define checkNeg(x) { if (x < 0) x += mod; } #define mInc(x,y) { x += y; if (x >= mod) x -= mod; }...

May 21, 2015 · 3 min · laekov

bzoj2962.cc

#include #include #include using namespace std; #define _l (long long int) const int maxc = 23; const int maxn = 50009; const int mod = 19940417; struct dat { int a[maxc], t; inline dat() { memset(a, 0, sizeof(a)); a[0] = 1; t = 0; } inline int& operator[](const int& x) { return a[x]; } inline int operator[](const int& x) const { return a[x]; } void add(int); void rev(); }; struct seg { int l, r, rv, a; dat d; seg *ch[2]; inline void update(); inline void catTag(int ta, int tr) { if (tr) { a = (mod - a) % mod; d....

May 18, 2015 · 4 min · laekov

bzoj4066.cc

#include #include #include using namespace std; #define upMax(a,b) { if (a < b) a = b; } #define upMin(a,b) { if (a > b) a = b; } struct kdnode { int p[2], a[2][2], v, s; kdnode *ch[2]; inline void update() { a[0][0] = a[1][0] = p[0]; a[0][1] = a[1][1] = p[1]; s = v; if (ch[0]) { upMin(a[0][0], ch[0]-> a[0][0]); upMin(a[0][1], ch[0]-> a[0][1]); upMax(a[1][0], ch[0]-> a[1][0]); upMax(a[1][1], ch[0]-> a[1][1]); s += ch[0]-> s; } if (ch[1]) { upMin(a[0][0], ch[1]-> a[0][0]); upMin(a[0][1], ch[1]-> a[0][1]); upMax(a[1][0], ch[1]-> a[1][0]); upMax(a[1][1], ch[1]-> a[1][1]); s += ch[1]-> s; } } };...

May 14, 2015 · 2 min · laekov

bzoj1225.java

import java.util.; import java.math.; class Main { static int n, m, a[], tp, pn[]; static BigInteger f[][]; static boolean pr[], fl[][]; static void pre() { int maxm = 30; pr = new boolean[maxm]; pn = new int[maxm]; pn[0] = 1; tp = 1; for (int i = 0; i < maxm; ++ i) pr[i] = false; for (int i = 2; i < maxm; ++ i) { if (!pr[i]) pn[tp ++] = i; for (int j = 1; j < tp && i * pn[j] < maxm; ++ j) { pr[i * pn[j]] = true; if (i % pn[j] == 0) break; } } } public static void main(String args[]) { Scanner cin = new Scanner(System....

May 14, 2015 · 2 min · laekov

bzoj4071.cc

#include #include #include #include #include using namespace std; typedef long long dint; #ifdef WIN32 #define lld “%I64d” #else #define lld “%lld” #endif #define _l (long long int) struct range { int l, r; }; inline bool operator <(const range& a, const range& b) { return a. l + a. r < b. l + b. r; } struct bridge { static const int maxn = 200009; int ha[maxn], hb[maxn], ta, tb; dint sa, sb; inline void clr() { ta = tb = sa = sb = 0; } bridge() { clr(); } void balance() { while (ta > tb + 1) { hb[tb] = -ha[0]; sa -= ha[0]; sb += hb[tb]; pop_heap(ha, ha + ta –); push_heap(hb, hb + ++ tb); } while (ta < tb + 1) { ha[ta] = -hb[0]; sb -= hb[0]; sa += ha[ta]; pop_heap(hb, hb + tb –); push_heap(ha, ha + ++ ta); } } inline void ins(int x) { if (x <= ha[0]) { sa += x; ha[ta] = x; push_heap(ha, ha + ++ ta); } else { sb -= x; hb[tb] = -x; push_heap(hb, hb + ++ tb); } balance(); } inline dint qry() { return _l ha[0] * (ta - tb) - sa - sb; } };...

May 13, 2015 · 3 min · laekov

bzoj4070.cc

#include #include #include #include #include using namespace std; struct edge { int t, v; edge* next; }; const int maxn = 30009; const int bsz = 80; const int maxb = 83; const int maxnd = maxn * maxb; const int ebsz = 1000001; int n, m, st, te, d[maxnd], tnid, nid[maxb][maxn]; edge *head[maxnd]; inline void addEdge(int u, int v, int w) { static edge* ebuf; static int cnt(0); if (!...

May 13, 2015 · 2 min · laekov

bzoj4069.cc

#include #include #include #include using namespace std; typedef long long dint; #ifdef WIN32 #define lld “%I64d” #else #define lld “%lld” #endif #define _l (long long int) #define lpow2(x) (1ll«(x)) const int maxn = 2009; const int maxb = 43; dint a[maxn], ans; int n, ml, mh, d[maxn]; bitset f[maxn]; int bitDP(int bo) { if (ml > 1) { memset(f, 0, sizeof(f)); f[0][0] = 1; for (int i = 1; i <= n; ++ i) { f[i - 1] «= 1; for (int j = 0; j < i; ++ j) { dint vd(a[i] - a[j]); if (((vd & ans) » bo) !...

May 13, 2015 · 2 min · laekov

bzoj2111.cc

#include #include #include using namespace std; #define _l (long long int) const int maxn = 1000009; int n, mod, sz[maxn]; int modPow(int a, int x) { int s(1); for (; x; x »= 1, a = _l a * a % mod) if (x & 1) s = _l s * a % mod; return s; } struct modInt { int a, b; modInt() {} modInt(int ao, int bo) { a = ao, b = bo; } modInt(int xo) { a = xo; for (b = 0; a % mod == 0; a /= mod, ++ b); a %= mod; } inline void print() { if (b) puts(“0”); else printf("%d\n", a); } }; inline modInt operator *(const modInt& a, const modInt& b) { return modInt(_l a....

May 13, 2015 · 2 min · laekov