//Copyright(c)2016 liuchenrui
//Scoi 2016
#include
#include
#include
#include
#include
#include
#include
#define LL long long
using namespace std;
char s[510010];
int t[510010][26],cnt;
int f[510010],n,q[510000];
int *tmp[510010],tin[510010];
LL ans;int tot;int p[510010];
struct node{
int id,v;
friend bool operator < (const node &a,const node &b){
return a.v
3的做法:每层处理经过当前处理点的询问,每次bfs一遍,然后带着基合并下一个节点的基,每次询问暴力合并两个bfs到的节点的基
这里贴2的代码
//Copyright(c)2016 liuchenrui
#include
#define LL long long
using namespace std;
template
inline void splay(T &v){
v=0;char c=0;
while(c<'0' || c>'9')c=getchar();
while(c>='0' && c<='9'){v=(v<<3)+(v<<1)+c-'0';c=getchar();}
}
struct Edge{
int to,next;
}edge[40010];
int first[20010],size;
void addedge(int x,int y){
size++;
edge[size].to=y;
edge[size].next=first[x];
first[x]=size;
}
LL ji[20010][16][61];
int t[20010][16],deep[20010];
int fa[20010][16];
int swam(int x,int f){
for(int i=15;i>=0;i--){
if(1<=0;i--){
if(fa[x][i]!=fa[y][i]){
x=fa[x][i],y=fa[y][i];
}
}
return fa[x][0];
}
LL s[40005],ans1[40005],ans2[40005],ans[40005];
int at1,at2,at;
int uni(LL *a,int &ta,LL *b,int tb,LL *c,int tc){
int cnt=0;
for(int i=1;i<=tb;i++){
s[++cnt]=b[i];
}
for(int i=1;i<=tc;i++){
s[++cnt]=c[i];
}
int f=0;
for(LL j=1LL<<60;j;j>>=1){
bool flag=false;
for(int i=f+1;i<=cnt;i++){
if(s[i]&j){
swap(s[i],s[++f]);
flag=true;break;
}
}
if(!flag)continue;
for(int i=1;i<=cnt;i++){
if(i==f)continue;
if(s[i]&j)s[i]^=s[f];
}
}
ta=f;
for(int i=1;i<=f;i++){
a[i]=s[i];
}
}
void dfs(int now,int F){
fa[now][0]=F;deep[now]=deep[F]+1;
for(int i=1;i<=15;i++){
fa[now][i]=fa[fa[now][i-1]][i-1];
}
for(int i=1;i<=15;i++){
uni(ji[now][i],t[now][i],ji[now][i-1],t[now][i-1],ji[fa[now][i-1]][i-1],t[fa[now][i-1]][i-1]);
}
for(int u=first[now];u;u=edge[u].next){
if(edge[u].to!=F){
dfs(edge[u].to,now);
}
}
}
int Log[20010],n,q;
int main(){
splay(n),splay(q);
for(int i=1;i<=n;i++){
splay(ji[i][0][++t[i][0]]);
}
for(int i=1;i
update:更新了更快的代码 2016.05.17
//Copyright(c)2016 liuchenrui
#include
#define LL long long
using namespace std;
template
inline void splay(T&v){
v=0;char c=0;
while(c<'0'||c>'9')c=getchar();
while(c>='0'&&c<='9'){v=(v<<3)+(v<<1)+c-'0';c=getchar();}
}
struct Edge{
int to,next;
}
edge[40010];
int first[20010],size,mxs;
void addedge(int x,int y){
size++;
edge[size].to=y;
edge[size].next=first[x];
first[x]=size;
}
LL *ji[20010][16];
int t[20010][16],deep[20010];
int fa[20010][16];
int swam(int x,int f){
for(int i=15;i>=0;i--){
if(1<=0;i--){
if(fa[x][i]!=fa[y][i]){
x=fa[x][i],y=fa[y][i];
}
}
return fa[x][0];
}
LL s[40005],ans[40005];
int at1,at2,at;
int uni2(LL*a,int&ta,LL*b,int tb){
int cnt=0;
for(int i=1;i<=tb;i++){
a[++ta]=b[i];
}
}
int uni(LL*&a,int&ta,LL*b,int tb,LL*c,int tc){
int cnt=0;
for(int i=1;i<=tb;i++){
s[++cnt]=b[i];
}
for(int i=1;i<=tc;i++){
s[++cnt]=c[i];
}
int f=0;
for(LL j=1LL<>=1){
bool flag=false;
for(int i=f+1;i<=cnt;i++){
if(s[i]&j){
swap(s[i],s[++f]);
flag=true;
break;
}
}
if(!flag)continue;
for(int i=1;i<=cnt;i++){
if(i==f)continue;
if(s[i]&j)s[i]^=s[f];
}
}
a=new LL[f+2];ta=f;
for(int i=1;i<=f;i++){
a[i]=s[i];
}
}
int calc(LL*a,int&ta){
int f=0;
for(LL j=1LL<>=1){
bool flag=false;
for(int i=f+1;i<=ta;i++){
if(a[i]&j){
swap(a[i],a[++f]);
flag=true;
break;
}
}
if(!flag)continue;
for(int i=1;i<=ta;i++){
if(i==f)continue;
if(a[i]&j)a[i]^=a[f];
}
}
ta=f;
}
void dfs(int now,int F){
fa[now][0]=F;
deep[now]=deep[F]+1;
for(int i=1;i<=15;i++){
fa[now][i]=fa[fa[now][i-1]][i-1];
}
for(int i=1;i<=15;i++){
if(fa[now][i-1]){
uni(ji[now][i],t[now][i],ji[now][i-1],t[now][i-1],ji[fa[now][i-1]][i-1],t[fa[now][i-1]][i-1]);
}
}
for(int u=first[now];u;u=edge[u].next){
if(edge[u].to!=F){
dfs(edge[u].to,now);
}
}
}
int Log[20010],n,q;
int main(){
freopen("xxx.in","r",stdin);
splay(n),splay(q);
for(int i=1;i<=n;i++){
LL x;splay(x);ji[i][0]=new LL[2];
ji[i][0][++t[i][0]]=x;
while(1LL<60)mxs=60;
for(int i=1;i
//Copyright(c)2016 liuchenrui
//Scoi 2016
#include
#include
#include
#include
#include
#include
#include
#define LL long long
#define mod 1000000007
using namespace std;
void read(int &v){
v=0;char c='a';bool p=0;
for(c=getchar();c>'9'||c<'0';c=getchar()){
if(c=='-')p=1;
}
for(;c>='0'&&c<='9';c=getchar()){
v=v*10+c-'0';
}
if(p)v=-v;
}
int a,A,b,B,n,m;
int getnum(int i,int j){
int x=(i-1)*20+j;
if(x>=n*20)x=n*20;
return x;
}
int f[100010][20];
int fa[2500010];
int getfa(int v){
if(fa[v]==v)return v;
else return fa[v]=getfa(fa[v]);
}
void uni(int x,int y){
//cerr<y)swap(x,y);
fa[y]=x;
}
void cal(int v){
int x=v/20+1,y=v%20;
a=getnum(x,y-1);
b=getnum(x+(1<<(y-1)),y-1);
return;
}
void cal2(int v){
int x=v/20+1,y=v%20;
A=getnum(x,y-1);
B=getnum(x+(1<<(y-1)),y-1);
return;
}
int main(){
read(n),read(m);
for(int i=1;i<=2000001;i++)fa[i]=i;
for(int i=1;i<=m;i++){
int l,r,L,R;
read(l),read(r),read(L),read(R);
for(int j=19;j>=0;j--){
if(l+(1<=1;j--){
for(int i=1;i<=n;i++){
int x=getfa(getnum(i,j));
cal(x);cal2(getnum(i,j));
uni(a,A),uni(b,B);
}
}
int ans=1;
for(int i=1;i<=n;i++){
if(getfa(getnum(i,0))==getnum(i,0)){
if(i==1)ans=(LL)ans*9%mod;
else ans=(LL)ans*10%mod;
}
}
cout<
//Copyright(c)2016 liuchenrui
//Scoi 2016
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long long
#define dis(a,b) ((LL)(a.x-b.x)*(a.x-b.x)+(LL)(a.y-b.y)*(a.y-b.y))
using namespace std;
void read(int &v){
char c='a';v=0;
for(c=getchar();c>'9'||c<'0';c=getchar());
for(;c<='9'&&c>='0';c=getchar()){
v=v*10+c-'0';
}
}
struct P{
int x,y;
friend P operator - (const P &a,const P &b){
return (P){a.x-b.x,a.y-b.y};
}
friend LL operator * (const P &a,const P &b){
return (LL)a.x*b.y-(LL)a.y*b.x;
}
}p[1000010],s[1000010];
#define c p[1]
bool operator < (const P &a,const P &b){
LL t=(LL)(a.x-c.x)*(a.y-c.y)-(LL)(a.y-c.y)*(b.x-c.x);
if(t==0)return dis(a,c)0;
}
double ans=1e18;
int n;
double inter(const P &a,const P &b){
if(a.x==b.x)return 1e18;
double x=a.x-b.x,y=b.y-a.y;
double x1=b.x,y2=a.y;
double y1=x1/x*y,x2=y2/y*x;
return x1+x2+x+y1+y2+y;
}
double checknum(P x){
return (double)x.x+(double)x.y+sqrt((double)x.x*x.y)*2;
}
double slop(P x,P y){
if(x.x-y.x==0)return -1e18;
return (double)(x.y-y.y)/(x.x-y.x);
}
double slop(P x){
return -((double)x.y+sqrt((double)x.x*x.y))/((double)x.x+sqrt((double)x.x*x.y));
}
int main(){
read(n);
for(int i=1;i<=n;i++){
read(p[i].x),read(p[i].y);
}
int t=1;
for(int i=2;i<=n;i++){
if(p[i].ys[l].x)l=i;
if(s[i].x==s[l].x&&s[i].ys[r].y)r=i;
if(s[i].y==s[r].y&&s[i].x=y)&&(z<=x)){
ans=min(ans,checknum(s[i]));
}
}
if(r-l>=1){
double x,y,z;
x=slop(s[l],s[l+1]);
z=slop(s[l]);
if(z<=x){
ans=min(ans,checknum(s[l]));
}
y=slop(s[r-1],s[r]);
z=slop(s[r]);
if(z>=y){
ans=min(ans,checknum(s[r]));
}
}
printf("%.4f",ans);
}
//Copyright(c)2016 liuchenrui
//Scoi 2016
#include
#include
#include
#include
#include
#include
#include
#define P 233
#define M 1000000
using namespace std;
void read(int &v){
char c='a';v=0;bool p=0;
for(c=getchar();c>'9'||c<'0';c=getchar()){
if(c=='-')p=1;
}
for(;c<='9'&&c>='0';c=getchar()){
v=v*10+c-'0';
}
if(p)v=-v;
}
int n,m;
int a[200010];
int ls[8000000],rs[8000000],val[8000000],tot;
int s[101],root[200010];
void insert(int pre,int &now,int l,int r,int pos){
if(!now)now=++tot;
if(l==r){
val[now]=val[pre]+1;
return;
}
int mid=l+r>>1;
if(pos<=mid)insert(ls[pre],ls[now],l,mid,pos),rs[now]=rs[pre];
else insert(rs[pre],rs[now],mid+1,r,pos),ls[now]=ls[pre];
val[now]=val[ls[now]]+val[rs[now]];
}
int ishave(int pre,int now,int l,int r,int L,int R){
if(!(val[now]-val[pre]))return 0;
if(L<=l && r<=R){
return 1;
}
int mid=l+r>>1,ret=0;
if(L<=mid)ret|=ishave(ls[pre],ls[now],l,mid,L,R);
if(R>=mid+1)ret|=ishave(rs[pre],rs[now],mid+1,r,L,R);
return ret;
}
int main(){
read(n),read(m);
for(int i=1;i<=n;i++){
read(a[i]);
insert(root[i-1],root[i],0,M,a[i]);
}
for(;m--;){
int b,x,l,r;
read(b),read(x),read(l),read(r);
for(int i=30,t=b;i>=1;i--,t>>=1)s[i]=t&1;
int L=0,R=(1<<30)-1;
for(int i=1;i<=30;i++){
int mid=L+R>>1;
if(s[i]){
if(ishave(root[l-1],root[r],0,M,L-x,mid-x))R=mid;
else L=mid+1;
}
else{
if(ishave(root[l-1],root[r],0,M,mid+1-x,R-x))L=mid+1;
else R=mid;
}
}
printf("%d\n",b^L);
}
}