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

03:15:05
40

03:14:01
  140

03:15:05

emm

怎么讲

  T2我把自己优化掉了40分

优化前:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define cin(a) scanf("%d",&a)
using namespace std;
const int maxn=1e5+5;
int dui[maxn],siz,now,last;
int a[maxn];
int m,n,qu;
int ri[maxn];
int len[maxn];
int sum[maxn];
long long ans[maxn];
struct node{
int l,r,k;
}t[maxn];
__attribute((always_inline))int h233(const node &a,const node &b)
{return a.r==b.r?a.l<b.l:a.r<b.r;}
int main()
{
// freopen("ans.in","r",stdin);
// freopen("a.out","w",stdout);
cin(n),cin(m),cin(qu);
for(int q=1;q<=n;q++)
cin>>a[q];
for(int q=1;q<=n;q++)
{
while(siz<m&&now<n)
{
++now;
if(!dui[a[now]])
++siz;
++dui[a[now]];
}
if(siz>=m)
ri[q]=now;
else
{
last=q;
break;
}
dui[a[q]]--;
if(!dui[a[q]])
--siz;
}
/*for(int q=1;q<=last;q++)
cout<<ri[q]<<" ";
cout<<endl;*/
/*for(int q=1;q<=qu;q++)
{
cin(t[q].l),cin(t[q].r),t[q].k=q;
}
sort(t+1,t+qu+1,h233);*/
/*for(int q=1;q<=qu;q++)
cout<<t[q].l<<" "<<t[q].r<<endl;*/
for(int q=1,x,y;q<=qu;q++)
{
cin(x),cin(y);
long long ans=0;
for(int w=x;w<=y;w++)
{
//cout<<w<<" "<<y<<" "<<(ri[w]+y-2*w)*(y-ri[w]+1)/2<<endl;
ans+=max(0,(ri[w]+y-2*w)*(y-ri[w]+1)/2);
}
cout<<ans<<endl;
}
/*
int tmp=0;
for(int q=1;q<=qu;q++)
{
if(tmp==t[q].r)
ans[t[q].k]=sum[t[q].l];
else
{
//cout<<t[q].l<<" "<<t[q].r<<endl;
sum[t[q].r+1]=0;
for(int w=t[q].r;w>=t[q].l;w--)
sum[w]=sum[w+1]+max(0,(ri[w]+t[q].r-2*w)*(t[q].r-ri[w]+1)/2);
tmp=t[q].r;
ans[t[q].k]=sum[t[q].l];
for(int w=t[q].l;w<=t[q].r;w++)
cout<<sum[w]<<" ";
cout<<endl<<endl;
}
}*/
/*for(int q=1;q<=qu;q++)
cout<<ans[q]<<endl;*/
}

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

 $n\leq10000$,$q\leq10000$

 时限2s

 可以过的对吧

 然而我忘了时限是2s

 强行玄学优化:

 

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define cin(a) scanf("%d",&a)
using namespace std;
const int maxn=1e5+5;
int dui[maxn],siz,now,last;
int a[maxn];
int m,n,qu;
int ri[maxn];
int len[maxn];
int sum[maxn];
long long ans[maxn];
struct node{
int l,r,k;
}t[maxn];
__attribute((always_inline))int h233(const node &a,const node &b)
{return a.r==b.r?a.l<b.l:a.r<b.r;}
int main()
{
// freopen("ans.in","r",stdin);
// freopen("a.out","w",stdout);
cin(n),cin(m),cin(qu);
for(int q=1;q<=n;q++)
cin>>a[q];
for(int q=1;q<=n;q++)
{
while(siz<m&&now<n)
{
++now;
if(!dui[a[now]])
++siz;
++dui[a[now]];
}
if(siz>=m)
ri[q]=now;
else
{
last=q;
break;
}
dui[a[q]]--;
if(!dui[a[q]])
--siz;
}
/*for(int q=1;q<=last;q++)
cout<<ri[q]<<" ";
cout<<endl;*/
for(int q=1;q<=qu;q++)
{
cin(t[q].l),cin(t[q].r),t[q].k=q;
}
sort(t+1,t+qu+1,h233);
/*for(int q=1;q<=qu;q++)
cout<<t[q].l<<" "<<t[q].r<<endl;*/
/*for(int q=1,x,y;q<=qu;q++)
{
cin(x),cin(y);
long long ans=0;
for(int w=x;w<=y;w++)
{
//cout<<w<<" "<<y<<" "<<(ri[w]+y-2*w)*(y-ri[w]+1)/2<<endl;
ans+=max(0,(ri[w]+y-2*w)*(y-ri[w]+1)/2);
}
cout<<ans<<endl;
}*/
int tmp=0;
for(int q=1;q<=qu;q++)
{
if(tmp==t[q].r)
ans[t[q].k]=sum[t[q].l];
else
{
//cout<<t[q].l<<" "<<t[q].r<<endl;
sum[t[q].r+1]=0;
for(int w=t[q].r;w>=t[q].l;w--)
sum[w]=sum[w+1]+max(0,(ri[w]+t[q].r-2*w)*(t[q].r-ri[w]+1)/2);
tmp=t[q].r;
ans[t[q].k]=sum[t[q].l];
/*for(int w=t[q].l;w<=t[q].r;w++)
cout<<sum[w]<<" ";
cout<<endl<<endl;*/
}
}
for(int q=1;q<=qu;q++)
cout<<ans[q]<<endl;
}

 于是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. JVM内存管理(一)--GC简介

    GC策略解决了哪些问题?  既然是要进行自动GC,那必然会有相应的策略,而这些策略解决了哪些问题呢,粗略的来说,主要有以下几点.         1.哪些对象可以被回收.         2.何时回收 ...

  2. GXOI/GZOI2019部分题解

    D1T1:与或和 对每位处理,问题变成所有内部不包含0/1的矩阵的个数,单调栈维护即可. #include<cstdio> #include<algorithm> #inclu ...

  3. Educational Codeforces Round 61 (Div.2)

    A.(c1=0&&c3>0)||(c1!=c4) #include<cstdio> #include<cstring> #include<algor ...

  4. Eclipse下使用Maven创建项目出现的archetype错误,记,转

    记自:http://blog.csdn.net/ZhuboSun/article/details/50099635 [1]出现的错误提示: Unable to create project from ...

  5. linux 系统运维工具13款

    1. 查看进程占用带宽情况 - Nethogs Nethogs 是一个终端下的网络流量监控工具可以直观的显示每个进程占用的带宽. 下载:http://sourceforge.net/projects/ ...

  6. 你听过稀疏数组(sparseArray)吗?

    稀疏数组(sparseArray) 基本介绍 当一个数组中大部分元素为0,或者为同一个值的数组时,可以使用稀疏数组来保存该数组. 稀疏数组的处理方法是: 1.记录数组一共有几行几列,有多少个不同的值 ...

  7. OS X系统特有文件目录说明

    os x特有的目录 OS X系统中,除了标准的unix目录外,还增加了特有的目录. /Applications 应用程序目录,默认所有的GUI应用程序都安装在这里: /Library 系统的数据文件. ...

  8. Django-cms show_menu参数解释

    当页面结构设置(/admin/cms/page)如下: - Home (level=0) - About Us (level=1) - About Company Services (level=2) ...

  9. python day3 int,str,list类型补充

    目录 python day 3 1. int类小知识点 2. str类小知识点 3. list类小知识点 python day 3 (学习资料来自老男孩教育) 2019/10/06 1. int类小知 ...

  10. 只需五分钟-用Maven快速搭建Spring Cloud微服务

    Maven安装手册 1.准备安装包 安装包: apache-maven-3.5.4-bin.zip  (最好JDK 1.7及以上版本) 集成包: eclipse-maven3-plugin.zip 2 ...