传送门

众所周知lxl是个毒瘤,Ynoi道道都是神仙题

用蒲公英那个分块的方法做结果两天没卡过去→_→

首先我们分块,预处理块与块之间的答案,然后每次询问的时候拆成整块和两边剩下的元素

整块的答案很简单,那么只有两边剩下的元素有可能更新答案

我们对于每一个元素用\(vector\)记录所有的出现位置,设\(dep_i\)为位置为\(i\)的元素在\(vector\)中的位置,那么如果\(a_i\)在这段区间中的出现次数超过\(res\),那么\(vector\)中第\(i+res\)个元素就要小于等于\(r\)

不难发现\(res\)的改变次数小于\(2S\),其中\(S\)为块的大小

然后就没有然后了

//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=a,I=b+1;i<I;++i)
#define fd(i,a,b) for(R int i=a,I=b-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
R int res,f=1;R char ch;
while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
return res*f;
}
char sr[1<<21],z[20];int C=-1,Z=0;
inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(R int x){
if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;
while(z[++Z]=x%10+48,x/=10);
while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
const int N=5e5+5,M=1005;
int ans[M][M],a[N],b[N],cnt[N],rt[N],vis[N],sz[N],dep[N],nxt[N];
vector<int>pos[N];
int n,m,q,lastans=0,s,l,r;
void init(){
fp(i,1,rt[n]){
int bg=s*(i-1)+1,res=0;
fp(j,bg,n){
cmax(res,++cnt[a[j]]);
ans[i][rt[j]]=res;
}
memset(cnt,0,sizeof(cnt));
}
}
int query(){
if(r-l+1<=(s<<2)){
int res=0;
fp(i,l,r)cmax(res,++cnt[a[i]]);
fp(i,l,r)cnt[a[i]]=0;
return res;
}
int ll=rt[l]+1,rr=rt[r]-1;
int LL=(ll-1)*s+1,RR=rr*s;
int res=ans[ll][rr];
fp(i,l,LL-1)
while(dep[i]+res<sz[a[i]]&&pos[a[i]][dep[i]+res]<=r)++res;
fp(i,RR+1,r)
while(dep[i]-res>=0&&pos[a[i]][dep[i]-res]>=l)++res;
return res;
}
int main(){
// freopen("testdata.in","r",stdin);
n=read(),q=read(),s=sqrt(n)-1;
fp(i,1,n)a[i]=b[i]=read(),rt[i]=(i-1)/s+1;
sort(b+1,b+1+n),m=unique(b+1,b+1+n)-b-1;
dep[0]=-1;
fp(i,1,n){
a[i]=lower_bound(b+1,b+1+m,a[i])-b,pos[a[i]].push_back(i);
dep[i]=dep[nxt[a[i]]]+1,nxt[a[i]]=i;
}
fp(i,1,m)sz[i]=pos[i].size();
init();
while(q--){
l=read()^lastans,r=read()^lastans;
print(lastans=query());
}
Ot();
return 0;
}

洛谷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(分块)

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

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

    这才是真正的$N\sqrt{N}$吧$qwq$ 记录每个数$vl$出现的位置$s[vl]$,和每个数$a[i]=vl$是第几个$vl$,记为$P[i]$,然后预处理出块$[i,j]$区间的答案$f[i ...

  4. 洛谷 P5046 [Ynoi2019 模拟赛] Yuno loves sqrt technology I(分块+卡常)

    洛谷题面传送门 zszz,lxl 出的 DS 都是卡常题( 首先由于此题强制在线,因此考虑分块,我们那么待查询区间 \([l,r]\) 可以很自然地被分为三个部分: 左散块 中间的整块 右散块 那么这 ...

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

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

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

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

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

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

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

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

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

    题目描述 给你一个长为n的排列,m次询问,每次查询一个区间的逆序对数,强制在线. 题解 MD不卡了..TMD一点都卡不动. 强制在线的话也没啥好一点的方法,只能分块预处理了. 对于每个块,我们设lef ...

随机推荐

  1. Selenium-浮层的操作

    实现-百度登录浮层-输入登录用户名 #! /usr/bin/env python #coding=utf-8 ''' 百度首页-登录浮层 ''' from selenium import webdri ...

  2. 动态规划 两个字符串之间的编辑距离 leetcode72

    public static int minDistance(String word1, String word2) { char[] s1 = word1.toCharArray(); char[] ...

  3. LiveMediaStreamer

    LiveMediaStreamer is an open source multimedia framework that allows the manipulation of multiple au ...

  4. 2017-2018-1 20179215《Linux内核原理与分析》第七周作业

    一.实验部分:分析Linux内核创建一个新进程的过程. [第一部分] 根据要求完成第一部分,步骤如下: 1. 首先进入虚拟机,打开终端,这命令行依次敲入以下命令: cd LinuxKernel    ...

  5. ACM学习历程——ZOJ 3822 Domination (2014牡丹江区域赛 D题)(概率,数学递推)

    Description Edward is the headmaster of Marjar University. He is enthusiastic about chess and often ...

  6. TYVJ 1094 矩形分割

    时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 YHOI Train#4 Problem 1 描述 出于某些方面的需求,我们要把一块N×M的木板切成一个个1× ...

  7. CF1060B:Maximum Sum of Digits

    我对贪心的理解:https://www.cnblogs.com/AKMer/p/9776293.html 题目传送门:http://codeforces.com/problemset/problem/ ...

  8. hashCode之二--Java:重写equals()和hashCode()

    以下内容总结自<Effective Java>. 1.何时需要重写equals() 当一个类有自己特有的“逻辑相等”概念(不同于对象身份的概念). 2.设计equals() [1]使用in ...

  9. zoj 3872

    D - Beauty of Array Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu S ...

  10. rails Ajax--利用Jquery

    view function init_tree(product_name) { var htmlobj=$.ajax({url: "get_all_file?param=" + p ...