Preface

老年菜鸡终于开始打CC了,由于他太弱了所以只能打Div2

因为台风的原因challenge并没有写,所以水了个Rank7


A Football

SB模拟题不解释

  1. #include<cstdio>
  2. #include<iostream>
  3. #define RI register int
  4. using namespace std;
  5. const int N=155;
  6. int t,n,a[N],b[N],ans;
  7. int main()
  8. {
  9. for (scanf("%d",&t);t;--t)
  10. {
  11. RI i; for (ans=0,scanf("%d",&n),i=1;i<=n;++i) scanf("%d",&a[i]);
  12. for (i=1;i<=n;++i) scanf("%d",&b[i]),ans=max(ans,20*a[i]-10*b[i]);
  13. printf("%d\n",ans);
  14. }
  15. return 0;
  16. }

B Distribute Apples

题意杀,简单分析之后发现如果\(k^2|n\)就是NO,否则就是YES

  1. #include<cstdio>
  2. #include<iostream>
  3. #define RI register int
  4. using namespace std;
  5. int t; long long n,k;
  6. int main()
  7. {
  8. for (scanf("%d",&t);t;--t)
  9. {
  10. scanf("%lld%lld",&n,&k);
  11. if (n/k<k) { puts("YES"); continue; }
  12. puts(n%(k*k)?"YES":"NO");
  13. }
  14. return 0;
  15. }

C Dilemma

首先不考虑有\(0\)的情况,我们发现长度为奇数的\(1\)就是合法的

考虑在两段\(1\)中间插入一段\(0\),手玩一下发现加入多少都是没有影响的

因此我们按照连续的\(1\)的奇偶性个数讨论,如果奇数的连续的\(1\)有奇数段就是合法的,否则不合法

  1. #include<cstdio>
  2. #include<cstring>
  3. #define RI register int
  4. using namespace std;
  5. const int N=100005;
  6. int t,n; char s[N];
  7. int main()
  8. {
  9. for (scanf("%d",&t);t;--t)
  10. {
  11. scanf("%s",s+1); n=strlen(s+1); int num=0,len=0;
  12. for (RI i=1;i<=n;++i) if (s[i]=='1')
  13. {
  14. if (s[i-1]=='1') ++len; else num+=len&1,len=1;
  15. }
  16. num+=len&1; puts(num&1?"WIN":"LOSE");
  17. }
  18. return 0;
  19. }

D Zombie and the Caves

刚开始看错题了,以为要重排这个序列来构造方案

没想到是直接模拟判断是否可行即可,区间加单点求值差分一下即可

  1. #include<cstdio>
  2. #include<cctype>
  3. #include<iostream>
  4. #include<algorithm>
  5. #define RI register int
  6. #define CI const int&
  7. #define Tp template <typename T>
  8. using namespace std;
  9. const int N=100005;
  10. int t,n,x,h[N],dlt[N];
  11. class FileInputOutput
  12. {
  13. private:
  14. static const int S=1<<21;
  15. #define tc() (A==B&&(B=(A=Fin)+fread(Fin,1,S,stdin),A==B)?EOF:*A++)
  16. char Fin[S],*A,*B;
  17. public:
  18. Tp inline void read(T& x)
  19. {
  20. x=0; char ch; while (!isdigit(ch=tc()));
  21. while (x=(x<<3)+(x<<1)+(ch&15),isdigit(ch=tc()));
  22. }
  23. #undef tc
  24. }F;
  25. int main()
  26. {
  27. //freopen("CODE.in","r",stdin); freopen("CODE.out","w",stdout);
  28. for (F.read(t);t;--t)
  29. {
  30. RI i; for (F.read(n),i=1;i<=n;++i)
  31. F.read(x),++dlt[max(i-x,1)],--dlt[min(i+x,n)+1];
  32. for (i=1;i<=n;++i) dlt[i]+=dlt[i-1],F.read(h[i]);
  33. sort(dlt+1,dlt+n+1); sort(h+1,h+n+1);
  34. bool flag=1; for (i=1;i<=n;++i)
  35. if (dlt[i]!=h[i]) { flag=0; break; }
  36. for (i=1;i<=n+1;++i) dlt[i]=0;
  37. puts(flag?"YES":"NO");
  38. }
  39. return 0;
  40. }

E Guddu and his Mother

