大爷的字符串题

思路:

  莫队,需开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的更多相关文章

  1. AC日记——校门外的树 洛谷 P1047

    题目描述 某校大门外长度为L的马路上有一排树,每两棵相邻的树之间的间隔都是1米.我们可以把马路看成一个数轴,马路的一端在数轴0的位置,另一端在L的位置:数轴上的每个整数点,即0,1,2,……,L,都种 ...

  2. AC日记——妖梦拼木棒 洛谷 P3799

    妖梦拼木棒 思路: 神特么题: 代码: #include <bits/stdc++.h> using namespace std; #define mod 1000000007LL int ...

  3. AC日记——小B的询问 洛谷 P2709

    小B的询问 思路: 水题: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 50005 #define ll ...

  4. AC日记——Car的旅行路线 洛谷 P1027

    Car的旅行路线 思路: 这题不难,就是有点恶心: 而且,请认真读题目(就是题目卡死劳资): 来,上代码: #include <cmath> #include <cstdio> ...

  5. AC日记——最小路径覆盖问题 洛谷 P2764

    题目描述 «问题描述: 给定有向图G=(V,E).设P 是G 的一个简单路(顶点不相交)的集合.如果V 中每个顶点恰好在P 的一条路上,则称P是G 的一个路径覆盖.P 中路径可以从V 的任何一个顶点开 ...

  6. AC日记——飞行员配对方案问题 洛谷 P2756

    题目背景 第二次世界大战时期.. 题目描述 英国皇家空军从沦陷国征募了大量外籍飞行员.由皇家空军派出的每一架飞机都需要配备在航行技能和语言上能互相配合的2 名飞行员,其中1 名是英国飞行员,另1名是外 ...

  7. AC日记——无线网络发射器选址 洛谷 P2038

    题目描述 随着智能手机的日益普及,人们对无线网的需求日益增大.某城市决定对城市内的公共场所覆盖无线网. 假设该城市的布局为由严格平行的129 条东西向街道和129 条南北向街道所形成的网格状,并且相邻 ...

  8. AC日记——小A的糖果 洛谷七月月赛

    小A的糖果 思路: for循环贪心: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 100005 #defi ...

  9. AC日记——矩阵取数游戏 洛谷 P1005

    矩阵取数游戏 思路: dp+高精: 代码: #include <bits/stdc++.h> using namespace std; #define ll long long struc ...

随机推荐

  1. sql 中sum函数返回null的解决方案

    SUM 是SQL语句中的标准求和函数,如果没有符合条件的记录,那么SUM函数会返回NULL. 但多数情况下,我们希望如果没有符合条件记录的情况下,我们希望它返回0,而不是NULL,那么我们可以使用例如 ...

  2. ACE线程管理机制-面向对象的线程类ACE_Task

    转载于:http://www.cnblogs.com/TianFang/archive/2006/12/05/583231.html 我们在前一章中使用ACE_Thread包装时,你一定已经注意到了一 ...

  3. 使用自己的数据集训练和测试"caffenet"

    主要步骤可参考: http://blog.csdn.net/u010194274/article/details/50575284 补充几点: 1. convert函数是ImageMagick包里面的 ...

  4. ACM2066

    题目原址:http://acm.hdu.edu.cn/showproblem.php?pid=2066 大神必须飘过,我在这个题目里面学到了太多太多了.我提交了十六次,错了十二次,反复了这么久才解决内 ...

  5. Kubernetes - Start containers using Kubectl

    In this scenario, you'll learn how to use Kubectl to create and launch Deployments, Replication Cont ...

  6. js 拖动滑块验证

    备注:拖动滑块时尽量平移,chrome浏览器上没有卡顿情况,但是搜狗极速模式和360极速模式都遇到了卡顿,拖不动情况,应是浏览器内部对事件响应速度导致吧. JS代码: ;(function ($,wi ...

  7. 上下文管理器 contextlib

    from contextlib import contextmanager @contextmanager def tag(name): print "<%s>" % ...

  8. windows修改文件的修改或者创建时间

    https://www.online-tech-tips.com/computer-tips/how-to-change-the-last-modified-date-creation-date-an ...

  9. Eclipse中 将java Gradle项目转换为web项目

    1.找到项目工作空间目录,打开.project文件,并修改文件, 修改如下:      找到:<natures> </natures>代码段,在代码段中加入如下内容并保存:   ...

  10. codeforces——contest 864 problemE

    Polycarp is in really serious trouble — his house is on fire! It's time to save the most valuable it ...