3
28
2016
0

[bzoj]3551: [ONTAK2010]Peaks加强版

传送门-->http://www.lydsy.com/JudgeOnline/problem.php?id=3551

搞了一上午的系统总算是弄好了,颓

经典题,很早就想做了,正巧要给初三爷讲并$(zhu)$查$(xi)$集$(shu)$,然后发现这道题可以放作业题_(:зゝ∠)_

先是看了$Claris$的题解,瞬间变成猪,太神了和我的逗比做法完全不同

Category: bzoj | Tags: 重构 DFS序 主席树
3
20
2016
0

[bzoj]3772: 精神污染

传送门-->http://www.lydsy.com/JudgeOnline/problem.php?id=3772

坑没怎么填, 写篇题解 凑凑数

促使我写这题题解的动力是网上题解都是什么$dfs$序+主席树,看到都忍不住笑出声

Category: bzoj | Tags: DFS序 扫描线
3
14
2016
0

[坑]PA2014 Final

推了君彼彼后感觉精神有点恍惚,做点PA final提提神

诶以前居然做过两题_(:зゝ∠)_

现在做了几题:  2/6

$3.16$ $qiancl:$我已经方了

Category: bzoj | Tags:
2
25
2016
0

[bzoj]3944: Sum

传送门-->http://www.lydsy.com/JudgeOnline/problem.php?id=3944

本来想留着给初三爷出题。。然而都没几个会欧拉函数的,所以就写个题解等我忘了看……

最开始给我灵感的是codevs月赛的一道题,它的一个子问题是求

$\sum_{i=1}^{n}\sigma \left ( i \right )$,其中$\sigma \left ( n \right )= \sum_{d|n}d$

介个东西怎么做呢,当然并不能直接做喽,当时比利直接秒出%%%,he said :"This is a foolish thing." 他是考虑每个数对答案的贡献,我还是暴力推了推公式

$\sum_{i=1}^{n} \sigma \left ( i \right )= \sum_{i=1}^{n}\sum_{j=1}^{n}[j|i]\cdot j= \sum_{i=1}^{n}i\cdot [\frac{n}{i}]$

2
25
2016
0

[bzoj]3545: [ONTAK2010]Peaks

传送门-->http://www.lydsy.com/JudgeOnline/problem.php?id=3545

sb题

离线做,把边和询问都排序,然后一条条加边,维护连通块,于是这就是个平衡树合并裸题。。然而只有我这种都比被卡了辣么久- =

一发5s,感觉跑好慢……,一看榜,发现rank3而且代码也很短2333

#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
#define nc() getchar()
inline int read(){
	int x=0;char ch=nc();for(;ch<'0'||ch>'9';ch=nc());
	for(;ch<='9'&&ch>='0';x=x*10+ch-48,ch=nc());return x;
}
#define N 100010
int i,j,k,m,n,x,y,Q,h[N],cnt,fa[N],pp[N],ans[N*5],top;
struct edge{
	int x,y,z;
	inline void in(){x=read(),y=read(),z=read();}
	bool operator <(const edge&a)const{return z<a.z;}	
}e[N*5];
struct ques{
	int v,x,k,id;
	inline void in(){v=read(),x=read(),k=read(),id=i;}
	bool operator <(const ques&a)const{return x<a.x;}
}q[N*5];
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
struct node{
	node*ch[2];int r,sz,h,id;inline void up(){sz=ch[0]->sz+ch[1]->sz+1;}
	inline int cmp(int x)const{return x>h;}
}C[N],Null,*null=&Null;
inline void rotate(node*&o,int d){node*k=o->ch[d^1];o->ch[d^1]=k->ch[d],k->ch[d]=o,k->sz=o->sz,o->up(),o=k;}
int insert(node*&o,int x,int id){
	if(o==null)o=&C[id],o->id=id,o->h=x,o->ch[0]=o->ch[1]=null,o->sz=1,o->r=rand();
	else{
		int d=o->cmp(x);++o->sz;
		insert(o->ch[d],x,id);if(o->ch[d]->r>o->r)rotate(o,d^1);
	}
	return o->id;
}
void Add(node*x,node*y){if(x==null)return;Add(x->ch[0],y),Add(x->ch[1],y),top=insert(y=&(C[top]),x->h,x->id);}
inline void link(int u,int v){
	if(u==v)return;
	if((C+u)->sz<(C+v)->sz)swap(u,v);
	fa[v]=u,top=pp[u],Add(C+pp[v],C+pp[u]),pp[u]=top;
}
int kth(node*o,int k){
	if(o==null||k<=0||k>o->sz)return 0x7f7f7f7f;
	if(k<=o->ch[0]->sz)return kth(o->ch[0],k);
	if(k>o->ch[0]->sz+1)return kth(o->ch[1],k-o->ch[0]->sz-1);
	return o->h;
}
int main(){
	for(n=read(),m=read(),Q=read(),i=1;i<=n;++i)h[i]=read(),fa[i]=i,pp[i]=i,(C+i)->id=i,(C+i)->h=h[i],(C+i)->sz=1,(C+i)->ch[0]=(C+i)->ch[1]=null,(C+i)->r=rand();
	for(i=1;i<=m;++i)e[i].in();for(i=1;i<=Q;++i)q[i].in();
	for(cnt=1,sort(e+1,e+m+1),sort(q+1,q+Q+1),i=1;i<=Q;++i){
		while(e[cnt].z<=q[i].x&&cnt<=m)link(find(e[cnt].x),find(e[cnt].y)),++cnt;
		ans[q[i].id]=kth(C+pp[find(q[i].v)],(C+pp[find(q[i].v)])->sz-q[i].k+1);
	}
	for(i=1;i<=Q;++i)if(ans[i]==0x7f7f7f7f)puts("-1");else printf("%d\n",ans[i]);
}

Category: bzoj | Tags: 平衡树 启发式合并
2
23
2016
2

(持续更新)[bzoj][黑科技]一些题

有人问我为什么有些题那么快_(:зゝ∠)_

所以我来解释一下我加的黑科技,题目编号是乱的= =,有想要我解释的题请评论


首先是fastio,bzoj上有了这个就可以轻易rank1吧。。

#define S 100000
char bf[S],*p1=bf,*p2=bf;
#define nc() (p1==p2&&(p2=(p1=bf)+fread(bf,1,S,stdin),p2==p1)?-1:*p1++)
inline int read(){
	int x=0;char ch=nc();for(;ch<'0'||ch>'9';ch=nc());
	for(;ch<='9'&&ch>='0';x=x*10+ch-48,ch=nc());return x;
}
char pf[S],*o1=pf,*o2=pf+S;
#define ot(x) (o1==o2?fwrite(pf,1,S,stdout),*(o1=pf)++=x:*o1++=x)
inline void print(int x){static char s[15],*b;b=s;if(!x)*b++=48;for(;x;*b++=x%10+48,x/=10);for(;b--!=s;ot(*b));}
fwrite(pf,1,o1-pf,stdout);
//for(i=1;i<=m;++i)print(ans[i]),ot('\n');

所以在这里我就不解释用fastio艹上去的题了

Category: bzoj | Tags: 黑科技

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com