我们发现如果一个区间\([l,r]\)内所有数异或起来是\(0\)那么中间的点可以取区间长度-1的位置

因此我们统计一下异或和为\(0\)的区间长度和即可,用树状数组统计一下即可

  1. #include<cstdio>
  2. #include<cctype>
  3. #include<vector>
  4. #include<algorithm>
  5. #define int long long
  6. #define RI register int
  7. #define CI const int&
  8. #define Tp template <typename T>
  9. using namespace std;
  10. typedef vector <int>::iterator VI;
  11. const int N=100005;
  12. int t,n,x,ret,stk[N],top; bool vis[N*10];
  13. vector <int> L[N*10],R[N*10]; long long ans;
  14. class FileInputOutput
  15. {
  16. private:
  17. static const int S=1<<21;
  18. #define tc() (A==B&&(B=(A=Fin)+fread(Fin,1,S,stdin),A==B)?EOF:*A++)
  19. char Fin[S],*A,*B;
  20. public:
  21. Tp inline void read(T& x)
  22. {
  23. x=0; char ch; while (!isdigit(ch=tc()));
  24. while (x=(x<<3)+(x<<1)+(ch&15),isdigit(ch=tc()));
  25. }
  26. #undef tc
  27. }F;
  28. class Tree_Array
  29. {
  30. private:
  31. int bit[N];
  32. public:
  33. #define lowbit(x) x&-x
  34. inline void add(RI x,CI y)
  35. {
  36. for (;x<=n;x+=lowbit(x)) bit[x]+=y;
  37. }
  38. inline int get(RI x,int ret=0)
  39. {
  40. for (;x;x-=lowbit(x)) ret+=bit[x]; return ret;
  41. }
  42. #undef lowbit
  43. }NUM,SUM;
  44. signed main()
  45. {
  46. //freopen("CODE.in","r",stdin); freopen("CODE.out","w",stdout);
  47. for (F.read(t);t;--t)
  48. {
  49. RI i,j; for (F.read(n),vis[stk[top=1]=ret=0]=i=1;i<=n;++i)
  50. {
  51. L[ret].push_back(i); F.read(x);
  52. ret^=x; R[ret].push_back(i);
  53. if (!vis[ret]) stk[++top]=ret,vis[ret]=0;
  54. }
  55. for (ans=0,i=1;i<=top;++i)
  56. {
  57. for (VI it=L[stk[i]].begin();it!=L[stk[i]].end();++it)
  58. NUM.add(*it,1),SUM.add(*it,*it);
  59. for (VI it=R[stk[i]].begin();it!=R[stk[i]].end();++it)
  60. ans+=(*it)*NUM.get(*it)-SUM.get(*it);
  61. for (VI it=L[stk[i]].begin();it!=L[stk[i]].end();++it)
  62. NUM.add(*it,-1),SUM.add(*it,-(*it));
  63. L[stk[i]].clear(); R[stk[i]].clear(); vis[stk[i]]=0;
  64. }
  65. printf("%lld\n",ans);
  66. }
  67. return 0;
  68. }

F Encoding

看到数据范围直接数位DP一下就好了

定义\(f_{i,j}\)表示当前处理完了前\(i\)位,上一位是\(j\)时的状态

