来自FallDream的博客,未经允许,请勿转载,谢谢。


晚上去clj博客逛来逛去很开心,突然同学提醒了一下,发现cf已经开始40分钟了,慌的一B,从B题开始写,写完了B到E最后收掉了A,结果太着急B题忘记写一个等号挂掉了。。。。D题瞎dp也挂了很难受。F题还剩5分钟的时候想出来了,如果没迟应该能写完。

A.

你要做n道题 每道题要花费时间ti,有m个可以提交的时间段,你在同一时刻可以交很多代码并且不耗时间,求最早什么时候可以把代码全部交完。

发现只要管最后一道题啥时候交就行了,扫一遍区间。

  1. #include<iostream>
  2. #include<cstdio>
  3. #define MN 1000
  4. #define INF 1000000000
  5. using namespace std;
  6. inline int read()
  7. {
  8. int x = , f = ; char ch = getchar();
  9. while(ch < '' || ch > ''){ if(ch == '-') f = -; ch = getchar();}
  10. while(ch >= '' && ch <= ''){x = x * + ch - '';ch = getchar();}
  11. return x * f;
  12. }
  13. int n,m,mn=INF,tot=;
  14. int main()
  15. {
  16. n=read();
  17. for(int i=;i<=n;++i) tot+=read();
  18. m=read();
  19. for(int i=;i<=m;++i)
  20. {
  21. int l=read(),r=read();
  22. if(r>=tot) mn=min(mn,max(,l-tot));
  23. }
  24. printf("%d",mn==INF?-:mn+tot);
  25. return ;
  26. }

B.给定一个区间[l,r]和x,y,定义特殊数字是可以被表示成x^a+y^b(a,b是非负整数)的数,求[l,r]中最长的连续的一段数字,满足这段数字区间内全是非特殊的数字。

l,r<=10^18 2<=x,y<=10^19

显然x^a和y^b只有log种,都拿出来排个序就行了。

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #define ll long long
  5. #define MN (ll)1e18
  6. using namespace std;
  7. ll s[],s2[],mx=,a[];int top1=,top2=,top=;
  8. int main()
  9. {
  10. ll x,y,l,r;
  11. scanf("%lld%lld%lld%lld",&x,&y,&l,&r);
  12. s[++top1]=;s2[++top2]=;
  13. for(ll i=x;;i*=x)
  14. {
  15. s[++top1]=i;
  16. if(i>MN/x)break;
  17. }
  18. for(ll i=y;;i*=y)
  19. {
  20. s2[++top2]=i;
  21. if(i>MN/y)break;
  22. }
  23. for(int i=;i<=top1;++i)
  24. for(int j=;j<=top2;++j)
  25. if(s[i]+s2[j]>=l&&s[i]+s2[j]<=r)
  26. a[++top]=s[i]+s2[j];
  27. if(!top) return *printf("%lld",r-l+);
  28. sort(a+,a+top+);
  29. mx=max(mx,a[]-l);
  30. mx=max(mx,r-a[top]);
  31. for(int i=;i<=top;++i)
  32. mx=max(mx,a[i]-a[i-]-);
  33. cout<<mx;
  34. return ;
  35. }

C.

给定一棵树,一个人在x(x!=1)号点,另一个在1号点,每次行动每个人可以移动到一个相邻节点或者不动,第一个人希望回合最多,第二个人希望最少,求最多有多少个回合。

n<=2*10^5

枚举目标点,一个点可行当且仅当x到它和x的lca的距离小于1号点到lca的距离。

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #define MD 18
  5. #define MN 200000
  6. using namespace std;
  7. inline int read()
  8. {
  9. int x = , f = ; char ch = getchar();
  10. while(ch < '' || ch > ''){ if(ch == '-') f = -; ch = getchar();}
  11. while(ch >= '' && ch <= ''){x = x * + ch - '';ch = getchar();}
  12. return x * f;
  13. }
  14. pair<int,int> p[MN+];
  15. int cnt=,head[MN+],fa[MD+][MN+],dep[MN+],f[MN+],n;
  16. struct edge{int to,next;}e[MN*+];
  17. inline void ins(int f,int t)
  18. {
  19. e[++cnt]=(edge){t,head[f]};head[f]=cnt;
  20. e[++cnt]=(edge){f,head[t]};head[t]=cnt;
  21. }
  22. bool cmp(pair<int,int> x,pair<int,int> y){return x.first>y.first;}
  23. void Dfs(int x,int f)
  24. {
  25. fa[][x]=f;p[x]=make_pair(dep[x],x);
  26. for(int i=head[x];i;i=e[i].next)
  27. if(e[i].to!=f)
  28. dep[e[i].to]=dep[x]+,Dfs(e[i].to,x);
  29. }
  30.  
  31. inline int lca(int x,int y)
  32. {
  33. if(dep[x]<dep[y]) swap(x,y);
  34. for(int k=dep[x]-dep[y],j=;k;k>>=,++j)
  35. if(k&)x=fa[j][x];
  36. if(x==y) return x;
  37. for(int i=MD;~i;--i)
  38. if(fa[i][x]!=fa[i][y])
  39. x=fa[i][x],y=fa[i][y];
  40. return fa[][x];
  41. }
  42.  
  43. int main()
  44. {
  45. n=read();int x=read();
  46. for(int i=;i<n;++i) ins(read(),read());
  47. Dfs(,);
  48. for(int i=;i<=MD;++i)
  49. for(int j=;j<=n;++j)
  50. fa[i][j]=fa[i-][fa[i-][j]];
  51. sort(p+,p+n+,cmp);
  52. for(int i=;i<=n;++i)
  53. {
  54. int z=lca(x,p[i].second);
  55. if(dep[x]-dep[z]>=dep[z]) continue;
  56. return *printf("%d\n",p[i].first*);
  57. }
  58. return ;
  59. }

