这次的比赛真心水,考时估分240,然后各种悠闲乱逛

然后测完T1数组开小了炸成40,T2,T3都没开long long,T2炸成20,T3爆0

掉回1600+的深渊,但是还有CJJ dalao比我更惨,链接

T1

这道题就比较simple了,很显然用数据结构乱优化

貌似有很多种解法:单调队列,堆,线段树等等

我主要就讲一下我考试的时候YY出来的线段树

首先我们发现一个性质:对于n次操作之后,序列就进入循环

然后我们只需要处理处前n次询问就可以O(n)处理了

我们开一个前缀和记录原串中1的个数,然后设一个数组f[i]表示i左边k的长度范围内(包括它自己)一共有几个1(不足k也允许)

然后我们发现将一个数从尾部移到最前面,有两种情况:

  • 如果这个数是0,那么只需要把它自己的f[i]修改成0即可

  • 如果这个数是1,那么只需要把它自己的f[i]就改成1,并且把队头的前k-1项的f[]值加1

然后我们之间把初始数组右移n个长度(前面的为循环做准备),然后上线段树即可

然而我f数组忘记<<1了,而且那个字符串数组也看错了范围dog!!!

CODE

  1. #include<cstdio>
  2. #include<cstring>
  3. using namespace std;
  4. const int N=100005;
  5. struct segtree
  6. {
  7. int add,s;
  8. }tree[N<<3];
  9. int a[N],f[N<<1],sum[N],ans[N],n,k,q,tot;
  10. char s[N<<1];
  11. inline void read(int &x)
  12. {
  13. x=0; char ch=getchar();
  14. while (ch<'0'||ch>'9') ch=getchar();
  15. while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
  16. }
  17. inline void write(int x)
  18. {
  19. if (x/10) write(x/10);
  20. putchar(x%10+'0');
  21. }
  22. inline int max(int a,int b)
  23. {
  24. return a>b?a:b;
  25. }
  26. inline void up(int root)
  27. {
  28. tree[root].s=max(tree[root<<1].s,tree[root<<1|1].s);
  29. }
  30. inline void down(int root)
  31. {
  32. if (tree[root].add)
  33. {
  34. tree[root<<1].add+=tree[root].add;
  35. tree[root<<1|1].add+=tree[root].add;
  36. tree[root<<1].s+=tree[root].add;
  37. tree[root<<1|1].s+=tree[root].add;
  38. tree[root].add=0;
  39. }
  40. }
  41. inline void build(int root,int l,int r)
  42. {
  43. if (l==r)
  44. {
  45. tree[root].s=f[l];
  46. return;
  47. }
  48. int mid=l+r>>1;
  49. build(root<<1,l,mid); build(root<<1|1,mid+1,r);
  50. up(root);
  51. }
  52. inline void updata(int root,int l,int r,int id)
  53. {
  54. if (l==r)
  55. {
  56. tree[root].s=0;
  57. return;
  58. }
  59. int mid=l+r>>1;
  60. down(root);
  61. if (id<=mid) updata(root<<1,l,mid,id); else updata(root<<1|1,mid+1,r,id);
  62. up(root);
  63. }
  64. inline void modify(int root,int l,int r,int beg,int end)
  65. {
  66. if (l>=beg&&r<=end)
  67. {
  68. tree[root].s+=1; tree[root].add+=1;
  69. return;
  70. }
  71. int mid=l+r>>1;
  72. down(root);
  73. if (beg<=mid) modify(root<<1,l,mid,beg,end);
  74. if (end>mid) modify(root<<1|1,mid+1,r,beg,end);
  75. up(root);
  76. }
  77. int main()
  78. {
  79. //freopen("A.in","r",stdin); freopen("A.out","w",stdout);
  80. register int i;
  81. read(n); read(k); read(q);
  82. for (i=1;i<=n;++i)
  83. {
  84. read(a[i]); sum[i]=sum[i-1]+a[i];
  85. if (i>=k) f[i+n]=sum[i]-sum[i-k]; else f[i+n]=sum[i];
  86. }
  87. build(1,1,n<<1);
  88. ans[0]=tree[1].s;
  89. for (i=1;i<=n;++i)
  90. {
  91. updata(1,1,n<<1,(n<<1)-i+1);
  92. if (a[n-i+1]) modify(1,1,n<<1,n-i+1,n-i+k);
  93. ans[i]=tree[1].s;
  94. }
  95. for (scanf("%s",s+1),i=1;i<=q;++i)
  96. if (s[i]=='?') write(ans[tot]),putchar('\n'); else { if (++tot==n) tot=0; }
  97. return 0;
  98. }

T2

这题意一看就是暴力数据结构,然而我没开long long

我们通过观察发现2操作满足一个很凶猛的性质:前面的操作不会影响后面的操作

