AC日记——大爷的字符串题 洛谷 P3709
思路:
莫队,需开O2,不开50;
代码:
#include <bits/stdc++.h>
using namespace std;
#define maxn 200005
int bel[maxn],blo;
struct QueryType {
int l,r,id;
bool operator<(const QueryType pos)const
{
if(bel[l]==bel[pos.l]) return r<pos.r;
else return bel[l]<bel[pos.l];
}
};
struct QueryType qu[maxn];
int num[maxn],cnt[maxn],ai[maxn],n,m;
int bi[maxn],size,ans[maxn],now;
inline void in(int &now)
{
char Cget=getchar();now=;
while(Cget>''||Cget<'') Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
}
inline void updata(int x,bool di)
{
x=ai[x];
if(di)
{
if(num[x]==now) now++;
cnt[num[x]]--,num[x]++,cnt[num[x]]++;
}
else
{
if(num[x]==now&&cnt[num[x]]==) now--;
cnt[num[x]]--,num[x]--,cnt[num[x]]++;
}
}
int main()
{
in(n),in(m),blo=sqrt(n);
for(int i=;i<=n;i++)
{
in(ai[i]);
bi[i]=ai[i];
bel[i]=(i+)/blo;
}
sort(bi+,bi+n+);
size=unique(bi+,bi+n+)-bi-;
for(int i=;i<=n;i++)ai[i]=lower_bound(bi+,bi+size+,ai[i])-bi;
for(int i=;i<=m;i++)in(qu[i].l),in(qu[i].r),qu[i].id=i;
sort(qu+,qu++m);int l=,r=;
for(int no=;no<=m;no++)
{
while(r<qu[no].r) updata(++r,true);
while(r>qu[no].r) updata(r--,false);
while(l>qu[no].l) updata(--l,true);
while(l<qu[no].l) updata(l++,false);
ans[qu[no].id]=now;
}
for(int i=;i<=m;i++) printf("%d\n",-ans[i]);
return ;
}
AC日记——大爷的字符串题 洛谷 P3709的更多相关文章
- AC日记——校门外的树 洛谷 P1047
题目描述 某校大门外长度为L的马路上有一排树,每两棵相邻的树之间的间隔都是1米.我们可以把马路看成一个数轴,马路的一端在数轴0的位置,另一端在L的位置:数轴上的每个整数点,即0,1,2,……,L,都种 ...
- AC日记——妖梦拼木棒 洛谷 P3799
妖梦拼木棒 思路: 神特么题: 代码: #include <bits/stdc++.h> using namespace std; #define mod 1000000007LL int ...
- AC日记——小B的询问 洛谷 P2709
小B的询问 思路: 水题: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 50005 #define ll ...
- AC日记——Car的旅行路线 洛谷 P1027
Car的旅行路线 思路: 这题不难,就是有点恶心: 而且,请认真读题目(就是题目卡死劳资): 来,上代码: #include <cmath> #include <cstdio> ...
- AC日记——最小路径覆盖问题 洛谷 P2764
题目描述 «问题描述: 给定有向图G=(V,E).设P 是G 的一个简单路(顶点不相交)的集合.如果V 中每个顶点恰好在P 的一条路上,则称P是G 的一个路径覆盖.P 中路径可以从V 的任何一个顶点开 ...
- AC日记——飞行员配对方案问题 洛谷 P2756
题目背景 第二次世界大战时期.. 题目描述 英国皇家空军从沦陷国征募了大量外籍飞行员.由皇家空军派出的每一架飞机都需要配备在航行技能和语言上能互相配合的2 名飞行员,其中1 名是英国飞行员,另1名是外 ...
- AC日记——无线网络发射器选址 洛谷 P2038
题目描述 随着智能手机的日益普及,人们对无线网的需求日益增大.某城市决定对城市内的公共场所覆盖无线网. 假设该城市的布局为由严格平行的129 条东西向街道和129 条南北向街道所形成的网格状,并且相邻 ...
- AC日记——小A的糖果 洛谷七月月赛
小A的糖果 思路: for循环贪心: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 100005 #defi ...
- AC日记——矩阵取数游戏 洛谷 P1005
矩阵取数游戏 思路: dp+高精: 代码: #include <bits/stdc++.h> using namespace std; #define ll long long struc ...
随机推荐
- vs报错“以下文件中的行尾不一致,是否将行尾标准化”
vs报错"以下文件中的行尾不一致,是否将行尾标准化" 分析: 通过读取源文件,发现换行都使用的是"\n" Windows和Unix不同的标准引起的...即& ...
- UVA 1648 Business Center
https://vjudge.net/problem/UVA-1648 设上升x层,列个方程解出来,再把x带回去 #include<cmath> #include<cstdio> ...
- Linux局域网内文件传送
先安装ssh服务 sudo apt-get install ssh 普通传输文件,可以使用scp命令 1.将本地文件复制到目标机器: scp 文件名 用户名@目标机器IP:目标机器路径 回车后输入密 ...
- Bzoj4481 [Jsoi2015]非诚勿扰
Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 147 Solved: 75 Description [故事背景] JYY赶上了互联网创业的大潮,为非 ...
- HDU 1372 Knight Moves (广搜)
题目链接 Problem Description A friend of you is doing research on the Traveling Knight Problem (TKP) whe ...
- 【CC2530入门教程-01】CC2530微控制器开发入门基础
[引言] 本系列教程就有关CC2530单片机应用入门基础的实训案例进行分析,主要包括以下6部分的内容:[1]CC2530微控制器开发入门基础.[2]通用I/O端口的输入和输出.[3]外部中断初步应用. ...
- eCharts_基于eCharts开发的一个多图表页面
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 抓其根本(一)(hdu2710 Max Factor 素数 最大公约数 最小公倍数.....)
素数判断: 一.根据素数定义,该数除了1和它本身以外不再有其他的因数. 详见代码. int prime() { ; i*i<=n; i++) { ) //不是素数 ; //返回1 } ; //是 ...
- 网络设备之分配net_device结构
注册网络设备时,会调用pci_driver->probe函数,以e100为例,最终会调用alloc_netdev_mqs来分配内存,并且在分配内存后调用setup函数(以太网为ether_set ...
- wait与waitpid
1. 函数原型: #include <sys/wait.h> pid_t wait(int *statloc); pid_t waitpid(pid_t pid, int *statloc ...