D.

给定一个长度为n(<=5000)的序列ai,定义优秀的序列是满足相邻元素相差1或者在膜7意义下相等的序列,求这个序列的两个不相交的优秀子序列满足长度之和最大。

f[i][j]表示两个序列结尾分别在i,j的最长长度

枚举i,j,对于每个i,开两个数组分别表示最后一个数是k和最后一个数膜7等于k的最长长度,然后分别转移。

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #define MN 5000
  5. using namespace std;
  6. inline int read()
  7. {
  8. int x = ,f = ; char ch = getchar();
  9. while(ch < '' || ch > ''){if(ch == '-') f = ;ch = getchar();}
  10. while(ch >= '' && ch <= ''){x = x * + ch - '';ch = getchar();}
  11. return f?x:-x;
  12. }
  13. int n,a[MN+],f[MN+],F[],D[MN+][MN+],ans=,ha[],cnt=;
  14. inline void R(int&x,int y){y>x?x=y:;}
  15. int main()
  16. {
  17. n=read();
  18. for(int i=;i<=n;++i)!ha[a[i]=read()]?ha[a[i]]=++cnt:;
  19. for(int i=;i<=n;++i)
  20. {
  21. memset(F,,sizeof(F));
  22. memset(f,,sizeof(f));
  23. int Mx=D[i][];
  24. for(int j=;j<i;++j)
  25. R(F[a[j]%],D[i][j]),
  26. R(f[ha[a[j]]],D[i][j]);
  27. for(int j=i+;j<=n;++j)
  28. {
  29. R(D[i][j],Mx+);
  30. R(D[i][j],max(f[ha[a[j]]],F[a[j]%])+);
  31. if(ha[a[j]-]) R(D[i][j],f[ha[a[j]-]]+);
  32. if(ha[a[j]+]) R(D[i][j],f[ha[a[j]+]]+);
  33. R(F[a[j]%],D[i][j]);R(f[ha[a[j]]],D[i][j]);
  34. R(D[j][i],D[i][j]);R(ans,D[i][j]);
  35. }
  36. }
  37. cout<<ans;
  38. return ;
  39. }

E. Army Creation

给定一个长度为n(<=100000)的序列ai,每次询问一段区间,满足每个数字出现次数不超过k(预先给定)次的情况下最多能保留几个数字。

从前往后扫一遍,找到每个数字前面的第k个相同的数字的位置pos,右区间>=i且左区间<=pos的时候答案减1,可持久化线段树维护即可。

复杂度nlogn

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<vector>
  4. #define MN 100000
  5. using namespace std;
  6. inline int read()
  7. {
  8. int x = , f = ; char ch = getchar();
  9. while(ch < '' || ch > ''){ if(ch == '-') f = -; ch = getchar();}
  10. while(ch >= '' && ch <= ''){x = x * + ch - '';ch = getchar();}
  11. return x * f;
  12. }
  13. vector<int> v[MN+];
  14. int n,k,num[MN+],rt[MN+],cnt=,last=,a[MN+];
  15. struct Tree{int l,r,x;}T[];
  16.  
  17. void Modify(int x,int nx,int k)
  18. {
  19. int l=,r=n,mid;T[nx].x=T[x].x+;
  20. while(l<r)
  21. {
  22. mid=l+r>>;
  23. if(k<=mid)T[nx].r=T[x].r,T[nx].l=++cnt,x=T[x].l,nx=T[nx].l,r=mid;
  24. else T[nx].l=T[x].l,T[nx].r=++cnt,x=T[x].r,nx=T[nx].r,l=mid+;
  25. T[nx].x=T[x].x+;
  26. }
  27. }
  28.  
  29. int Query(int x,int k)
  30. {
  31. int sum=,l=,r=n,mid;
  32. while(l<r)
  33. {
  34. mid=l+r>>;
  35. if(k<=mid) sum+=T[T[x].r].x,x=T[x].l,r=mid;
  36. else x=T[x].r,l=mid+;
  37. }
  38. return sum+T[x].x;
  39. }
  40.  
  41. int main()
  42. {
  43. n=read();k=read();
  44. for(int i=;i<=n;++i)
  45. v[a[i]=read()].push_back(i);
  46. for(int i=;i<=n;++i)
  47. if(++num[a[i]]>k)
  48. Modify(rt[i-],rt[i]=++cnt,v[a[i]][num[a[i]]-k-]);
  49. else rt[i]=rt[i-];
  50. for(int q=read();q;--q)
  51. {
  52. int l=(read()+last)%n+,r=(read()+last)%n+;
  53. if(l>r) swap(l,r);
  54. printf("%d\n",last=(r-l+)-Query(rt[r],l));
  55. }
  56. return ;
  57. }

