Skip to content

Instantly share code, notes, and snippets.

@lazycal
lazycal / bzoj3206.cpp
Created May 2, 2014 10:56
BZOJ3206: [Apio2013]道路费用
#include <cstdio>
#include <cstring>
#include <algorithm>
const int M = 300000 * 2 + 9,N = 100000 + 9;
struct Edge
{
int x,y,c;
}et[M],en[M],eo[M];
inline bool operator<(const Edge &lhs,const Edge &rhs){return lhs.c < rhs.c;}
int n,m,K,Map[N],p[N],num[N],fa[N],edge[N],cnt,val[N],root,d,depth[N],fa_edge[N];
@lazycal
lazycal / bzoj2303.cpp
Created April 26, 2014 10:46
BZOJ2303: [Apio2011]方格染色 并查集
#include <cstdio>
#include <cstring>
const int N = 1000000 + 9,MOD = 1000000000;
int f[N],son[N],lnk[N],nxt[N],v[N],fa[N],pre[N],n,wei[N],ec,m,k;
int tmp[100][100];
bool mark[N];
int getf(int x){return x == f[x] ? x : f[x] = getf(f[x]);}
inline void addedge(int x,int y,int z)
{
nxt[++ec] = son[x];
@lazycal
lazycal / bzoj3205.cpp
Created April 25, 2014 14:21
BZOJ3205
#include <cstdio>
#include <cstring>
#include <queue>
const int N = 509;
const int d[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
int q[N*N*4][3],h,t,f[10][10][N*N],n,W,H,to[N*N][4],p[N*N],QQ[N*N],tmp[N*N],b[N*N],Q[N*N],used[N*N],Time,pre[N*N];
char map[N][N];
bool inq[N*N];
inline int node(int x,int y){return (x - 1) * W + y;}
inline void Min(int &x,int y){if (x > y) x = y;}
@lazycal
lazycal / hdu4641.cpp
Created April 24, 2014 09:23
hdu4641 sam 左偏树
#include <cstdio>
#include <algorithm>
#include <cstring>
const int N = 200000 + 50000 + 9;
char s[N];
struct node
{
int l,r,dis,sz,v;
node(){}
node(const int _l,const int _r,const int _dis,const int _sz,const int _v):
@lazycal
lazycal / CF235C.cpp
Last active August 29, 2015 14:00
codeforces 235C - Cyclical Quest
#include <cstdio>
#include <algorithm>
#include <cstring>
const int N = 1000000 * 2 + 9;
int f[N],vis[N],Time,b[N],t[N],n;
char s[N];
int l[N],fa[N],ch[N][26],last,len,cnt;
void add(int c)
{
int p = last,np = ++cnt; last = np;
@lazycal
lazycal / bzoj2806.cpp
Created April 24, 2014 08:15
bzoj2806 sam dp
#include <cstdio>
#include <cstring>
#include <algorithm>
const int N = 1100000 * 2 + 9;
int fa[N],l[N],ch[N][3],len,last,cnt;
int f[N],q[N],n,m,a[N];
char s[N];
void add(int c)
{
int np = ++cnt,p = last; last = np;
@lazycal
lazycal / LCS2.cpp
Created April 24, 2014 07:58
SPOJ-LCS2 sam
#include <cstdio>
#include <cstring>
#include <algorithm>
const int N = 100000 * 2 + 9;
char s[N];
struct SAM
{
int l[N],fa[N],ch[N][26],cnt,len,last,b[N],t[N],mnl[N],cl[N];
void init()
{
@lazycal
lazycal / LCS.cpp
Created April 24, 2014 07:55
SPOJ-LCS sam
#include <cstdio>
#include <cstring>
#include <algorithm>
const int N = 250000 * 2 + 9;
char s[N];
struct SAM
{
int l[N],ch[N][26],fa[N],cnt,len,last;
void init(){cnt = last = 1; len = 0;memset(ch[1],0,sizeof ch[1]);}
void add(int c)
@lazycal
lazycal / SUBLEX.cpp
Last active August 29, 2015 14:00
SPOJ SUBLEX
#include <cstdio>
#include <cstring>
const int N = 90000 * 2 + 9;
char s[N];
int l[N],fa[N],ch[N][26],len,last,cnt,ec;
int f[N];
bool mark[N];
void query(int k)
{
for (int p = 1; k; )
@lazycal
lazycal / bzoj2555.cpp
Created April 24, 2014 07:30
bzoj2555,lct+sam
#include <cstdio>
#include <cstring>
#include <string>
using std::string;
const int N = 600000 * 2 + 9;
int mask;
char s[3000000 + 9];
string chars;
void gets(int mask)
{