#
  用  户  名  公园 计划 抽卡   总分 
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. HTML5 Notification

    H5的Notification特性 Web桌面通知 Notification API的通知接口用于向用户配置和显示桌面通知. 生产环境仅支持https下使用:否则会被默认禁止.开发环境可以在local ...

  2. Shiro简介、入门案例、web容器的集成

    目的: shiro简介 Shiro入门案例 Shiro与web容器的集成 shiro简介(中文官网:https://www.w3cschool.cn/shiro/andc1if0.html) 1.什么 ...

  3. C#7 进入快速迭代道路

    out变量 有一定C#编程经历的园友一定没少写如下这样的代码: int speed; if (int.TryParse(speedStr, out speed)) speed*=; 注释:int.Tr ...

  4. hdu 2616 暴力使用 dfs求最短路径(剪枝有点依稀)

    Kill the monster Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. Java源码阅读之ArrayList

    基于jdk1.8的ArrayList源码分析. 实现List接口最常见的大概就四种,ArrayList, LinkedList, Vector, Stack实现,今天就着重看一下ArrayList的源 ...

  6. 在浏览器输入URL回车后发生了什么?

    本文由 简悦 SimpRead 转码, 原文地址 https://4ark.me/post/b6c7c0a2.html 这个问题已经是老生常谈了,更是经常被作为面试的压轴题出现,网上也有很多文章,但最 ...

  7. Java 之 网络编程基础

    一.软件结构 C/S 结构:全称为 Client/Server 结构,是指客户端和服务器结构.常见的程序有微信,QQ,迅雷等软件. B/S 结构:全称 Brower/Server 结构,是指浏览器和服 ...

  8. Java虚拟机(五):JVM 类加载机制

    一.JVM 类加载机制 JVM 类加载机制分为五个部分:加载,验证,准备,解析,初始化,下面我们就分别来看一下这五个过程. 1. 加载: 加载是类加载过程中的第一个阶段,这个阶段会在内存中生成一个代表 ...

  9. bootstrap tab选项卡

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  10. JAVA中使用递归和尾递归实现1000的阶乘的比较

    在JAVA中求阶乘首先遇到的问题就是结果溢出,不管是使用int还是long,double都无法表示1000!这么大的天文数字,这里暂且用BigInteger解决这个问题! 下面是使用递归和尾递归分别计 ...