F.

给你n个点,支持删边,加边,询问是否是二分图。

n,q<=10^5

考虑线段树分治避免删除操作,然后带权并差集+启发式合并维护答案即可。

复杂度nlog^2n

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<map>
  4. #include<vector>
  5. #define pa pair<int,int>
  6. #define mp(x,y) make_pair(x,y)
  7. #define MN 100000
  8. using namespace std;
  9. inline int read()
  10. {
  11. int x = ,f = ; char ch = getchar();
  12. while(ch < '' || ch > ''){if(ch == '-') f = ;ch = getchar();}
  13. while(ch >= '' && ch <= ''){x = x * + ch - '';ch = getchar();}
  14. return f?x:-x;
  15. }
  16. bool Ans[MN+];
  17. map<long long,int> mp;
  18. int n,q,cnt=,fa[MN+],W[MN+],val[MN+],size[MN+],A[MN+],B[MN+];
  19. struct Tree{int l,r;vector<pa> x;vector<int> v;}T[MN*+];
  20.  
  21. void Ins(int x,int l,int r,pa v)
  22. {
  23. if(T[x].l==l&&T[x].r==r) {T[x].x.push_back(v);return;}
  24. int mid=T[x].l+T[x].r>>;
  25. if(r<=mid) Ins(x<<,l,r,v);
  26. else if(l>mid) Ins(x<<|,l,r,v);
  27. else Ins(x<<,l,mid,v),Ins(x<<|,mid+,r,v);
  28. }
  29.  
  30. void build(int x,int l,int r)
  31. {
  32. if((T[x].l=l)==(T[x].r=r))return;
  33. int mid=l+r>>;
  34. build(x<<,l,mid);
  35. build(x<<|,mid+,r);
  36. }
  37. inline int getfa(int x)
  38. {
  39. if(fa[x]==x) return x;
  40. int F=getfa(fa[x]);
  41. return val[x]=val[fa[x]]^W[x],F;
  42. }
  43. void Solve(int k,bool flag)
  44. {
  45. for(int i=;i<T[k].x.size();++i)
  46. {
  47. int x=T[k].x[i].first,y=T[k].x[i].second;
  48. int f1=getfa(x),f2=getfa(y);
  49. if(size[f1]>size[f2]) swap(f1,f2);
  50. if(f1==f2) flag|=(val[x]==val[y]);
  51. else
  52. {
  53. size[f2]+=size[f1];fa[f1]=f2;
  54. W[f1]=val[x]==val[y];
  55. T[k].v.push_back(f1);
  56. }
  57. }
  58. if(T[k].l==T[k].r) Ans[T[k].l]=flag;
  59. else Solve(k<<,flag),Solve(k<<|,flag);
  60. for(int i=;i<T[k].v.size();++i)
  61. {
  62. int x=T[k].v[i];fa[x]=x;
  63. size[fa[x]]-=size[x];W[x]=val[x]=;
  64. }
  65. }
  66.  
  67. int main()
  68. {
  69. n=read();q=read();build(,,q);
  70. for(int i=;i<=n;++i) fa[i]=i,size[i]=,val[i]=W[i]=;
  71. for(int i=;i<=q;++i)
  72. {
  73. int x=read(),y=read();
  74. if(mp[1LL*x*MN+y])
  75. {
  76. Ins(,mp[1LL*x*MN+y],i-,mp(x,y));
  77. mp[1LL*x*MN+y]=;
  78. }
  79. else mp[1LL*x*MN+y]=i;
  80. A[i]=x;B[i]=y;
  81. }
  82. for(int i=;i<=q;++i)
  83. {
  84. int x=mp[1LL*A[i]*MN+B[i]];
  85. if(x) mp[1LL*A[i]*MN+B[i]]=,Ins(,x,q,mp(A[i],B[i]));
  86. }
  87. Solve(,);
  88. for(int i=;i<=q;++i) puts(Ans[i]?"NO":"YES");
  89. return ;
  90. }