因此我们可以从前往后推一下,对于所有的操作2,将它操作的区间中的所有操作的次数+=目前这个操作的次数(默认为1)

然后最后我们得到了所有操作的次数,然后对于操作1上线段树 or 树状数组+差分即可

线段树CODE

  1. #include<cstdio>
  2. using namespace std;
  3. typedef long long LL;
  4. const LL N=100005,mod=1e9+7;
  5. struct time_segtree
  6. {
  7. LL add[N<<2],sum[N<<2];
  8. inline void up(LL root)
  9. {
  10. sum[root]=(sum[root<<1]+sum[root<<1|1])%mod;
  11. }
  12. inline void down(LL root,LL l,LL r)
  13. {
  14. if (add[root])
  15. {
  16. add[root<<1]=(add[root<<1]+add[root])%mod;
  17. add[root<<1|1]=(add[root<<1|1]+add[root])%mod;
  18. sum[root<<1]=(sum[root<<1]+add[root]*l)%mod;
  19. sum[root<<1|1]=(sum[root<<1|1]+add[root]*r)%mod;
  20. add[root]=0;
  21. }
  22. }
  23. inline void modify(LL root,LL l,LL r,LL beg,LL end,LL k)
  24. {
  25. if (l>=beg&&r<=end)
  26. {
  27. sum[root]=(sum[root]+k*(r-l+1))%mod;
  28. add[root]=(add[root]+k)%mod;
  29. return;
  30. }
  31. LL mid=l+r>>1;
  32. down(root,mid-l+1,r-mid);
  33. if (beg<=mid) modify(root<<1,l,mid,beg,end,k);
  34. if (end>mid) modify(root<<1|1,mid+1,r,beg,end,k);
  35. up(root);
  36. }
  37. inline LL query(LL root,LL l,LL r,LL id)
  38. {
  39. if (l==r) return sum[root];
  40. LL mid=l+r>>1;
  41. down(root,mid-l+1,r-mid);
  42. if (id<=mid) return query(root<<1,l,mid,id); else return query(root<<1|1,mid+1,r,id);
  43. }
  44. }T;
  45. struct ans_segtree
  46. {
  47. LL add[N<<2],sum[N<<2];
  48. inline void up(LL root)
  49. {
  50. sum[root]=(sum[root<<1]+sum[root<<1|1])%mod;
  51. }
  52. inline void down(LL root,LL l,LL r)
  53. {
  54. if (add[root])
  55. {
  56. add[root<<1]=(add[root<<1]+add[root])%mod;
  57. add[root<<1|1]=(add[root<<1|1]+add[root])%mod;
  58. sum[root<<1]=(sum[root<<1]+add[root]*l)%mod;
  59. sum[root<<1|1]=(sum[root<<1|1]+add[root]*r)%mod;
  60. add[root]=0;
  61. }
  62. }
  63. inline void modify(LL root,LL l,LL r,LL beg,LL end,LL k)
  64. {
  65. if (l>=beg&&r<=end)
  66. {
  67. sum[root]=(sum[root]+k*(r-l+1))%mod;
  68. add[root]=(add[root]+k)%mod;
  69. return;
  70. }
  71. LL mid=l+r>>1;
  72. down(root,mid-l+1,r-mid);
  73. if (beg<=mid) modify(root<<1,l,mid,beg,end,k);
  74. if (end>mid) modify(root<<1|1,mid+1,r,beg,end,k);
  75. up(root);
  76. }
  77. inline LL query(LL root,LL l,LL r,LL id)
  78. {
  79. if (l==r) return sum[root];
  80. LL mid=l+r>>1;
  81. down(root,mid-l+1,r-mid);
  82. if (id<=mid) return query(root<<1,l,mid,id); else return query(root<<1|1,mid+1,r,id);
  83. }
  84. }A;
  85. struct data
  86. {
  87. LL opt,x,y;
  88. }q[N];
  89. LL n,m;
  90. inline char tc(void)
  91. {
  92. static char fl[100000],*A=fl,*B=fl;
  93. return A==B&&(B=(A=fl)+fread(fl,1,100000,stdin),A==B)?EOF:*A++;
  94. }
  95. inline void read(LL &x)
  96. {
  97. x=0; char ch=tc();
  98. while (ch<'0'||ch>'9') ch=tc();
  99. while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=tc();
  100. }
  101. inline void write(LL x)
  102. {
  103. if (x/10) write(x/10);
  104. putchar(x%10+'0');
  105. }
  106. int main()
  107. {
  108. //freopen("B.in","r",stdin); freopen("B.out","w",stdout);
  109. register LL i;
  110. read(n); read(m);
  111. for (i=1;i<=m;++i)
  112. read(q[i].opt),read(q[i].x),read(q[i].y);
  113. for (i=m;i>=1;--i)
  114. {
  115. T.modify(1,1,m,i,i,1);
  116. if (q[i].opt==2) { LL x=T.query(1,1,m,i); T.modify(1,1,m,q[i].x,q[i].y,x); }
  117. }
  118. for (i=1;i<=m;++i)
  119. if (q[i].opt==1) { LL x=T.query(1,1,m,i); A.modify(1,1,n,q[i].x,q[i].y,x); }
  120. for (i=1;i<=n;++i)
  121. write(A.query(1,1,n,i)),putchar(' ');
  122. return 0;
  123. }

