这才是真正的$N\sqrt{N}$吧$qwq$


记录每个数$vl$出现的位置$s[vl]$,和每个数$a[i]=vl$是第几个$vl$,记为$P[i]$,然后预处理出块$[i,j]$区间的答案$f[i][j]$;

对于$[l,r]$,现将$ans$设为$[l,r]$中整块的答案;对于散块,将散块中的每个数$a[i]=vl$,有对应的$P[i]$,我们用$s[vl]$检查第$P[i]+ans+1$个$vl$对应的位置是否在$[l,r]$,如果在的话就更新答案$ans=ans+1$,并重复上述过程,直到$P[i]+ans+1$不在$[l,r]$中。

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<vector>
#include<queue>
#include<map>
#include<set>
#define ull unsigned long long
#define ll long long
#define R register int
#define pause (for(R i=1;i<=10000000000;++i))
#define OUT freopen("out.out","w",stdout);
using namespace std;
namespace Fread {
static char B[<<],*S=B,*D=B;
#define getchar() (S==D&&(D=(S=B)+fread(B,1,1<<15,stdin),S==D)?EOF:*S++)
inline int g() {
R ret=,fix=; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-:fix;
do ret=ret*+(ch^); while(isdigit(ch=getchar())); return ret*fix;
} inline bool isempty(const char& ch) {return ch<=||ch>=;}
inline void gs(char* s) {register char ch; while(isempty(ch=getchar())); do *s++=ch; while(!isempty(ch=getchar()));}
}using Fread::g; using Fread::gs;
const int N=,M=;
int n,m,T,tot,lst; int cnt[N],pos[N],P[N],a[N],b[N],f[M][M];
vector <int> s[N];
#define pb push_back
signed main() {
n=g(),m=g(),T=pow(n,/2.0); for(R i=;i<=n;++i) a[i]=g(); memcpy(b,a,sizeof(int)*(n+));
sort(b+,b+n+); tot=unique(b+,b+n+)-b-;
for(R i=;i<=n;++i) a[i]=lower_bound(b+,b+tot+,a[i])-b;
for(R i=;i<=n;++i) s[a[i]].pb(i);
for(R i=;i<=n;++i) P[i]=++cnt[a[i]]-; memset(cnt,,sizeof(cnt));
for(R i=;i<=n;++i) pos[i]=(i-)/T+;
for(R p=,L=pos[n],mx=;p<=L;++p,mx=,memset(cnt,,sizeof(cnt))) for(R t=p;t<=L;++t) {
for(R i=(t-)*T+,LL=min(t*T,n);i<=LL;++i) mx=max(++cnt[a[i]],mx);
f[p][t]=mx;
} for(R i=,l,r;i<=m;++i) { R ans=;
l=g()^lst,r=g()^lst;
if(pos[l]==pos[r]) {
for(R i=l;i<=r;++i) ans=max(ans,++cnt[a[i]]); for(R i=l;i<=r;++i) cnt[a[i]]=;
} else { R p=pos[l]+,q=pos[r]-; ans=f[p][q];
for(R i=l,L=pos[l]*T;i<=L;++i) { R tmp=P[i];
while((tmp+ans)<s[a[i]].size()&&s[a[i]][tmp+ans]<=r) ++ans;
} for(R i=q*T+;i<=r;++i) { R tmp=P[i];
while((tmp-ans)>=&&s[a[i]][tmp-ans]>=l) ++ans;
}
} printf("%d\n",lst=ans);
}
}

2019.07.03

