简化题意:区间众数出现次数???

为什么?原因是,贪心的想,我们要划分成尽量少的严格递增序列,这样rp掉的最少。

设区间众数出现次数为 \(x\) ,那我们至少要分成 \(x\) 段严格上升序列。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define R register int
using namespace std;
namespace Luitaryi {
inline int g() { R x=0,f=1;
register char s; while(!isdigit(s=getchar())) f=s=='-'?-1:f;
do x=x*10+(s^48); while(isdigit(s=getchar())); return x*f;
} const int N=200010;
int n,m,B,anss;
int a[N],b[N],c[N],d[N],ans[N],pos[N];
struct node {int l,r,id;
inline bool operator < (const node& that) const
{return pos[l]==pos[that.l]?pos[l]&1?r<that.r:r>that.r:l<that.l;}
}q[N];
inline void add(int x) {
if(anss==c[x]&&d[c[x]+1]==0) ++anss;
--d[c[x]],++c[x],++d[c[x]];
}
inline void sub(int x) {
if(anss==c[x]&&d[c[x]]==1) --anss;
--d[c[x]],--c[x],++d[c[x]];
}
inline void main() {
n=g(),m=g(); B=sqrt(n);
for(R i=1;i<=n;++i) a[i]=g();
memcpy(b,a,sizeof b),sort(b+1,b+n+1);
R tot=unique(b+1,b+n+1)-b;
for(R i=1;i<=n;++i) a[i]=lower_bound(b+1,b+tot+1,a[i])-b-1;
for(R i=1;i<=m;++i) q[i].l=g(),q[i].r=g(),q[i].id=i;
for(R i=1;i<=m;++i) pos[i]=(i-1)/B+1;
sort(q+1,q+m+1); d[0]=n;
for(R i=1,l=1,r=0,LL,RR,id;i<=m;++i) {
LL=q[i].l,RR=q[i].r,id=q[i].id;
while(l<LL) sub(a[l++]);
while(l>LL) add(a[--l]);
while(r<RR) add(a[++r]);
while(r>RR) sub(a[r--]);
ans[id]=anss;
} for(R i=1;i<=m;++i) printf("%d\n",-ans[i]);
}
} signed main() {Luitaryi::main(); return 0;}

2019.11.23

最新文章

  1. Ceph RGW服务 使用s3 java sdk 分片文件上传API 报‘SignatureDoesNotMatch’ 异常的定位及规避方案
  2. C#测试运行时间
  3. OAuth认证
  4. Myeclipse8.5 最新注册码以使用方法(可以用到2015年!!!)
  5. 查看Linux内核版本命令
  6. 傅里叶变换:MP3、JPEG和Siri背后的数学
  7. Codeforces Round #Pi (Div. 2) E. President and Roads 最短路+桥
  8. bzoj2241: [SDOI2011]打地鼠
  9. 检测目标程序ELF bit是32还是64
  10. BZOJ 1072 [SCOI2007]排列perm
  11. java下socket传文件
  12. “String.h” 源代码总结
  13. 利用反射机制设计Dao
  14. 一种解决eclipse中安装maven出错的方法
  15. 特殊需求:EF 6.x如何比较TimeSpan格式的字符串?EF Core实现方式是否和EF 6.x等同?
  16. Spring MVC 使用介绍(七)—— 注解式控制器(三):生产者与消费者模型
  17. 感言&amp;3
  18. 消息队列之RabbitMQ的.Net客户端EasyNetQ
  19. 学习Oracle的一些收获
  20. slub分配器

热门文章

  1. Fedora30 - Xrdp 远程桌面
  2. python学习-68 反射
  3. 转 Html转pdf的工具——wkhtmltopdf
  4. Java调用WebService方法总结(3)--wsimport调用WebService
  5. 作为消费者访问提供者提供的功能(eureka的铺垫案例)
  6. R_基本统计分析_06
  7. Fortify漏洞之Insecure Randomness(不安全随机数)
  8. SIM900 HTTP POST
  9. keychain不能导出p12证书的解决方法
  10. jenkens + github