[Educational Codeforces Round#22]的更多相关文章

  1. Educational Codeforces Round 22 E. Army Creation

    Educational Codeforces Round 22 E. Army Creation 题意:求区间[L,R]内数字次数不超过k次的这些数字的数量的和 思路:和求区间内不同数字的数量类似,由 ...

  2. Educational Codeforces Round 22.B 暴力

    B. The Golden Age time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  3. Educational Codeforces Round 22 E. Army Creation 主席树 或 分块

    http://codeforces.com/contest/813/problem/E 题目大意: 给出长度为n的数组和k,  大小是1e5级别. 要求在线询问区间[l, r]权值,  权值定义为对于 ...

  4. Educational Codeforces Round 22 B. The Golden Age(暴力)

    题目链接:http://codeforces.com/contest/813/problem/B 题意:就是有一个数叫做不幸运数,满足题目的 n = x^a + y^b,现在给你一个区间[l,r],让 ...

  5. 【Educational Codeforces Round 22】

    又打了一场EDU,感觉这场比23难多了啊…… 艹还是我太弱了. A. 随便贪心一下. #include<bits/stdc++.h> using namespace std; ,ans=- ...

  6. Educational Codeforces Round 22 E. Army Creation(分块好题)

    E. Army Creation time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  7. Educational Codeforces Round 22 补题 CF 813 A-F

    A The Contest 直接粗暴贪心 略过 #include<bits/stdc++.h> using namespace std; int main() {//freopen(&qu ...

  8. Educational Codeforces Round 40千名记

    人生第二场codeforces.然而遇上了Education场这种东西 Educational Codeforces Round 40 下午先在家里睡了波觉,起来离开场还有10分钟. 但是突然想起来还 ...

  9. [Educational Codeforces Round 63 ] D. Beautiful Array (思维+DP)

    Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array time limit per test 2 seconds ...

随机推荐

  1. docopt——好用的Python命令行参数解释器

    Qingchat使用的命令行参数解释器是 docopt,用下来感觉非常棒,所以决定介绍一下这个库.( 奉劝各位看官,真爱生命,远离argparse. ) 介绍 docopt 本质上是在 Python ...

  2. Struts2之配置文件中Action的详细配置

    在Struts2之配置一文中,我们知道一个struts配置文件可以分为三部分:常量配置    包含其他配置文件的配置    Action配置  . 这其中 常量配置  和 包含其他配置文件的配置  二 ...

  3. 关于移动web教程免费发布

    各位老铁大家好,最近经历了太多太多,精力一直不能集中做自己愿意做的事情. 移动Web课程一开始设置收费10块,其实本意是让大家感觉有支出,就会相对珍惜好好学习,但是发现收费把大部分人挡在门外,现在恢复 ...

  4. LeetCode & Q14-Longest Common Prefix-Easy

    String Description: Write a function to find the longest common prefix string amongst an array of st ...

  5. java 零基础搭建dubbo运行环境

    一:简介    以前做项目时,分布式环境都是其它同事在搭建,自己也没参与分布式环境搭建,只负责开发,由于近段时间工作重心转到android,java后台有一段时间没有接触了,刚好这几天有空,决定自己动 ...

  6. GIT入门笔记(10)- 多种撤销修改场景和对策

    场景1:当你改乱了工作区某个文件的内容,想直接丢弃工作区的修改时,用命令git checkout -- file. 场景2:当你不但改乱了工作区某个文件的内容,还添加到了暂存区时,想丢弃修改,分两步, ...

  7. Homebrew update error not work on OSX

    brew update 错误是这样的 chown: /usr/local: Operation not permitted 然后网上osx 10.11, 10.12的解决方法这样的 The probl ...

  8. 【52ABP实战教程】0.3-- 从github推送代码回vsts实现双向同步

    需求 在之前的文章中"[DevOps]如何用VSTS持续集成到Github仓库" 我们有讲述如何将vsts中的代码编译推送到github中,这一篇我们来完善,如果有人给你开源项目推 ...

  9. intelj idea 创建聚合项目(典型web项目,包括子项目util、dao、service)

    需求:第三方提供了http api接口,我们需要将其数据全部取回来,存放到本地Mysql数据库. 开发工具是intelj idea,准备基于maven创建聚合项目,util作为工具包,单独作为一个工程 ...

  10. Oracle处理XML字段时遇到的ORA-31013: XPATH 表达式无效问题

    select extractValue(ed.info_id, '/Root/ExpandProfile/PhoneNumber') as phone, extractValue(ed.info_id ...