#
  用  户  名  公园 计划 抽卡   总分 
19
859乔屹 100

03:15:05
40

03:14:01
  140

03:15:05

emm

怎么讲

  T2我把自己优化掉了40分

优化前:

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cmath>
  5. #define cin(a) scanf("%d",&a)
  6. using namespace std;
  7. const int maxn=1e5+5;
  8. int dui[maxn],siz,now,last;
  9. int a[maxn];
  10. int m,n,qu;
  11. int ri[maxn];
  12. int len[maxn];
  13. int sum[maxn];
  14. long long ans[maxn];
  15. struct node{
  16. int l,r,k;
  17. }t[maxn];
  18. __attribute((always_inline))int h233(const node &a,const node &b)
  19. {return a.r==b.r?a.l<b.l:a.r<b.r;}
  20. int main()
  21. {
  22. // freopen("ans.in","r",stdin);
  23. // freopen("a.out","w",stdout);
  24. cin(n),cin(m),cin(qu);
  25. for(int q=1;q<=n;q++)
  26. cin>>a[q];
  27. for(int q=1;q<=n;q++)
  28. {
  29. while(siz<m&&now<n)
  30. {
  31. ++now;
  32. if(!dui[a[now]])
  33. ++siz;
  34. ++dui[a[now]];
  35. }
  36. if(siz>=m)
  37. ri[q]=now;
  38. else
  39. {
  40. last=q;
  41. break;
  42. }
  43. dui[a[q]]--;
  44. if(!dui[a[q]])
  45. --siz;
  46. }
  47. /*for(int q=1;q<=last;q++)
  48. cout<<ri[q]<<" ";
  49. cout<<endl;*/
  50. /*for(int q=1;q<=qu;q++)
  51. {
  52. cin(t[q].l),cin(t[q].r),t[q].k=q;
  53. }
  54. sort(t+1,t+qu+1,h233);*/
  55. /*for(int q=1;q<=qu;q++)
  56. cout<<t[q].l<<" "<<t[q].r<<endl;*/
  57. for(int q=1,x,y;q<=qu;q++)
  58. {
  59. cin(x),cin(y);
  60. long long ans=0;
  61. for(int w=x;w<=y;w++)
  62. {
  63. //cout<<w<<" "<<y<<" "<<(ri[w]+y-2*w)*(y-ri[w]+1)/2<<endl;
  64. ans+=max(0,(ri[w]+y-2*w)*(y-ri[w]+1)/2);
  65. }
  66. cout<<ans<<endl;
  67. }
  68. /*
  69. int tmp=0;
  70. for(int q=1;q<=qu;q++)
  71. {
  72. if(tmp==t[q].r)
  73. ans[t[q].k]=sum[t[q].l];
  74. else
  75. {
  76. //cout<<t[q].l<<" "<<t[q].r<<endl;
  77. sum[t[q].r+1]=0;
  78. for(int w=t[q].r;w>=t[q].l;w--)
  79. sum[w]=sum[w+1]+max(0,(ri[w]+t[q].r-2*w)*(t[q].r-ri[w]+1)/2);
  80. tmp=t[q].r;
  81. ans[t[q].k]=sum[t[q].l];
  82. for(int w=t[q].l;w<=t[q].r;w++)
  83. cout<<sum[w]<<" ";
  84. cout<<endl<<endl;
  85. }
  86. }*/
  87. /*for(int q=1;q<=qu;q++)
  88. cout<<ans[q]<<endl;*/
  89. }

 显然是$\Theta (n+qn)$的

 $n\leq10000$,$q\leq10000$

 时限2s

 可以过的对吧

 然而我忘了时限是2s

 强行玄学优化:

 

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cmath>
  5. #define cin(a) scanf("%d",&a)
  6. using namespace std;
  7. const int maxn=1e5+5;
  8. int dui[maxn],siz,now,last;
  9. int a[maxn];
  10. int m,n,qu;
  11. int ri[maxn];
  12. int len[maxn];
  13. int sum[maxn];
  14. long long ans[maxn];
  15. struct node{
  16. int l,r,k;
  17. }t[maxn];
  18. __attribute((always_inline))int h233(const node &a,const node &b)
  19. {return a.r==b.r?a.l<b.l:a.r<b.r;}
  20. int main()
  21. {
  22. // freopen("ans.in","r",stdin);
  23. // freopen("a.out","w",stdout);
  24. cin(n),cin(m),cin(qu);
  25. for(int q=1;q<=n;q++)
  26. cin>>a[q];
  27. for(int q=1;q<=n;q++)
  28. {
  29. while(siz<m&&now<n)
  30. {
  31. ++now;
  32. if(!dui[a[now]])
  33. ++siz;
  34. ++dui[a[now]];
  35. }
  36. if(siz>=m)
  37. ri[q]=now;
  38. else
  39. {
  40. last=q;
  41. break;
  42. }
  43. dui[a[q]]--;
  44. if(!dui[a[q]])
  45. --siz;
  46. }
  47. /*for(int q=1;q<=last;q++)
  48. cout<<ri[q]<<" ";
  49. cout<<endl;*/
  50. for(int q=1;q<=qu;q++)
  51. {
  52. cin(t[q].l),cin(t[q].r),t[q].k=q;
  53. }
  54. sort(t+1,t+qu+1,h233);
  55. /*for(int q=1;q<=qu;q++)
  56. cout<<t[q].l<<" "<<t[q].r<<endl;*/
  57. /*for(int q=1,x,y;q<=qu;q++)
  58. {
  59. cin(x),cin(y);
  60. long long ans=0;
  61. for(int w=x;w<=y;w++)
  62. {
  63. //cout<<w<<" "<<y<<" "<<(ri[w]+y-2*w)*(y-ri[w]+1)/2<<endl;
  64. ans+=max(0,(ri[w]+y-2*w)*(y-ri[w]+1)/2);
  65. }
  66. cout<<ans<<endl;
  67. }*/
  68. int tmp=0;
  69. for(int q=1;q<=qu;q++)
  70. {
  71. if(tmp==t[q].r)
  72. ans[t[q].k]=sum[t[q].l];
  73. else
  74. {
  75. //cout<<t[q].l<<" "<<t[q].r<<endl;
  76. sum[t[q].r+1]=0;
  77. for(int w=t[q].r;w>=t[q].l;w--)
  78. sum[w]=sum[w+1]+max(0,(ri[w]+t[q].r-2*w)*(t[q].r-ri[w]+1)/2);
  79. tmp=t[q].r;
  80. ans[t[q].k]=sum[t[q].l];
  81. /*for(int w=t[q].l;w<=t[q].r;w++)
  82. cout<<sum[w]<<" ";
  83. cout<<endl<<endl;*/
  84. }
  85. }
  86. for(int q=1;q<=qu;q++)
  87. cout<<ans[q]<<endl;
  88. }

 于是WA40了

 以此铭记:

