# 两次考试

10.22

T1

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
#define rint register int
using namespace std;
const int N=100006;
{
x=0; char q=getchar();
while(q<'0'||q>'9') q=getchar();
while(q>='0'&&q<='9') x=x*10+q-'0',q=getchar();
}

int n;
int f[N],g[N];

int main(){

//freopen("T1.in","r",stdin);
//freopen("T1.out","w",stdout);

rint i,j;

int tt=0;
for(i=0;i<n;++i)
{
tt=(tt^(f[i]^g[i]));
printf("%d ",tt);
}
}
T1

T2

ans就是最底下一层最中间开始数到左右两边最近的连续的一段

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
#define rint register int
using namespace std;
const int N=100006;
{
x=0; char q=getchar();
while(q<'0'||q>'9') q=getchar();
while(q>='0'&&q<='9') x=x*10+q-'0',q=getchar();
}

int n;
int f[N],g[N];

int main(){

//freopen("T1.in","r",stdin);
//freopen("T1.out","w",stdout);

rint i,j;

int tt=0;
for(i=0;i<n;++i)
{
tt=(tt^(f[i]^g[i]));
printf("%d ",tt);
}
}
T2正解

T3

#pragma GCC optimize("O3")
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
#define rint register int
using namespace std;
{
x=0; char q=getchar();
while(q<'0'||q>'9') q=getchar();
while(q>='0'&&q<='9') x=x*10+q-'0',q=getchar();
}
const int N=200006;
const int INF=1000000000;
int first[N],nt[N],ver[N],e;
{
ver[e]=v;
nt[e]=first[u];
first[u]=e++;
}

int T;
int n;
int u[N],v[N];

int mn[N*5],sum[N*5],jiid[N*5],jiv[N*5];
int L,R,oo,vv,pos,id;
inline void add(int l,int r,int x)
{
if(L<=l&&r<=R)
{
mn[x]+=vv;
sum[x]+=(oo*(r-l+1));
jiv[x]+=vv;
jiid[x]+=oo;
return ;
}

int mid=(l+r)>>1,ls=x<<1,rs=x<<1|1;

if(jiid[x])
{
jiid[ls]+=jiid[x];
jiid[rs]+=jiid[x];
sum[ls]+=jiid[x]*(mid-l+1);
sum[rs]+=jiid[x]*(r-mid);
jiid[x]=0;
}
if(jiv[x])
{
jiv[ls]+=jiv[x];
jiv[rs]+=jiv[x];
mn[ls]+=jiv[x];
mn[rs]+=jiv[x];
jiv[x]=0;
}

mn[x]=(mn[ls]<mn[rs]?mn[ls]:mn[rs]);
sum[x]=sum[ls]+sum[rs];
}
inline void qq(int l,int r,int x)
{
if(l==r)
{
if(mn[x]==1) mn[x]=INF,pos=l,id=sum[x];
return ;
}
int mid=(l+r)>>1,ls=x<<1,rs=x<<1|1;
if(jiid[x])
{
jiid[ls]+=jiid[x];
jiid[rs]+=jiid[x];
sum[ls]+=jiid[x]*(mid-l+1);
sum[rs]+=jiid[x]*(r-mid);
jiid[x]=0;
}
if(jiv[x])
{
jiv[ls]+=jiv[x];
jiv[rs]+=jiv[x];
mn[ls]+=jiv[x];
mn[rs]+=jiv[x];
jiv[x]=0;
}

if(mn[ls]==1) qq(l,mid,ls);
else qq(mid+1,r,rs);

mn[x]=(mn[ls]<mn[rs]?mn[ls]:mn[rs]);
sum[x]=sum[ls]+sum[rs];
}

int fa[N],dep[N],size[N],son[N];
inline void dfs1(int x)
{
size[x]=1;
for(int i=first[x];i!=-1;i=nt[i])
{
if(ver[i]==fa[x])
continue;
fa[ver[i]]=x;
dep[ver[i]]=dep[x]+1;
dfs1(ver[i]);
size[x]+=size[ver[i]];
if(size[son[x]]<size[ver[i]])
son[x]=ver[i];
}
}
int top[N],zheng[N],timer;
inline void dfs2(int x,int tp)
{
top[x]=tp; zheng[x]=++timer;
if(son[x])
dfs2(son[x],tp);
for(int i=first[x];i!=-1;i=nt[i])
{
if(ver[i]==fa[x]||ver[i]==son[x])
continue;
dfs2(ver[i],ver[i]);
}
}
{
int fx=top[x],fy=top[y];
while(fx!=fy)
{
if(dep[fx]<dep[fy])
{
x^=y; y^=x; x^=y;
fx^=fy; fy^=fx; fx^=fy;
}
L=zheng[fx]; R=zheng[x];
x=fa[fx];
fx=top[x];
}
if(dep[x]>dep[y]) x^=y,y^=x,x^=y;
}