状态我们要记录两个,一个是合法的状态数,用来累计这一位的贡献,另一个就是总贡献数

  1. #include<cstdio>
  2. #include<cctype>
  3. #define RI register int
  4. #define CI const int&
  5. #define Tp template <typename T>
  6. using namespace std;
  7. const int N=100005,mod=1e9+7;
  8. int t,n,a[N],pw[N]; char ch;
  9. struct data
  10. {
  11. int num,sum;
  12. inline data(CI Num=-1,CI Sum=-1)
  13. {
  14. num=Num; sum=Sum;
  15. }
  16. }f[N][10];
  17. inline bool operator ~ (const data& x)
  18. {
  19. return ~x.num&&~x.sum;
  20. }
  21. class FileInputOutput
  22. {
  23. private:
  24. static const int S=1<<21;
  25. #define tc() (A==B&&(B=(A=Fin)+fread(Fin,1,S,stdin),A==B)?EOF:*A++)
  26. char Fin[S],*A,*B;
  27. public:
  28. Tp inline void read(T& x)
  29. {
  30. x=0; char ch; while (!isdigit(ch=tc()));
  31. while (x=(x<<3)+(x<<1)+(ch&15),isdigit(ch=tc()));
  32. }
  33. inline void get_digit(char& ch)
  34. {
  35. while (!isdigit(ch=tc()));
  36. }
  37. #undef tc
  38. }F;
  39. inline void inc(int& x,CI y)
  40. {
  41. if ((x+=y)>=mod) x-=mod;
  42. }
  43. inline data MDFS(CI nw,CI lst,CI cl)
  44. {
  45. if (!~nw) return data(1,0); if (!cl&&~f[nw][lst]) return f[nw][lst];
  46. data ret(0,0); int lim=cl?a[nw]:9; for (RI i=0;i<=lim;++i)
  47. {
  48. data nxt=MDFS(nw-1,i,cl&&(i==a[nw]));
  49. inc(ret.num,nxt.num); inc(ret.sum,nxt.sum);
  50. if (i!=lst) inc(ret.sum,1LL*i*pw[nw]%mod*nxt.num%mod);
  51. }
  52. if (cl) return ret; return f[nw][lst]=ret;
  53. }
  54. signed main()
  55. {
  56. //freopen("CODE.in","r",stdin); freopen("CODE.out","w",stdout);
  57. RI i,j; for (pw[0]=i=1;i<N;++i) pw[i]=10LL*pw[i-1]%mod;
  58. for (F.read(t);t;--t)
  59. {
  60. for (F.read(n),i=n-1;~i;--i)
  61. F.get_digit(ch),a[i]=ch&15;
  62. for (--a[i=0];a[i]<0;++i) a[i]+=10,--a[i+1];
  63. if (!a[n-1]) --n; for (i=0;i<=n;++i) for (j=0;j<10;++j)
  64. f[i][j]=data(); int dlt=MDFS(n-1,0,1).sum;
  65. for (F.read(n),i=n-1;~i;--i)
  66. F.get_digit(ch),a[i]=ch&15;
  67. for (i=0;i<=n;++i) for (j=0;j<10;++j)
  68. f[i][j]=data(); int ret=MDFS(n-1,0,1).sum;
  69. printf("%d\n",(ret-dlt+mod)%mod);
  70. }
  71. return 0;
  72. }

G Chef and Gordon Ramsay

首先有一个很套路的统计方法,我们考虑将每个点作为中间点时计算答案

那么我们分类讨论一下三种情况,发现其实只需要统计出子树内小于(大于)它的数的个数和子树外小于(大于)它的数的个数

子树内我们套路的线段树合并一下就能求出来了,然后减一减就得到了外面的,将方案乘起来就好了