T3

比较玄学的卢卡斯定理乱推

反正我对这种数学的东西没什么兴趣,还是打打暴力好了

这里的暴力也比较有技巧,我们搞一下每一个点第x天的权值,记录下来,因为既可以用来推后面的,也可以用来O(1)求答案

40ptsCODE

  1. #include<cstdio>
  2. #include<cstring>
  3. using namespace std;
  4. typedef long long LL;
  5. const LL N=1005;
  6. struct edge
  7. {
  8. LL to,next;
  9. }e[N<<1];
  10. LL head[N],w[N][N],a[N],n,q,x,y,root,cnt,m;
  11. inline char tc(void)
  12. {
  13. static char fl[100000],*A=fl,*B=fl;
  14. return A==B&&(B=(A=fl)+fread(fl,1,100000,stdin),A==B)?EOF:*A++;
  15. }
  16. inline void read(LL &x)
  17. {
  18. x=0; char ch=tc();
  19. while (ch<'0'||ch>'9') ch=tc();
  20. while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=tc();
  21. }
  22. inline void write(LL x)
  23. {
  24. if (x/10) write(x/10);
  25. putchar(x%10+'0');
  26. }
  27. inline void add(LL x,LL y)
  28. {
  29. e[++cnt].to=y; e[cnt].next=head[x]; head[x]=cnt;
  30. }
  31. inline LL max(LL a,LL b)
  32. {
  33. return a>b?a:b;
  34. }
  35. inline void DFS(LL now,LL fa)
  36. {
  37. bool flag=1; register LL i,j;
  38. for (i=head[now];i!=-1;i=e[i].next)
  39. if (e[i].to!=fa)
  40. {
  41. flag=0;
  42. DFS(e[i].to,now);
  43. }
  44. if (flag) for (i=1;i<=m;++i) w[now][i]=w[now][0]; else
  45. {
  46. for (i=1;i<=m;++i)
  47. for (w[now][i]=w[now][i-1],j=head[now];j!=-1;j=e[j].next)
  48. if (e[j].to!=fa) w[now][i]^=w[e[j].to][i];
  49. }
  50. }
  51. int main()
  52. {
  53. //freopen("C.in","r",stdin); freopen("C.out","w",stdout);
  54. register LL i;
  55. memset(head,-1,sizeof(head));
  56. memset(e,-1,sizeof(e));
  57. read(n); read(q);
  58. for (i=1;i<n;++i)
  59. read(x),read(y),add(x,y),add(y,x);
  60. for (i=0;i<n;++i)
  61. read(w[i][0]);
  62. for (i=1;i<=q;++i)
  63. read(a[i]),m=max(m,a[i]);
  64. DFS(root,-1);
  65. for (i=1;i<=q;++i)
  66. write(w[root][a[i]]),putchar('\n');
  67. return 0;
  68. }