inline int work()
{
mem(ver,0); mem(first,-1); mem(nt,0); e=0;
mem(son,0); mem(size,0);
timer=0;
mem(mn,0); mem(sum,0); mem(jiv,0); mem(jiid,0);
rint i,j; int tin1,tin2;
for(i=1;i<n;++i)
{
}
for(i=1;i<n;++i)
fa[1]=-1; dep[1]=0;
dfs1(1);
dfs2(1,1);
L=1; R=1; vv=INF; oo=0;
for(i=1;i<n;++i)
for(i=1;i<n;++i)
{
id=0; pos=0;
qq(1,n,1);
if(!id) return 0;
oo=-id; vv=-1;
}
return 1;
}

int main(){

//freopen("T3.in","r",stdin);

//freopen("tree13.in","r",stdin);

while(T--)
{
if(work())
printf("YES\n");
else
printf("NO\n");
}
}
T3

10.23

T1

(1)

(2)

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <cmath>
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define dd double
#define rint register int
//#define dis(x3,y3,x4,y4) (sqrt((y3-y4)*(y3-y4)+(x3-x4)*(x3-x4)))
#define esp 0.0000001
using namespace std;
{
x=0; char q=getchar();
while(q<'0'||q>'9') q=getchar();
while(q>='0'&&q<='9') x=x*10+q-'0',q=getchar();
}
const int MAXK=10006;
int first[MAXK*3],nt[MAXK*3],ver[MAXK*3],e;
dd w[MAXK*3];
{
ver[e]=v;
w[e]=_w;
nt[e]=first[u];
first[u]=e++;
}

int n,m,K;
int x[MAXK+100],y[MAXK+100];
dd mn[MAXK+100];
bool ff[MAXK+100];
int pr[MAXK+100];

inline dd dis(int f1,int f2)
{
if( (f1==0&&f2==K+1)||(f1==K+1&&f2==0) ) return m;
if(f1==0) return y[f2];
if(f1==K+1) return m-y[f2];
if(f2==0) return y[f1];
if(f2==K+1) return m-y[f1];
return sqrt((y[f1]-y[f2])*(y[f1]-y[f2])+(x[f1]-x[f2])*(x[f1]-x[f2]));
}

dd an[MAXK+100];
void dfs(int x)
{
for(int i=first[x];i!=-1;i=nt[i])
{
if(an[ver[i]]>w[i])
an[ver[i]]=w[i];
dfs(ver[i]);
}
}

dd work()
{
rint i,j; int all=K+1;

for(i=all+1;i>=0;--i) mn[i]=an[i]=0x7fffffff;
mn[0]=0;
int tt; dd vv;
for(i=0;i<=all;++i)
{
tt=all+1;
for(j=0;j<=all;++j)
if(!ff[j]&&mn[tt]>mn[j])
tt=j;
ff[tt]=1;
//printf("i=%d tt=%d\n",i,tt);
for(j=0;j<=all;++j)
if(!ff[j])
{
vv=dis(tt,j);
//printf("j=%d vv=%lf\n",j,vv);
if(mn[j]>vv)
mn[j]=vv,pr[j]=tt;
}
}
for(i=1;i<=all;++i)
dfs(0);
return an[all]/2.0;
}

int main(){

freopen("T1.in","r",stdin);
//freopen("T1.out","w",stdout);

mem(first,-1);

rint i,j;

printf("%.8lf",work());
}

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <cmath>
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define dd double
#define rint register int
//#define dis(x3,y3,x4,y4) (sqrt((y3-y4)*(y3-y4)+(x3-x4)*(x3-x4)))
#define esp 0.0000001
using namespace std;
{
x=0; char q=getchar();
while(q<'0'||q>'9') q=getchar();
while(q>='0'&&q<='9') x=x*10+q-'0',q=getchar();
}
{
x=0; char q=getchar();
while(q<'0'||q>'9') q=getchar();
while(q>='0'&&q<='9') x=x*10+q-'0',q=getchar();
}
const int MAXK=10006;
int first[MAXK*3],nt[MAXK*3],ver[MAXK*3],e;
ll w[MAXK*3];
{
ver[e]=v;
w[e]=_w;
nt[e]=first[u];
first[u]=e++;
}

int n,m,K;
ll x[MAXK+100],y[MAXK+100];
ll mn[MAXK+100],ans;
bool ff[MAXK+100];
int pr[MAXK+100];

inline ll dis(int f1,int f2)
{
if(f1>f2) f1^=f2,f2^=f1,f1^=f2;
if(f1==K+1&&f2==K+2) return (ll)m*m;
if(f2==K+1) return y[f1]*y[f1];
if(f2==K+2) return ((ll)m-y[f1])*((ll)m-y[f1]);
return (y[f1]-y[f2])*(y[f1]-y[f2])+(x[f1]-x[f2])*(x[f1]-x[f2]);
}

void dfs(int x,int fa,ll ww)
{
if(x==K+2)
{
ans=ww;
return ;
}
for(int i=first[x];i!=-1;i=nt[i])
{
if(ver[i]==fa)
continue;
dfs(ver[i],x,max(ww,w[i]));
}
}

