bzoj3265.cc

#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) const int maxn = 1003; const int maxm = 10003; const dint dinf = 0x3f3f3f3f3f3f3f3fll; int n, m, ne[maxn]; dint a[maxm][maxn]; void pivot(int e, int p) { int fr(n + 1); for (int i = n; i >= 0; – i) if (a[p][i]) { ne[fr] = i; fr = i; } ne[fr] = -1; a[p][e] = -1; for (int i = 0; i <= m; ++ i) if (i !...

June 16, 2015 · 2 min · laekov

bzoj2589.cc

#include #include #include using namespace std; struct seg { int v; seg *ch[2]; }; struct edge { int t; edge *ne; }; const int maxn = 40003; const int leafc = 20; const int maxk = leafc + 1;; const int maxl = 17; const int albsz = 1000003; int n, m, t, w[maxn], dl[maxn], df[maxn], fk[maxn], deg[maxn]; int tlf, lf[maxk], la[maxk][maxn], d[maxk][maxn], fr[maxk][maxn]; int dfb[maxk][maxn], dfe[maxk][maxn], dfn; int tvis, vis[maxn], vo[maxn], tv; seg *rt[maxk][maxn], *rl[maxk][maxn]; edge ebuf_arr[maxn « 1], *ebuf(ebuf_arr), *head[maxn];...

June 12, 2015 · 6 min · laekov

rshcr5count.cc

#include #include #include using namespace std; #define _l (long long int) const int maxn = 103; const int mod = 1e9 + 7; 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; } int fac[maxn], finv[maxn], vinv[maxn]; int n, m, k, f[maxn], c[maxn];...

June 11, 2015 · 3 min · laekov

bzoj1228.cc

#include #include #include using namespace std; int calc(int i, int j, int d) { if ((i & 1) && (j & 1)) return d; else return calc((i + 1) » 1, (j + 1) » 1, d + 1); } int main() { #ifdef LAEKOV_LOCAL freopen(".in", “r”, stdin); #endif int t; scanf("%d", &t); while (t --) { int n, s(0); scanf("%d", &n); for (int i = 0; i < n; i += 2) { int a, b; scanf("%d%d", &a, &b); s ^= calc(a, b, 0); } puts(s ?...

June 11, 2015 · 1 min · laekov

bzoj4127.cc

#include #include #include #include using namespace std; const int buf_len = 45678; char buf[buf_len], *bufb(buf), *bufe(buf + 1); #define readBuf() { if (++ bufb == bufe) bufe = (bufb = buf) + fread(buf, 1, sizeof(buf), stdin); } #define readInt(x) { register int s(0), neg(0); while (!isdigit(*bufb)) { if (*bufb == ‘-’) neg = 1; readBuf(); } do { s = s * 10 + *bufb - 48; readBuf(); } while (isdigit(*bufb)); if (neg) x = -s; else x = s; }...

June 10, 2015 · 5 min · laekov

bzoj4004.cc

#include #include #include using namespace std; #define _l (long long int) const int maxn = 503; const int hmod = 1111111121; int n, m, a[maxn][maxn], b[maxn][maxn], rb[maxn][maxn], c[maxn], o[maxn]; int t, s; inline bool cCmp(const int& a, const int& b) { return c[a] < c[b]; } void pr() { for (int i = 0; i < t; ++ i, putchar(10)) for (int j = 0; j < m; ++ j) fprintf(stderr, “%5d”, b[i][j]); }...

June 9, 2015 · 2 min · laekov

hdu5267.cc

#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 edge { int t; edge *ne; }; struct seg { int l, r, rv, s; seg *ch[2]; }; const int maxn = 10003; const int maxl = 17; int n, m, a[maxn], ca[maxn]; int dv[maxn], sz[maxl][maxn], dfb[maxl][maxn], dfe[maxl][maxn], dsr[maxl][maxn], df[maxn]; int cp[maxn], cv[maxn], cb[maxn]; dint ans[maxn], cans; dint tp[maxn], xpc[maxn]; int tvis, vis[maxn]; edge ebuf_arr[maxn « 1], *ebuf, *head[maxn]; seg sbuf_arr[maxn * maxl * 3], *sbuf, *rt[maxn];...

June 7, 2015 · 5 min · laekov

bzoj4123.cc

#include #include #include using namespace std; const int maxn = 1000003; int n, l, a[maxn], b[maxn], s; int q[maxn], hd, tl; int main() { #ifdef LAEKOV_LOCAL freopen(".in", “r”, stdin); #endif scanf("%d", &n); for (int i = 1; i <= n; ++ i) scanf("%d", a + i); for (int i = n + 1; i <= n * 2; ++ i) a[i] = a[i - n]; a[0] = 0; for (int i = 1; i <= n * 2; ++ i) a[i] += a[i - 1]; l = (n + 1) >> 1; for (int i = 1; i + l - 1 <= n * 2; ++ i) b[i] = a[i + l - 1] - a[i - 1]; s = 0; hd = tl = 0; for (int i = 1; i + l - 1 <= n * 2; ++ i) { while (hd < tl && b[q[tl - 1]] >= b[i]) -- tl; q[tl ++] = i; while (hd < tl && q[hd] + l <= i) ++ hd; if (i >= l) s = max(s, b[q[hd]]); } printf("%d\n", s); }

June 4, 2015 · 1 min · laekov

bzoj2877.cc

#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 checkNeg(x) { if (x < 0) x = -x; } dint gcd(dint a, dint b) { checkNeg(a); checkNeg(b); while (a) { register dint c(b % a); b = a; a = c; } return b; } #define md ((p->l+p->r)»1) #define mdp(p) ((p->l+p->r)»1) #define zp(x,y) ((x)*m+(y))...

May 28, 2015 · 6 min · laekov

ovoo.cc

#include #include #include using namespace std; typedef long long dint; #define _l (long long int) typedef pair <dint, int> dpr; struct node { int v, t, sz; node* ch[2]; }; struct edge { int t, v; edge *next; }; const int maxn = 100009; const int maxh = 200009; const int maxnd = maxn * 43; const int mod = (1 « 23) * 7 * 17 + 1; edge ebuf_arr[maxn], *ebuf(ebuf_arr), *head[maxn]; node nbuf_arr[maxnd], *nbuf(nbuf_arr), *nrt[maxn], *srt[maxn]; int n, k, ts, th; dint sans[maxn]; dpr hp[maxh];...

May 28, 2015 · 3 min · laekov