在打题之前,我们一定要看清时限

 以上

exam9.3的更多相关文章

  1. exam9.6&&7

    emmm 改题稍紧张,以后几篇并一起写 9.6 (前十并没有参加本次考试) 于是我就rank8了 一道题一道题来 先说T1: 显然是一个高精度GCD,于是打算用计算器算一下时间复杂度 众所周知gcd是 ...

  2. 【Mysql优化】索引覆盖

    索引覆盖 是指 如果查询的列恰好是索引的一部分,那么查询只需要在索引文件上进行,不需要回行到磁盘再找数据.这种查询速度非常快,称为”索引覆盖”,比平时的查询少一次到磁盘读数据的操作.(索引正好覆盖到查 ...

  3. 【Mysql优化】索引碎片与维护

    在长期的数据更改过程中, 索引文件和数据文件,都将产生空洞,形成碎片.(不停的删除修改导致) 解决办法: (1)我们可以通过一个nop操作(不产生对数据实质影响的操作), 来修改表. 比如: 表的引擎 ...

  4. MySQL导出数据库、数据库表结构、存储过程及函数【用】

    一.导出数据库 我的mysql安装目录是D:\Program Files\MySQL\MySQL Server 5.5\bin\,导出文件预计放在D:\sql\ 在mysql的安装目录执行命令: my ...

  5. 【存储过程】MySQL存储过程/存储过程与自定义函数的区别

    ---------------------------存储过程-------------------- 语法: 创建存储过程: CREATE [definer = {user|current_user ...

随机推荐

  1. 二十一、RTC驱动

    一.RTC设备驱动分析 内核的rtc驱动位于内核drivers/rtc目录下,里面包含各个平台的RTC驱动.读者可在此目录下任意选择一个单板驱动文件进行分析,我选择的是rtc-davinci.c文件. ...

  2. Java定时任务工具详解之Timer篇

    Java定时任务调度工具详解 什么是定时任务调度? ◆ 基于给定的时间点,给定的时间间隔或者给定的执行次数自动执行的任务. 在Java中的定时调度工具? ◆ Timer       ◆Quartz T ...

  3. C# 微信消息模板 发送

    项目要用到微信提醒 ,加上调转到小程序页面,或者 指定url 用到  RestSharp.Senparc.Weixin 类库 一开始直接照着微信示例直接post进去 发现一直提示 47001  ,估计 ...

  4. windows下搭建nginx负载均衡

    学习笔记,第一次记录避免忘记 首先介绍一下本地环境是windows2008 R2-64位. 1.  到nginx官网上下载最新稳定版的安装包,http://nginx.org/en/download. ...

  5. js实现图片的Blob base64 ArrayBuffer 的各种转换

    一.相关基础知识 构造函数 FileReader() 返回一个新构造的FileReader 事件处理 FileReader.onabort  处理abort事件.该事件在读取操作被中断时触发. Fil ...

  6. Java 之 字符输入流[Reader]

    一.字符输入流 java.io.Reader 抽象类是表示用于读取字符流的所有类的超类,可以读取字符信息到内存中. 它定义了字符输入流的基本共性功能方法. public void close() :关 ...

  7. MongoDB 无法启动

    提示 mongodb Mongod complains that there is no /data/db folder!! 解决方法:http://stackoverflow.com/questio ...

  8. Flutter——Checkbox组件、CheckboxListTile(多选框组件)

    Checkbox组件 Checkbox组件常用的属性: 属性 描述 value true 或者 false onChanged 改变的时候触发的事件  activeColor 选中的颜色.背景颜色 c ...

  9. C++——同名隐藏 和 赋值兼容规则

    同名隐藏 一旦子类定义了与父类同名的方法,则父类里面该名字的所有方法都被隐藏了.必须显示指定是父类的方法才可以 #include<iostream> using namespace std ...

  10. Ubuntu apt-get锁定问题