注意中间点为\(1\)或\(3\)时算点对要除以\(2\)

  1. #include<cstdio>
  2. #include<cctype>
  3. #define RI register int
  4. #define CI const int&
  5. #define Tp template <typename T>
  6. using namespace std;
  7. const int N=100005;
  8. struct edge
  9. {
  10. int to,nxt;
  11. }e[N<<1]; int t,head[N],n,p1,p2,p3,cnt,x,y,rt[N]; long long ans;
  12. class FileInputOutput
  13. {
  14. private:
  15. static const int S=1<<21;
  16. #define tc() (A==B&&(B=(A=Fin)+fread(Fin,1,S,stdin),A==B)?EOF:*A++)
  17. char Fin[S],*A,*B;
  18. public:
  19. Tp inline void read(T& x)
  20. {
  21. x=0; char ch; while (!isdigit(ch=tc()));
  22. while (x=(x<<3)+(x<<1)+(ch&15),isdigit(ch=tc()));
  23. }
  24. #undef tc
  25. }F;
  26. inline void addedge(CI x,CI y)
  27. {
  28. e[++cnt]=(edge){y,head[x]}; head[x]=cnt;
  29. e[++cnt]=(edge){x,head[y]}; head[y]=cnt;
  30. }
  31. class Segment_Tree
  32. {
  33. private:
  34. static const int P=20;
  35. struct segment
  36. {
  37. int ch[2],sum;
  38. }node[N*P<<1]; int tot;
  39. public:
  40. #define TN CI l=1,CI r=n
  41. #define LS l,mid
  42. #define RS mid+1,r
  43. #define lc(x) node[x].ch[0]
  44. #define rc(x) node[x].ch[1]
  45. #define S(x) node[x].sum
  46. inline void insert(int& now,CI pos,TN)
  47. {
  48. if (!now) now=++tot; ++S(now); if (l==r) return; int mid=l+r>>1;
  49. if (pos<=mid) insert(lc(now),pos,LS); else insert(rc(now),pos,RS);
  50. }
  51. inline int merge(CI x,CI y,TN)
  52. {
  53. if (!x||!y) return x|y; int now=++tot; S(now)=S(x)+S(y);
  54. if (l==r) return now; int mid=l+r>>1;
  55. lc(now)=merge(lc(x),lc(y),LS); rc(now)=merge(rc(x),rc(y),RS); return now;
  56. }
  57. inline int query(CI now,CI beg,CI end,TN)
  58. {
  59. if (!now) return 0; if (beg<=l&&r<=end) return S(now);
  60. int mid=l+r>>1,ret=0; if (beg<=mid) ret+=query(lc(now),beg,end,LS);
  61. if (end>mid) ret+=query(rc(now),beg,end,RS); return ret;
  62. }
  63. inline void clear(void)
  64. {
  65. for (RI i=1;i<=tot;++i) lc(i)=rc(i)=S(i)=0; tot=0;
  66. }
  67. #undef TN
  68. #undef LS
  69. #undef RS
  70. #undef lc
  71. #undef rc
  72. }SEG;
  73. #define to e[i].to
  74. inline void DFS(CI now=1,CI fa=0)
  75. {
  76. RI i; SEG.insert(rt[now],now); for (i=head[now];i;i=e[i].nxt)
  77. if (to!=fa) DFS(to,now),rt[now]=SEG.merge(rt[now],rt[to]);
  78. if (p2==1)
  79. {
  80. int mxnum=SEG.query(rt[now],now+1,n); long long ret=0;
  81. for (i=head[now];i;i=e[i].nxt) if (to!=fa)
  82. {
  83. int cur=SEG.query(rt[to],now+1,n);
  84. ret+=1LL*cur*(mxnum-cur);
  85. }
  86. ans+=(ret>>1LL)+1LL*mxnum*(n-now-mxnum);
  87. } else if (p2==2)
  88. {
  89. int mxnum=SEG.query(rt[now],now+1,n),minum=SEG.query(rt[now],1,now-1);
  90. for (i=head[now];i;i=e[i].nxt) if (to!=fa)
  91. ans+=1LL*SEG.query(rt[to],now+1,n)*(minum-SEG.query(rt[to],1,now-1));
  92. ans+=1LL*mxnum*(now-1-minum); ans+=1LL*minum*(n-now-mxnum);
  93. } else
  94. {
  95. int minum=SEG.query(rt[now],1,now-1); long long ret=0;
  96. for (i=head[now];i;i=e[i].nxt) if (to!=fa)
  97. {
  98. int cur=SEG.query(rt[to],1,now-1);
  99. ret+=1LL*cur*(minum-cur);
  100. }
  101. ans+=(ret>>1LL)+1LL*minum*(now-1-minum);
  102. }
  103. }
  104. #undef to
  105. int main()
  106. {
  107. //freopen("CODE.in","r",stdin); freopen("CODE.out","w",stdout);
  108. for (F.read(t);t;--t)
  109. {
  110. RI i; F.read(n); F.read(p1); F.read(p2); F.read(p3);
  111. for (ans=0,i=1;i<n;++i) F.read(x),F.read(y),addedge(x,y);
  112. for (DFS(),printf("%lld\n",ans),cnt=0,i=1;i<=n;++i) head[i]=0;
  113. for (SEG.clear(),i=1;i<=n;++i) rt[i]=0;
  114. }
  115. return 0;
  116. }

Postscript

讲道理Div2的题目还是偏简单的,全部做下来两三个小时就好了

希望到时候打Div1别被完虐吧QWQ