Luogu P5048 [Ynoi2019模拟赛]Yuno loves sqrt technology III 分块的更多相关文章

  1. [洛谷P5048][Ynoi2019模拟赛]Yuno loves sqrt technology III

    题目大意:有$n(n\leqslant5\times10^5)$个数,$m(m\leqslant5\times10^5)$个询问,每个询问问区间$[l,r]$中众数的出现次数 题解:分块,设块大小为$ ...

  2. 洛谷P5048 [Ynoi2019模拟赛]Yuno loves sqrt technology III(分块)

    传送门 众所周知lxl是个毒瘤,Ynoi道道都是神仙题 用蒲公英那个分块的方法做结果两天没卡过去→_→ 首先我们分块,预处理块与块之间的答案,然后每次询问的时候拆成整块和两边剩下的元素 整块的答案很简 ...

  3. P5048 [[Ynoi2019模拟赛]Yuno loves sqrt technology III]

    为什么我感觉这题难度虚高啊-- 区间众数的出现次数- 计算器算一下 \(\sqrt 500000 = 708\) 然后我们发现这题的突破口? 考虑分块出来[L,R]块的众数出现个数 用 \(\text ...

  4. 洛谷 P5048 - [Ynoi2019 模拟赛] Yuno loves sqrt technology III(分块)

    题面传送门 qwq 感觉跟很多年前做过的一道题思路差不多罢,结果我竟然没想起那道题?!!所以说我 wtcl/wq 首先将 \(a_i\) 离散化. 如果允许离线那显然一遍莫队就能解决,复杂度 \(n\ ...

  5. [Luogu5048] [Ynoi2019模拟赛]Yuno loves sqrt technology III[分块]

    题意 长为 \(n\) 的序列,询问区间众数,强制在线. \(n\leq 5\times 10^5\). 分析 考虑分块,暴力统计出整块到整块之间的众数次数. 然后答案还可能出现在两边的两个独立的块中 ...

  6. [luogu5048] [Ynoi2019模拟赛] Yuno loves sqrt technology III

    题目链接 洛谷. Solution 思路同[BZOJ2724] [Violet 6]蒲公英,只不过由于lxl过于毒瘤,我们有一些更巧妙的操作. 首先还是预处理\(f[l][r]\)表示\(l\sim ...

  7. [Ynoi2019模拟赛]Yuno loves sqrt technology III

    题目大意: 给你一个长为n的序列a,m次询问,每次查询一个区间的众数的出现次数,强制在线. 解题思路: 出题人题解 众所周知lxl是个毒瘤,Ynoi道道都是神仙题 首先得离散化. 分块后,预处理Fi, ...

  8. [Ynoi2019模拟赛]Yuno loves sqrt technology II(二次离线莫队)

    二次离线莫队. 终于懂了 \(lxl\) 大爷发明的二次离线莫队,\(\%\%\%lxl\) 二次离线莫队,顾名思义就是将莫队离线两次.那怎么离线两次呢? 每当我们将 \([l,r]\) 移动右端点到 ...

  9. [Ynoi2019模拟赛]Yuno loves sqrt technology II

    题目大意: 给定一个长为\(n\)的序列,\(m\)次询问,每次查询一个区间的逆序对数. 32MB. 解题思路: 出题人题解 众所周知lxl是个毒瘤,Ynoi道道都是神仙题 二次离线莫队. 对于每个区 ...

随机推荐

  1. LC 494. Target Sum

    问题描述 You are given a list of non-negative integers, a1, a2, ..., an, and a target, S. Now you have 2 ...

  2. 怎样快捷获取元素节点body

    1. 使用: document.body document.body.nodeName; // "BODY" 2. 使用: document.getElementsByTagNam ...

  3. Python脚本:Linux自动化执行Python脚本

    1.环境及其工具: ubuntu 16.04 python2.7(自带) pip2.7(安装) virtualenv(安装) crontab (自带) 2.pip2.7安装 (1)尝试使用 sudo ...

  4. Unity Button延迟功能

    有时候Button点下去不是要求立即反应的,而是先有个特别短的动画,再反应. 实现: 继承Button,然后重写一下OnPointerClick,利用协程来延迟. using System.Colle ...

  5. 感兴趣的WebGL ,来自微博的一个全景星空图~

    https://m.weibo.cn/z/panorama?oid=1042143:ee51daffe7e7f497069af8c74840bbc2 还有一些好玩的相关链接 http://webgls ...

  6. Install CUDA 6.0 on Ubuntu 14.04 LTS

    Ubuntu 14.04 LTS is out, loads of new features have been added. Here are some procedures I followed ...

  7. 【原创】大叔问题定位分享(36)openresty(nginx+lua)中获取不到post数据,ngx.req.get_body_data返回nil

    openresty(nginx+lua)中获取不到post数据,ngx.req.get_body_data返回nil This function returns nil if the request ...

  8. SpringBoot-JPA入门

    SpringBoot-JPA入门 JPA就是Spring集成了hibernate感觉. 注解,方法仓库(顾名思义的方法,封装好了,还有自定义的方法). 案例: spring: datasource: ...

  9. static{}静态代码块与{}普通代码块之间的区别

    先看一个例子: //class A package com.my.test; class A { static { System.out.println("A1:父类静态代码区域" ...

  10. 【转载】python format遇上花括号{}

    在format string中, 大括号已经被format占用,想要使用大括号本身,该怎么办? 以下转载自这里. ============ 分割线 ============ 使用format时,字符串 ...