EZ 2018 05 13 NOIP2018 模拟赛(十三)的更多相关文章

  1. EZ 2018 05 26 NOIP2018 模拟赛(十六)

    这次难道就是传说中的标准分大赛?而且这次比赛的链接不翼而飞了 一堆人153pts然后就有Rank4?看来这个Rank4不值钱了,才涨了50+的Rating. 不过还好最后5min的时候想出了T1正解, ...

  2. EZ 2018 05 20 NOIP2018 模拟赛(十五)

    这次的比赛充满着玄学的气息,玄学链接 首先讲一下为什么没有第十四场 其实今天早上9点时看到题目就叫了:原题! 没错,整套试卷都做过,我还写了题解 然后老叶就说换一套,但如果仅仅是这样就没什么 但等13 ...

  3. EZ 2018 05 04 NOIP2018 模拟赛(十二)

    这次的试卷应该是激励我们一下的,链接 然后大家的分数就都很高,然后我就210被一群秒A T2的240大佬爆踩 掉了5rating但Rank竟然发杀了 X_o_r dalao && YZ ...

  4. EZ 2018 05 01 NOIP2018 模拟赛(十一)

    莫名其妙暴涨Rating 其实题目都挺好挺简单的,但是越简单就越容易ZZ 不理解问什么第一题这么多人找环 不过T2是真心细节题,T3太难了 题目戳这里 T1 仔细分析题意发现那个交换规则就是废话,如果 ...

  5. EZ 2018 04 13 NOIP2018 模拟赛(八)

    这次的题目都是什么鬼? 玄学乱搞+肉眼看CODE+倒着搜索? 好吧是我ZZ了 链接在此 T1 玄学乱搞 由于考场上写的部分分做法忘记讨论n<=2000时的情况,少得了30pts 很容易得到一个基 ...

  6. EZ 2018 06 17 NOIP2018 模拟赛(十九)

    这次的题目难得的水,但是由于许多哲学的原因,第二题题意表述很迷. 然后是真的猜题意了搞了. 不过这样都可以涨Rating我也是服了. Upt:链接莫名又消失了 A. 「NOIP2017模拟赛11.03 ...

  7. EZ 2018 06 10 NOIP2018 模拟赛(十八)

    好久没写blog&&比赛题解了,最近补一下 这次还是很狗的,T3想了很久最后竟然连并查集都忘写了,然后T2map莫名爆炸. Rating爆减......链接不解释 好了我们开始看题. ...

  8. EZ 2018 06 24 NOIP2018 模拟赛(二十)

    很久之前写的一套题了,由于今天的时间太多了,所以记起来就写掉算了. 这一场尽管T2写炸了,但也莫名Rank4涨了Rating.不过还是自己太菜. A. 环游世界 首先我们先排个序,想一下如果不用走回来 ...

  9. EZ 2018 06 02 NOIP2018 模拟赛(十七)

    这次的比赛是真心比较狗,我TM的写了30min的树剖ZZ地直接memset超时了 话说我既然想到差分就应该去写差分的啊! 好了不过这次Rank还挺高的,终于要打进前10了当然是假的了. 好了下面开始讲 ...

随机推荐

  1. 关于win10下JDK环境变量的配置以及关于JDK的一些说明

    一.JDK的下载和安装 这里提供32位和64位JDK的下载链接 百度网盘:https://pan.baidu.com/s/1xtiVOE2gPCvlGCTy0vfBaw 密码:c5m4   官网:ht ...

  2. Swagger使用教程 SwashbuckleEx

    一.前言 自从之前写了一篇<Webapi文档描述-swagger优化>这篇文章后,欠了大家一篇使用文档的说明,现在给大家补上哈. 二.环境 .Net Framework 4.5 WebAp ...

  3. LeetCode题解之 Binary Tree Preorder Traversal

    1.题目描述 2.问题分析 利用递归. 3.代码 vector<int> preorderTraversal(TreeNode* root) { vector<int> v; ...

  4. 利用windows的计划任务和eKing.CmdReadFileAndSendEmailOper(控制台小程序)实现远程登录服务器的邮件告警提醒

    一.场景摘要: 1.windows计划任务中,有一个用户登录时候触发的事件 2.cmd命令:netstat -ano   | find "3389" 可以看到当前远程登录的IP 3 ...

  5. TiDB数据库 mydumper命令导出数据报错:(mydumper:1908): CRITICAL **: Couldn't acquire global lock, snapshots will not be consistent: Access denied for user 'super'@'%' (using password: YES)

    今天想使用Tidb官方提供的mydumper来备份AWS上的RDS集群中mysql数据库的某个表,发现报错了 [tidb@:xxx /usr/local/tidb-tools]$ -t -F -B x ...

  6. [LOJ 6030]「雅礼集训 2017 Day1」矩阵

    [LOJ 6030] 「雅礼集训 2017 Day1」矩阵 题意 给定一个 \(n\times n\) 的 01 矩阵, 每次操作可以将一行转置后赋值给某一列, 问最少几次操作能让矩阵全为 1. 无解 ...

  7. 阿里八八Alpha阶段Scrum(3/12)

    今日进度 叶文滔: 实现了悬浮按钮的拖动. 问题困难:第三方库调入不成功,多级悬浮按钮的实现仍未完成. 刘晓: 完成注册.修改密码的UI部分,创建了注册Activity,修改密码Activity. 问 ...

  8. [python]如何理解uiautomator里面的 instance 及使用场景

    通过uiautomatorviewer打开之后,需要通过对某个控件进行操作,但在当前界面中该控件所有属性无法唯一(其它控件属性也是一样),这个时候就需要借助实例(instance)来进行区分,inst ...

  9. Jmeter函数助手中添加自定义函数

    最近,群里的牛肉面大神有个需求,是将每个post请求的body部分做一个加密操作,其实这个需求不算难,用beanshell引入加密函数的包,然后调用就行了.只是,如果请求多了,每次都要调用一下自己加密 ...

  10. PHP生成有背景的二维码图,摘自网络

    有一天产品MM高高兴兴的走过来,兴奋的和我分享她想出来的一个新的idea. 产品MM:你看这个(她指了指她的手机),一脸兴奋 那是一张带着二维码的图片,内容如下: 她接着说:如果我们的分销也能做成类似 ...