清北刷题冲刺 10-30 a.m
星空
#include<iostream> #include<cstdio> using namespace std; int n,m; int main(){ freopen("star.in","r",stdin);freopen("star.out","w",stdout); while(1){ scanf("%d%d",&n,&m); if(n==0&&m==0)return 0; if((n*m)%2==0)puts("Yuri"); else puts("Chito"); } }
战争
#include<iostream> #include<cstdio> #include<vector> #include<algorithm> #define maxn 50010 #define mod 1000000007 using namespace std; int n,k,a[maxn],mx; vector<int>b; long long ans; bool cmp(int x,int y){return x>y;} int main(){ freopen("war.in","r",stdin);freopen("war.out","w",stdout); // freopen("Cola.txt","r",stdin); scanf("%d%d",&n,&k); for(int i=1;i<=n;i++)scanf("%d",&a[i]); for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++){ int w=a[i]^a[j]; b.push_back(w); } sort(b.begin(),b.end(),cmp); for(int i=0;i<k;i++){ ans+=b[i]; while(ans>=mod)ans-=mod; } cout<<ans; }
无题
#include<iostream> #include<cstdio> #include<algorithm> #define maxn 100010 using namespace std; int n,m,a[maxn],b[maxn]; struct node{ int l,r,v,lazy; }tr[100010*2]; struct Nde{ int opt,x,y,z; }qu[maxn]; bool flag=1; int opl,opr,opv; bool cmp(int x,int y){return x>y;} void build(int l,int r,int k){ tr[k].l=l;tr[k].r=r; if(l==r){tr[k].v=a[l];return;} int mid=(l+r)>>1; build(l,mid,k<<1); build(mid+1,r,k<<1|1); tr[k].v=max(tr[k<<1].v,tr[k<<1|1].v); } void update(int k){ tr[k<<1].lazy+=tr[k].lazy; tr[k<<1].v+=tr[k].lazy; tr[k<<1|1].lazy+=tr[k].lazy; tr[k<<1|1].v+=tr[k].lazy; tr[k].lazy=0; } int query(int l,int r,int k){ if(tr[k].l>=opl&&tr[k].r<=opr)return tr[k].v; if(tr[k].lazy)update(k); int mid=(l+r)>>1; int res=0; if(opl<=mid)res=max(res,query(l,mid,k<<1)); if(opr>mid)res=max(res,query(mid+1,r,k<<1|1)); tr[k].v=max(tr[k<<1].v,tr[k<<1|1].v); return res; } void change(int l,int r,int k){ if(tr[k].l>=opl&&tr[k].r<=opr){ tr[k].v+=opv; tr[k].lazy+=opv; return; } if(tr[k].lazy)update(k); int mid=(l+r)>>1; if(opl<=mid)change(l,mid,k<<1); if(opr>mid)change(mid+1,r,k<<1|1); tr[k].v=max(tr[k<<1].v,tr[k<<1|1].v); } int main(){ freopen("noname.in","r",stdin);freopen("noname.out","w",stdout); // freopen("Cola.txt","r",stdin); scanf("%d%d",&n,&m); for(int i=1;i<=n;i++)scanf("%d",&a[i]); for(int i=1;i<=m;i++){ scanf("%d%d%d%d",&qu[i].opt,&qu[i].x,&qu[i].y,&qu[i].z); if(qu[i].opt==0&&qu[i].z!=1)flag=0; } if(flag){ build(1,n,1); for(int i=1;i<=m;i++){ opl=qu[i].x;opr=qu[i].y; if(qu[i].opt==0){ if(qu[i].z>qu[i].y-qu[i].x+1)puts("-1"); else printf("%d\n",query(1,n,1)); } else { opv=qu[i].z; change(1,n,1); } } } else{ for(int i=1;i<=m;i++){ if(qu[i].opt==1) for(int j=qu[i].x;j<=qu[i].y;j++)a[j]+=qu[i].z; if(qu[i].opt==0){ int cnt=0; for(int j=qu[i].x;j<=qu[i].y;j++)b[++cnt]=a[j]; sort(b+1,b+cnt+1,cmp); if(cnt<qu[i].z)puts("-1"); else printf("%d\n",b[qu[i].z]); } } } }
/* k<=10,所以维护区间前10大,用左右子树的前10大更新根节点的前10大 */ #include<iostream> #include<cstdio> #include<cstring> #define maxn 100010 #define maxk 10 using namespace std; int n,m,col[maxn<<2|1],opl,opr,opv; struct rec{ int res[maxk]; rec operator + (const rec &b)const{ rec z; int p1=0,p2=0; for(int i=0;i<maxk;i++){ if(res[p1]>b.res[p2])z.res[i]=res[p1++]; else z.res[i]=b.res[p2++]; } return z; } }z[maxn<<2|1]; void color(int k,int c){ col[k]+=c; for(int i=0;i<maxk;i++) if(z[k].res[i])z[k].res[i]+=c; } void push_col(int k){ if(col[k]){ color(k<<1,col[k]); color(k<<1|1,col[k]); col[k]=0; } } void update(int k){ z[k]=z[k<<1]+z[k<<1|1]; } void build(int l,int r,int k){ if(l==r){ scanf("%d",&z[k].res[0]); return; } int mid=(l+r)>>1; build(l,mid,k<<1); build(mid+1,r,k<<1|1); update(k); } rec query(int l,int r,int k){ if(opl<=l&&opr>=r)return z[k]; push_col(k); int mid=(l+r)>>1; /*if(opr<=mid)return query(l,mid,k<<1); else if(opl>mid)return query(mid+1,r,k<<1|1); else return query(l,mid,k<<1)+query(mid+1,r,k<<1|1);*/ if (opl<=mid) { if (mid<opr) return query(l,mid,k<<1)+query(mid+1,r,k<<1|1); else return query(l,mid,k<<1); } else return query(mid+1,r,k<<1|1); } void modify(int l,int r,int k){ if(opl<=l&&opr>=r){ color(k,opv); return; } push_col(k); int mid=(l+r)>>1; if(opl<=mid)modify(l,mid,k<<1); if(opr>mid)modify(mid+1,r,k<<1|1); update(k); } int main(){ freopen("noname.in","r",stdin);freopen("noname.out","w",stdout); // freopen("Cola.txt","r",stdin); scanf("%d%d",&n,&m); build(1,n,1); for(int i=1;i<=m;i++){ int opt; scanf("%d%d%d%d",&opt,&opl,&opr,&opv); if(opt==0){ if(opr-opl+1<opv)puts("-1"); else printf("%d\n",query(1,n,1).res[opv-1]); } else modify(1,n,1); } return 0; }
预计得分0+40+50 实际得分100+0+20 T1看起来应该是个结论题,我博弈论很弱所以就找了半个小时规律,就写出来了,但是不会证明。T2不会正解,就直接枚举了,但是非常不小心的是在排序之前取了模,所以排序有误,报零了。T3没看到输出-1的情况,少了30分,很可惜 今天上午精神状态不好,发挥不佳,有很多细节出了错误,导致成绩与预计得分差距较大,以后要认真审题,谨慎写代码,考场上调整好状态