Codechef August Challenge 2019 Division 2的更多相关文章

  1. Codechef November Challenge 2019 Division 1

    Preface 这场CC好难的说,后面的都不会做QAQ 还因为不会三进制位运算卷积被曲明姐姐欺负了,我真是太菜了QAQ PS:最后还是狗上了六星的说,期待两(三)场之内可以上七星 Physical E ...

  2. Codechef October Challenge 2019 Division 1

    Preface 这次CC难度较上两场升高了许多,后面两题都只能借着曲明姐姐和jz姐姐的仙气来做 值得一提的是原来的F大概需要大力分类讨论,结果我写了一大半题目就因为原题被ban了233 最后勉强涨了近 ...

  3. Codechef September Challenge 2019 Division 2

    Preface 这确实应该是我打过的比较水的CC了(其实就打过两场) 但由于我太弱了打的都是Div2,所以会认为上一场更简单,其实上一场Div的数据结构是真的毒 好了废话不多说快速地讲一下 A Eas ...

  4. Codechef April Challenge 2019 Division 2

    Maximum Remaining 题意:给n个数,取出两个数$a_{i}$,$a_{j}$,求$a_{i}\% a_{j}$取模的最大值 直接排个序,第二大(严格的第二大)模第一大就是答案了. #i ...

  5. Codechef August Challenge 2019 Chef and Gordon Ramsay

    [传送门] 题目即求所有的三元组,相对大小关系同 $p_1,p_2,p_3$. 题解说都很清楚,这里写一下过程整理一下思路. 如果我们枚举中间这个元素,那么就是统计子树内外有多少个大于这个数和小于这个 ...

  6. CodeChef November Challenge 2019 Division 1题解

    传送门 AFO前的最后一场CC了--好好打吧-- \(SIMGAM\) 偶数行的必定两人平分,所以只要抢奇数行中间那个就行了 这题怎么被爆破了 //quming #include<bits/st ...

  7. Codechef July Challenge 2019 Division 1题解

    题面 \(CIRMERGE\) 破环成链搞个裸的区间\(dp\)就行了 //quming #include<bits/stdc++.h> #define R register #defin ...

  8. Codechef April Challenge 2019 游记

    Codechef April Challenge 2019 游记 Subtree Removal 题目大意: 一棵\(n(n\le10^5)\)个结点的有根树,每个结点有一个权值\(w_i(|w_i\ ...

  9. 【CodeChef】August Challenge 2019 Div2 解题报告

    点此进入比赛 \(T1\):Football(点此看题面) 大致题意: 求\(max(20a_i-10b_i,0)\). 送分题不解释. #include<bits/stdc++.h> # ...

随机推荐

  1. 安装docker后修改docker文件目录

    docker会下载容器,运行会挂载磁盘,所以我们需要把docker装在大容量的分区. 安装 https://docs.docker.com/install/linux/docker-ce/centos ...

  2. Focal Loss tensorflow 实现

    def focal_loss(pred, y, alpha=0.25, gamma=2): r"""Compute focal loss for predictions. ...

  3. Layui新手教程----帮助小白少走弯路

    Layui的学习 Layui官方文档:https://www.layui.com/ 先说说为啥我接触到了layui,因为需要去参与做一个项目,被学长推荐去学习layui,用来处理一些前端的问题. La ...

  4. WPF Adorner 简易图片取色器

    回答MSDN问题所写. 使用Adorner+附加属性 图片类(来自这位博主的博客) /// <summary> /// 用于获取位图像素的类 /// </summary> pu ...

  5. Windows 任务调度程序定时执行Python脚本

    Windows 任务调度程序(Task Scheduler)可以定时执行程序,本文分享使用Task Scheduler定时执行Python脚本的两种方法. 在控制面版->管理员工具中打开 Tas ...

  6. SkyWalking分布式链路追踪和监控-项目实战

    微服务框架落地后,分布式部署架构带来的问题就会迅速凸显出来.服务之间的相互调用过程中,如果业务出现错误或者异常,如何快速定位问题?如何跟踪业务调用链路?如何分析解决业务瓶颈?本专栏将引入Skywalk ...

  7. Winform中对DevExpress的RadopGroup的Description、Value、Tag、Text的理解与使用

    场景 Winform中实现读取xml配置文件并动态配置ZedGraph的RadioGroup的选项: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article ...

  8. 自己动手搭建经典的3层 Asp.Net MVC

    1:IBaseDAL using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expr ...

  9. ios浏览器调试踩坑(1)----mescroll.js和vue-scroller

    主要记录在ios浏览器出现触摸无限加载的情况 使用vue-scroller和mescroll.js/mescroll.vue先踩ios浏览器默认滑动会影响mescroll的方法调用. 首先给公共js加 ...

  10. SQLi-LABS Page-2 (Adv Injections) Less23-Less26

    Less-23 GET - Error based - strip comments http://10.10.202.112/sqli/Less-23?id=1' Warning: mysql_fe ...