dd work()
{
rint i,j; int all=K+2;

mem(mn,0x7f);
mn[K+1]=0;
int tt; ll vv;
for(i=1;i<=all;++i)
{
tt=0;
for(j=1;j<=all;++j)
if(!ff[j]&&mn[tt]>mn[j])
tt=j;
ff[tt]=1;
if(pr[tt])
for(j=1;j<=all;++j)
if(!ff[j])
{
vv=dis(tt,j);
if(mn[j]>vv)
mn[j]=vv,pr[j]=tt;
}
}
dfs(K+1,-1,0);
return sqrt(ans)/2.0;
}

int main(){

//freopen("T1.in","r",stdin);
//freopen("T1.out","w",stdout);

//freopen("in.in","r",stdin);

mem(first,-1);

rint i,j;

printf("%.8lf",work());
}
2

T2

ans、由于两个子区间不可加性的辅助转移的变量、记录状态防止超时的量

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <cmath>
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define dd double
#define rint register int
using namespace std;
{
x=0; char q=getchar();
while(q<'0'||q>'9') q=getchar();
while(q>='0'&&q<='9') x=x*10+q-'0',q=getchar();
}
const int N=200006;

struct son
{
int pos,p,c;
bool friend operator < (son a,son b)
{
return a.p<b.p;
}
}ji[N];

int n,INF;

int an[N*4],mx[N*4],ban[N*4];
int cal(int hi,int l,int r,int x)
{
if(hi>mx[x]) return INF;
if(l==r) return an[x];
int mid=(l+r)>>1;
if(hi>mx[x<<1|1]) return cal(hi,l,mid,x<<1);
else return min(ban[x<<1],cal(hi,mid+1,r,x<<1|1));
}
void change(int pos,int hh,int vv,int l,int r,int x)
{
if(l==r)
{
an[x]=vv; mx[x]=hh;
return ;
}
int mid=(l+r)>>1;
if(pos<=mid) change(pos,hh,vv,l,mid,x<<1);
else change(pos,hh,vv,mid+1,r,x<<1|1);
mx[x]=max(mx[x<<1],mx[x<<1|1]);
an[x]=min(an[x<<1|1],ban[x<<1]=cal(mx[x<<1|1],l,mid,x<<1));
}
void qq(int L,int R,int &ans,int &hi,int l,int r,int x)
{
//printf("L=%d R=%d ans=%d hi=%d l=%d r=%d x=%d\n",L,R,ans,hi,l,r,x);
if(L>R) return ;
if(L<=l&&r<=R)
{
ans=min(ans,cal(hi,l,r,x));
hi=max(hi,mx[x]);
return ;
}
int mid=(l+r)>>1;
if(mid<R)
qq(L,R,ans,hi,mid+1,r,x<<1|1);
if(L<=mid)
qq(L,R,ans,hi,l,mid,x<<1);
}

int f[N];

int work()
{
rint i,j; int tt,hi;
sort(ji+1,ji+1+n);
mem(an,0x7f); mem(ban,0x7f); mem(&INF,0x7f);
for(i=1;i<=n;++i)
{
//printf("i=%d\n",i);
hi=0; tt=INF;
qq(1,ji[i].pos-1,tt,hi,1,n,1);
if(tt==INF) tt=0;
f[ji[i].pos]=tt+ji[i].c;
change(ji[i].pos,ji[i].p,f[ji[i].pos],1,n,1);
}
/*printf("\n");
for(i=1;i<=n;++i)
printf("%d ",f[i]);
printf("\n");*/
return f[n];
}

int main(){

//freopen("T2.in","r",stdin);
//freopen("T2.out","w",stdout);

rint i,j;

++n; ji[n].pos=n; ji[n].c=0; ji[n].p=0x7fffffff;
cout<<work();
}
T2

T3

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <cmath>
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define dd double
#define rint register int
using namespace std;
{
x=0; char q=getchar();
while(q<'0'||q>'9') q=getchar();
while(q>='0'&&q<='9') x=x*10+q-'0',q=getchar();
}
const int N=500006;
int first[N*3],nt[N*3],ver[N*3],e;
{
ver[e]=v;
nt[e]=first[u];
first[u]=e++;
}

int n;
int c[N],dep[N];
int zhan[N*2],he;
dd an[N];

inline dd cross(int q,int w)
{
return (dd)(c[w]-c[q])/(dd)(dep[w]-dep[q]);
}

int er(int l,int r,int order)
{
int mid,tt,ans=r;
while(l<=r)
{
mid=(l+r)>>1;
tt=(cross(zhan[mid],order)<cross(zhan[mid-1],order));
if(tt) ans=mid-1,r=mid-1;
else l=mid+1;
}
return ans;
}

void dfs(int x)
{
int pr,prv;
++he;
prv=zhan[he];
zhan[he]=x;
pr=he;
for(int i=first[x];i!=-1;i=nt[i])
{
dep[ver[i]]=dep[x]+1;
if(he>1)
he=er(2,he,ver[i]);
an[ver[i]]=-cross(zhan[he],ver[i]);
dfs(ver[i]);
he=pr;
}
zhan[he]=prv;
}

int main(){

//freopen("T3.in","r",stdin);

rint i,j;

mem(first,-1);

int tin;
for(i=2;i<=n;++i)
{
}